JSPM

json-string-formatter

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 12824
  • Score
    100M100P100Q172036F
  • License MIT

A json string formatter with zero dependency.

Package Exports

  • json-string-formatter

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (json-string-formatter) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

JSON String Formatter

A lightweight JSON string formatter which can prettify your JSON string without parsing it to object.

Install

npm install --save json-string-formatter

or

yarn add json-string-formatter

Usage

  1. Import
const { format } = require('json-string-formatter';

// or

const jsonFormatter = require('json-string-formatter');

jsonFormatter.format(...)
  1. Basic usage
let input = "{'text': 'hello world!'}";
let output = format(input);

/**
 * output = `{
 *  'text': 'hello world!'
 * }`
 * /
  1. Customized indent and linebreak
let input = "{'text': 'hello world!'}";
let output = format(input, /* indent */ '--', /* linebreak */ '|');

/**
 * output = `{|--'text': 'hello world!'|}`
 */