html的js-beautify没有方法'beautify'

Jér*_*nge 3 html javascript node.js js-beautify

我尝试使用js-beautifyhtmlnode.js应用程序:

var htmlBeautifier = require('js-beautify').html;
...
res = htmlBeautifier.beautify(html);
...
Run Code Online (Sandbox Code Playgroud)

但是我得到:

...
res = htmlBeautifier.beautify(html,{});
                         ^
TypeError: Object function (html_source, options) {
    return style_html(html_source, options, js_beautify.js_beautify, css_beautify.css_beautify);
} has no method 'beautify'
Run Code Online (Sandbox Code Playgroud)

有关使用的文档 js-beautify forhtml没有提供太多信息。一个应该是怎样使用js-beautifyhtml

T.J*_*der 5

根据文档(可能有更多细节),函数html 函数,而不是将函数作为属性的对象。所以:

var htmlBeautifier = require('js-beautify').html;
//...
res = htmlBeautifier(html);
Run Code Online (Sandbox Code Playgroud)

要么

var htmlBeautifier = require('js-beautify');
//...
res = htmlBeautifier.html(html);
Run Code Online (Sandbox Code Playgroud)