Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

monocart-formatter

cenfun110.6kMIT3.0.1TypeScript support: included

JS/CSS/HTML/JSON formatter with content mapping

monocart-formatter

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

changelog

  • 3.0.0

    • (Breaking) removed locator, see separated monocart-locator
    • (Breaking) exported browser version by default
  • 2.3.3

    • fixed node import issue
  • 2.3.2

    • export commentParser for lineParser
  • 2.3.1

    • fixed the end column is out of source length
  • 2.3.0

    • added types
    • changed native node exports
  • 2.2.1

    • added worker bundle for nodejs
  • 2.2.0

    • added mapping parser class
    • added locator class
  • 2.1.0

    • added comment parser class
  • 2.0.0

    • added line parser class