pax_global_header00006660000000000000000000000064125572630550014524gustar00rootroot0000000000000052 comment=f58348696368583cc5bb18525fe31eacc9bd00e1 strip-json-comments-1.0.4/000077500000000000000000000000001255726305500154615ustar00rootroot00000000000000strip-json-comments-1.0.4/.editorconfig000066400000000000000000000003621255726305500201370ustar00rootroot00000000000000# editorconfig.org root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [package.json] indent_style = space indent_size = 2 [*.md] trim_trailing_whitespace = false strip-json-comments-1.0.4/.gitattributes000066400000000000000000000000141255726305500203470ustar00rootroot00000000000000* text=auto strip-json-comments-1.0.4/.gitignore000066400000000000000000000000361255726305500174500ustar00rootroot00000000000000node_modules bower_components strip-json-comments-1.0.4/.jshintrc000066400000000000000000000004741255726305500173130ustar00rootroot00000000000000{ "node": true, "esnext": true, "bitwise": true, "camelcase": true, "curly": true, "eqeqeq": true, "immed": true, "indent": 4, "latedef": true, "newcap": true, "noarg": true, "quotmark": "single", "regexp": true, "undef": true, "unused": true, "strict": true, "trailing": true, "smarttabs": true } strip-json-comments-1.0.4/.travis.yml000066400000000000000000000001101255726305500175620ustar00rootroot00000000000000sudo: false language: node_js node_js: - 'iojs' - '0.12' - '0.10' strip-json-comments-1.0.4/bower.json000066400000000000000000000007571255726305500175030ustar00rootroot00000000000000{ "name": "strip-json-comments", "description": "Strip comments from JSON. Lets you use comments in your JSON files!", "main": "strip-json-comments.js", "keywords": [ "json", "strip", "remove", "delete", "trim", "comments", "multiline", "parse", "config", "configuration", "conf", "settings", "util", "env", "environment" ], "ignore": [ ".*", "test.js", "cli.js", "component.json", "package.json" ] } strip-json-comments-1.0.4/cli.js000066400000000000000000000015461255726305500165740ustar00rootroot00000000000000#!/usr/bin/env node 'use strict'; var fs = require('fs'); var strip = require('./strip-json-comments'); var input = process.argv[2]; function getStdin(cb) { var ret = ''; process.stdin.setEncoding('utf8'); process.stdin.on('data', function (data) { ret += data; }); process.stdin.on('end', function () { cb(ret); }); } if (process.argv.indexOf('-h') !== -1 || process.argv.indexOf('--help') !== -1) { console.log('strip-json-comments input-file > output-file'); console.log('or'); console.log('strip-json-comments < input-file > output-file'); return; } if (process.argv.indexOf('-v') !== -1 || process.argv.indexOf('--version') !== -1) { console.log(require('./package').version); return; } if (input) { process.stdout.write(strip(fs.readFileSync(input, 'utf8'))); return; } getStdin(function (data) { process.stdout.write(strip(data)); }); strip-json-comments-1.0.4/component.json000066400000000000000000000010231255726305500203520ustar00rootroot00000000000000{ "name": "strip-json-comments", "version": "1.0.0", "description": "Strip comments from JSON. Lets you use comments in your JSON files!", "repository": "sindresorhus/strip-json-comments", "keywords": [ "json", "strip", "remove", "delete", "trim", "comments", "multiline", "parse", "config", "configuration", "conf", "settings", "util", "env", "environment" ], "main": "strip-json-comments.js", "scripts": ["strip-json-comments.js"], "license": "MIT" } strip-json-comments-1.0.4/license000066400000000000000000000021371255726305500170310ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) Sindre Sorhus (sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. strip-json-comments-1.0.4/package.json000066400000000000000000000015121255726305500177460ustar00rootroot00000000000000{ "name": "strip-json-comments", "version": "1.0.4", "description": "Strip comments from JSON. Lets you use comments in your JSON files!", "keywords": [ "json", "strip", "remove", "delete", "trim", "comments", "multiline", "parse", "config", "configuration", "conf", "settings", "util", "env", "environment", "cli", "bin" ], "license": "MIT", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "files": [ "cli.js", "strip-json-comments.js" ], "main": "strip-json-comments", "bin": "cli.js", "repository": "sindresorhus/strip-json-comments", "scripts": { "test": "mocha --ui tdd" }, "devDependencies": { "mocha": "*" }, "engines": { "node": ">=0.8.0" } } strip-json-comments-1.0.4/readme.md000066400000000000000000000031241255726305500172400ustar00rootroot00000000000000# strip-json-comments [![Build Status](https://travis-ci.org/sindresorhus/strip-json-comments.svg?branch=master)](https://travis-ci.org/sindresorhus/strip-json-comments) > Strip comments from JSON. Lets you use comments in your JSON files! This is now possible: ```js { // rainbows "unicorn": /* ❤ */ "cake" } ``` It will remove single-line comments `//` and multi-line comments `/**/`. 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. - *There's also [`json-comments`](https://npmjs.org/package/json-comments), but it's only for Node.js, inefficient, bloated as it also minifies, and comes with a `require` hook, which is :(* ## Install ```sh $ npm install --save strip-json-comments ``` ```sh $ bower install --save strip-json-comments ``` ```sh $ component install sindresorhus/strip-json-comments ``` ## Usage ```js var json = '{/*rainbows*/"unicorn":"cake"}'; JSON.parse(stripJsonComments(json)); //=> {unicorn: 'cake'} ``` ## API ### stripJsonComments(input) #### input Type: `string` Accepts a string with JSON and returns a string without comments. ## CLI ```sh $ npm install --global strip-json-comments ``` ```sh $ strip-json-comments --help strip-json-comments input-file > output-file # or strip-json-comments < input-file > output-file ``` ## Related - [`strip-css-comments`](https://github.com/sindresorhus/strip-css-comments) ## License MIT © [Sindre Sorhus](http://sindresorhus.com) strip-json-comments-1.0.4/strip-json-comments.js000066400000000000000000000032211255726305500217500ustar00rootroot00000000000000/*! strip-json-comments Strip comments from JSON. Lets you use comments in your JSON files! https://github.com/sindresorhus/strip-json-comments by Sindre Sorhus MIT License */ (function () { 'use strict'; var singleComment = 1; var multiComment = 2; function stripJsonComments(str) { var currentChar; var nextChar; var insideString = false; var insideComment = false; var ret = ''; for (var i = 0; i < str.length; i++) { currentChar = str[i]; nextChar = str[i + 1]; if (!insideComment && currentChar === '"') { var escaped = str[i - 1] === '\\' && str[i - 2] !== '\\'; if (!insideComment && !escaped && currentChar === '"') { insideString = !insideString; } } if (insideString) { ret += currentChar; continue; } if (!insideComment && currentChar + nextChar === '//') { insideComment = singleComment; i++; } else if (insideComment === singleComment && currentChar + nextChar === '\r\n') { insideComment = false; i++; ret += currentChar; ret += nextChar; continue; } else if (insideComment === singleComment && currentChar === '\n') { insideComment = false; } else if (!insideComment && currentChar + nextChar === '/*') { insideComment = multiComment; i++; continue; } else if (insideComment === multiComment && currentChar + nextChar === '*/') { insideComment = false; i++; continue; } if (insideComment) { continue; } ret += currentChar; } return ret; } if (typeof module !== 'undefined' && module.exports) { module.exports = stripJsonComments; } else { window.stripJsonComments = stripJsonComments; } })(); strip-json-comments-1.0.4/test.js000066400000000000000000000036441255726305500170050ustar00rootroot00000000000000'use strict'; var assert = require('assert'); var strip = require('./strip-json-comments'); suite('Test Cases', function () { test('should strip comments', function () { assert.strictEqual(strip('//comment\n{"a":"b"}'), '\n{"a":"b"}'); assert.strictEqual(strip('/*//comment*/{"a":"b"}'), '{"a":"b"}'); assert.strictEqual(strip('{"a":"b"//comment\n}'), '{"a":"b"\n}'); assert.strictEqual(strip('{"a":"b"/*comment*/}'), '{"a":"b"}'); assert.strictEqual(strip('{"a"/*\n\n\ncomment\r\n*/:"b"}'), '{"a":"b"}'); }); test('should not strip comments inside strings', function () { assert.strictEqual(strip('{"a":"b//c"}'), '{"a":"b//c"}'); assert.strictEqual(strip('{"a":"b/*c*/"}'), '{"a":"b/*c*/"}'); assert.strictEqual(strip('{"/*a":"b"}'), '{"/*a":"b"}'); assert.strictEqual(strip('{"\\"/*a":"b"}'), '{"\\"/*a":"b"}'); }); test('should consider escaped slashes when checking for escaped string quote', function () { assert.strictEqual(strip('{"\\\\":"https://foobar.com"}'), '{"\\\\":"https://foobar.com"}'); assert.strictEqual(strip('{"foo\\\"":"https://foobar.com"}'), '{"foo\\\"":"https://foobar.com"}'); }); suite('Line endings', function () { test('no comments', function () { assert.strictEqual(strip('{"a":"b"\n}'), '{"a":"b"\n}'); assert.strictEqual(strip('{"a":"b"\r\n}'), '{"a":"b"\r\n}'); }); test('single line comment', function () { assert.strictEqual(strip('{"a":"b"//c\n}'), '{"a":"b"\n}'); assert.strictEqual(strip('{"a":"b"//c\r\n}'), '{"a":"b"\r\n}'); }); test('single line block comment', function () { assert.strictEqual(strip('{"a":"b"/*c*/\n}'), '{"a":"b"\n}'); assert.strictEqual(strip('{"a":"b"/*c*/\r\n}'), '{"a":"b"\r\n}'); }); test('multi line block comment', function () { assert.strictEqual(strip('{"a":"b",/*c\nc2*/"x":"y"\n}'), '{"a":"b","x":"y"\n}'); assert.strictEqual(strip('{"a":"b",/*c\r\nc2*/"x":"y"\r\n}'), '{"a":"b","x":"y"\r\n}'); }); }); });