js-beautify icon indicating copy to clipboard operation
js-beautify copied to clipboard

Support ESM import

Open chriscarrollsmith opened this issue 1 year ago • 3 comments

Description

Currently, when I import js-beautifier to an ES module using an import statement and then log the object to the console, here's what I see:

import * as beautify from 'js-beautify';
console.log(beautify)

[Module: null prototype] { default: [Function: beautify] { js: [Function: js_beautify] { defaultOptions: [Function (anonymous)] }, css: [Function: css_beautify] { defaultOptions: [Function (anonymous)] }, html: [Function: style_html] { defaultOptions: [Function (anonymous)] }, js_beautify: [Function: js_beautify] { defaultOptions: [Function (anonymous)] }, css_beautify: [Function: css_beautify] { defaultOptions: [Function (anonymous)] }, html_beautify: [Function: style_html] { defaultOptions: [Function (anonymous)] } } }

Honestly not great, because it means I have to access the different beautifers through the default property, like this:

beautify.default.html()

At minimum, this needs to be added to the README so folks know the correct syntax. Preferably, the code should also be updated to better support ESM import.

chriscarrollsmith avatar Oct 02 '23 17:10 chriscarrollsmith

@chriscarrollsmith If you know how to update for better ESM support without breaking existing code, PR welcome.

bitwiseman avatar Oct 13 '23 22:10 bitwiseman