JavaScript API
The package is a WebAssembly build of the Rust core with a TypeScript wrapper. It works in Node.js, in browsers and as a UMD build.
The WebAssembly binary (about 1.5 MB, 0.7 MB gzipped) is embedded in the package as base64. No asset loading needs to be configured, and format() is synchronous.
format(input, options?)
Reorders attributes (HTML, Vue) or declarations (CSS, SCSS, Sass, Less).
options.language: the input language. Default:'html'.options.profile: a built-in profile name ('html','vue') or the YAML text of a profile. Default: the built-in profile forlanguage.options.classOrder: a built-in class order name ('tailwind') or the YAML text of a class order. Orders the classes of staticclassattributes and overrides the profile'sclassOrder. Default: classes keep their order. See Class order.
Throws an Error when the input or the profile is invalid.
init()
Compiles the WebAssembly module ahead of time without blocking. Optional: format() compiles it synchronously on first use.
languageFromPath(path)
Infers the language from a file name or path (.html, .htm, .vue, .css, .scss, .sass, .less). Returns undefined for other extensions.
builtinProfile(name)
Returns the YAML text of a built-in profile, as a starting point for a custom one.
builtinClassOrder(name)
Returns the YAML text of a built-in class order, as a starting point for a custom one.
Types
Language, FormatOptions and Meta are also exported as values: the extension-to-language map, the default options, and the build metadata.