"Fossies" - the Fresh Open Source Software Archive

Member "node-v12.18.4-win-x86/node_modules/npm/node_modules/strip-json-comments/readme.md" (14 Feb 2020, 1557 Bytes) of package /windows/www/node-v12.18.4-win-x86.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format (assuming markdown format). Alternatively you can here view or download the uninterpreted source code file. A member file download can also be achieved by clicking within a package contents listing on the according byte size field.

strip-json-comments Build Status

Strip comments from JSON. Lets you use comments in your JSON files!

This is now possible:

{
    // rainbows
    "unicorn": /* ❤ */ "cake"
}

It will replace single-line comments // and multi-line comments /**/ with whitespace. This allows JSON error positions to remain as close as possible to the original source.

Also available as a gulp/grunt/broccoli plugin.

Install

$ npm install --save strip-json-comments

Usage

const json = '{/*rainbows*/"unicorn":"cake"}';

JSON.parse(stripJsonComments(json));
//=> {unicorn: 'cake'}

API

stripJsonComments(input, options)

input

Type: string

Accepts a string with JSON and returns a string without comments.

options

whitespace

Type: boolean
Default: true

Replace comments with whitespace instead of stripping them entirely.

License

MIT © Sindre Sorhus