Skip to content

JS/CSS/HTML/JSON formatter with mapping for both browser (Web Worker) and Node.js (Worker Threads).

License

Notifications You must be signed in to change notification settings

cenfun/monocart-formatter

Repository files navigation

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);

About

JS/CSS/HTML/JSON formatter with mapping for both browser (Web Worker) and Node.js (Worker Threads).

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published