finki-main
main
|
Last change
on this file since 81bc7da was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago |
|
Initial commit
|
-
Property mode
set to
100644
|
|
File size:
1.5 KB
|
| Line | |
|---|
| 1 | # strip-json-comments [](https://travis-ci.org/sindresorhus/strip-json-comments)
|
|---|
| 2 |
|
|---|
| 3 | > Strip comments from JSON. Lets you use comments in your JSON files!
|
|---|
| 4 |
|
|---|
| 5 | This is now possible:
|
|---|
| 6 |
|
|---|
| 7 | ```js
|
|---|
| 8 | {
|
|---|
| 9 | // rainbows
|
|---|
| 10 | "unicorn": /* ❤ */ "cake"
|
|---|
| 11 | }
|
|---|
| 12 | ```
|
|---|
| 13 |
|
|---|
| 14 | 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.
|
|---|
| 15 |
|
|---|
| 16 | Also available as a [gulp](https://github.com/sindresorhus/gulp-strip-json-comments)/[grunt](https://github.com/sindresorhus/grunt-strip-json-comments)/[broccoli](https://github.com/sindresorhus/broccoli-strip-json-comments) plugin.
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 | ## Install
|
|---|
| 20 |
|
|---|
| 21 | ```
|
|---|
| 22 | $ npm install --save strip-json-comments
|
|---|
| 23 | ```
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 | ## Usage
|
|---|
| 27 |
|
|---|
| 28 | ```js
|
|---|
| 29 | const json = '{/*rainbows*/"unicorn":"cake"}';
|
|---|
| 30 |
|
|---|
| 31 | JSON.parse(stripJsonComments(json));
|
|---|
| 32 | //=> {unicorn: 'cake'}
|
|---|
| 33 | ```
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 | ## API
|
|---|
| 37 |
|
|---|
| 38 | ### stripJsonComments(input, [options])
|
|---|
| 39 |
|
|---|
| 40 | #### input
|
|---|
| 41 |
|
|---|
| 42 | Type: `string`
|
|---|
| 43 |
|
|---|
| 44 | Accepts a string with JSON and returns a string without comments.
|
|---|
| 45 |
|
|---|
| 46 | #### options
|
|---|
| 47 |
|
|---|
| 48 | ##### whitespace
|
|---|
| 49 |
|
|---|
| 50 | Type: `boolean`
|
|---|
| 51 | Default: `true`
|
|---|
| 52 |
|
|---|
| 53 | Replace comments with whitespace instead of stripping them entirely.
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 | ## Related
|
|---|
| 57 |
|
|---|
| 58 | - [strip-json-comments-cli](https://github.com/sindresorhus/strip-json-comments-cli) - CLI for this module
|
|---|
| 59 | - [strip-css-comments](https://github.com/sindresorhus/strip-css-comments) - Strip comments from CSS
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 | ## License
|
|---|
| 63 |
|
|---|
| 64 | MIT © [Sindre Sorhus](http://sindresorhus.com)
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.