monocart-formatter
v3.0.0
Published
JS/CSS/HTML/JSON formatter with content mapping
Downloads
199,400
Readme
Monocart Formatter
JS/CSS/HTML/JSON formatter
Features
- Base on js-beautify
- Generating mapping after formatted
- Working with web worker in browser
- Working with worker threads in Node.js
- Minifying worker code with gzip
Install
npm i monocart-formatter
Usage
import { format, MappingParser } from 'monocart-formatter';
const text = "var a = 1;";
const type = "js";
// js-beautify options https://github.com/beautify-web/js-beautify
const options = {};
const { content, mapping } = await format(text, type, options);
console.log("formatted content", content);
const mappingParser = new MappingParser(mapping);
// originalPosition = 10
const formattedPosition = mappingParser.originalToFormatted(10);
const originalPosition = mappingParser.formattedToOriginal(formattedPosition);