summaryrefslogtreecommitdiff
path: root/tools/node_modules/eslint/node_modules/strip-json-comments
diff options
context:
space:
mode:
Diffstat (limited to 'tools/node_modules/eslint/node_modules/strip-json-comments')
-rw-r--r--tools/node_modules/eslint/node_modules/strip-json-comments/index.js69
-rw-r--r--tools/node_modules/eslint/node_modules/strip-json-comments/license20
-rw-r--r--tools/node_modules/eslint/node_modules/strip-json-comments/package.json19
-rw-r--r--tools/node_modules/eslint/node_modules/strip-json-comments/readme.md28
4 files changed, 71 insertions, 65 deletions
diff --git a/tools/node_modules/eslint/node_modules/strip-json-comments/index.js b/tools/node_modules/eslint/node_modules/strip-json-comments/index.js
index 4e6576e6d3..c37da3de24 100644
--- a/tools/node_modules/eslint/node_modules/strip-json-comments/index.js
+++ b/tools/node_modules/eslint/node_modules/strip-json-comments/index.js
@@ -1,32 +1,35 @@
'use strict';
-var singleComment = 1;
-var multiComment = 2;
+const singleComment = Symbol('singleComment');
+const multiComment = Symbol('multiComment');
+const stripWithoutWhitespace = () => '';
+const stripWithWhitespace = (string, start, end) => string.slice(start, end).replace(/\S/g, ' ');
-function stripWithoutWhitespace() {
- return '';
-}
+const isEscaped = (jsonString, quotePosition) => {
+ let index = quotePosition - 1;
+ let backslashCount = 0;
-function stripWithWhitespace(str, start, end) {
- return str.slice(start, end).replace(/\S/g, ' ');
-}
+ while (jsonString[index] === '\\') {
+ index -= 1;
+ backslashCount += 1;
+ }
+
+ return Boolean(backslashCount % 2);
+};
-module.exports = function (str, opts) {
- opts = opts || {};
+module.exports = (jsonString, options = {}) => {
+ const strip = options.whitespace === false ? stripWithoutWhitespace : stripWithWhitespace;
- var currentChar;
- var nextChar;
- var insideString = false;
- var insideComment = false;
- var offset = 0;
- var ret = '';
- var strip = opts.whitespace === false ? stripWithoutWhitespace : stripWithWhitespace;
+ let insideString = false;
+ let insideComment = false;
+ let offset = 0;
+ let result = '';
- for (var i = 0; i < str.length; i++) {
- currentChar = str[i];
- nextChar = str[i + 1];
+ for (let i = 0; i < jsonString.length; i++) {
+ const currentCharacter = jsonString[i];
+ const nextCharacter = jsonString[i + 1];
- if (!insideComment && currentChar === '"') {
- var escaped = str[i - 1] === '\\' && str[i - 2] !== '\\';
+ if (!insideComment && currentCharacter === '"') {
+ const escaped = isEscaped(jsonString, i);
if (!escaped) {
insideString = !insideString;
}
@@ -36,35 +39,35 @@ module.exports = function (str, opts) {
continue;
}
- if (!insideComment && currentChar + nextChar === '//') {
- ret += str.slice(offset, i);
+ if (!insideComment && currentCharacter + nextCharacter === '//') {
+ result += jsonString.slice(offset, i);
offset = i;
insideComment = singleComment;
i++;
- } else if (insideComment === singleComment && currentChar + nextChar === '\r\n') {
+ } else if (insideComment === singleComment && currentCharacter + nextCharacter === '\r\n') {
i++;
insideComment = false;
- ret += strip(str, offset, i);
+ result += strip(jsonString, offset, i);
offset = i;
continue;
- } else if (insideComment === singleComment && currentChar === '\n') {
+ } else if (insideComment === singleComment && currentCharacter === '\n') {
insideComment = false;
- ret += strip(str, offset, i);
+ result += strip(jsonString, offset, i);
offset = i;
- } else if (!insideComment && currentChar + nextChar === '/*') {
- ret += str.slice(offset, i);
+ } else if (!insideComment && currentCharacter + nextCharacter === '/*') {
+ result += jsonString.slice(offset, i);
offset = i;
insideComment = multiComment;
i++;
continue;
- } else if (insideComment === multiComment && currentChar + nextChar === '*/') {
+ } else if (insideComment === multiComment && currentCharacter + nextCharacter === '*/') {
i++;
insideComment = false;
- ret += strip(str, offset, i + 1);
+ result += strip(jsonString, offset, i + 1);
offset = i + 1;
continue;
}
}
- return ret + (insideComment ? strip(str.substr(offset)) : str.substr(offset));
+ return result + (insideComment ? strip(jsonString.slice(offset)) : jsonString.slice(offset));
};
diff --git a/tools/node_modules/eslint/node_modules/strip-json-comments/license b/tools/node_modules/eslint/node_modules/strip-json-comments/license
index 654d0bfe94..e7af2f7710 100644
--- a/tools/node_modules/eslint/node_modules/strip-json-comments/license
+++ b/tools/node_modules/eslint/node_modules/strip-json-comments/license
@@ -1,21 +1,9 @@
-The MIT License (MIT)
+MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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:
+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 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.
+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.
diff --git a/tools/node_modules/eslint/node_modules/strip-json-comments/package.json b/tools/node_modules/eslint/node_modules/strip-json-comments/package.json
index dd3c353b82..e10695c282 100644
--- a/tools/node_modules/eslint/node_modules/strip-json-comments/package.json
+++ b/tools/node_modules/eslint/node_modules/strip-json-comments/package.json
@@ -11,28 +11,30 @@
"deprecated": false,
"description": "Strip comments from JSON. Lets you use comments in your JSON files!",
"devDependencies": {
- "ava": "*",
- "xo": "*"
+ "ava": "^1.4.1",
+ "matcha": "^0.7.0",
+ "tsd": "^0.7.2",
+ "xo": "^0.24.0"
},
"engines": {
- "node": ">=0.10.0"
+ "node": ">=8"
},
"files": [
- "index.js"
+ "index.js",
+ "index.d.ts"
],
"homepage": "https://github.com/sindresorhus/strip-json-comments#readme",
"keywords": [
"json",
"strip",
+ "comments",
"remove",
"delete",
"trim",
- "comments",
"multiline",
"parse",
"config",
"configuration",
- "conf",
"settings",
"util",
"env",
@@ -45,7 +47,8 @@
"url": "git+https://github.com/sindresorhus/strip-json-comments.git"
},
"scripts": {
- "test": "xo && ava"
+ "bench": "matcha benchmark.js",
+ "test": "xo && ava && tsd"
},
- "version": "2.0.1"
+ "version": "3.0.1"
} \ No newline at end of file
diff --git a/tools/node_modules/eslint/node_modules/strip-json-comments/readme.md b/tools/node_modules/eslint/node_modules/strip-json-comments/readme.md
index 0ee58dfe3a..9ebfc206c4 100644
--- a/tools/node_modules/eslint/node_modules/strip-json-comments/readme.md
+++ b/tools/node_modules/eslint/node_modules/strip-json-comments/readme.md
@@ -6,27 +6,30 @@ This is now possible:
```js
{
- // rainbows
+ // 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](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.
+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.
## Install
```
-$ npm install --save strip-json-comments
+$ npm install strip-json-comments
```
## Usage
```js
-const json = '{/*rainbows*/"unicorn":"cake"}';
+const json = `{
+ // Rainbows
+ "unicorn": /* ❤ */ "cake"
+}`;
JSON.parse(stripJsonComments(json));
//=> {unicorn: 'cake'}
@@ -35,9 +38,9 @@ JSON.parse(stripJsonComments(json));
## API
-### stripJsonComments(input, [options])
+### stripJsonComments(jsonString, [options])
-#### input
+#### jsonString
Type: `string`
@@ -45,14 +48,23 @@ Accepts a string with JSON and returns a string without comments.
#### options
+Type: `object`
+
##### whitespace
-Type: `boolean`
+Type: `boolean`<br>
Default: `true`
Replace comments with whitespace instead of stripping them entirely.
+## Benchmark
+
+```
+$ npm run bench
+```
+
+
## Related
- [strip-json-comments-cli](https://github.com/sindresorhus/strip-json-comments-cli) - CLI for this module
@@ -61,4 +73,4 @@ Replace comments with whitespace instead of stripping them entirely.
## License
-MIT © [Sindre Sorhus](http://sindresorhus.com)
+MIT © [Sindre Sorhus](https://sindresorhus.com)