diff options
Diffstat (limited to 'tools/node_modules/eslint/node_modules/circular-json')
8 files changed, 598 insertions, 0 deletions
diff --git a/tools/node_modules/eslint/node_modules/circular-json/LICENSE.txt b/tools/node_modules/eslint/node_modules/circular-json/LICENSE.txt new file mode 100644 index 0000000000..e42a04b646 --- /dev/null +++ b/tools/node_modules/eslint/node_modules/circular-json/LICENSE.txt @@ -0,0 +1,19 @@ +Copyright (C) 2013-2017 by Andrea Giammarchi - @WebReflection + +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. diff --git a/tools/node_modules/eslint/node_modules/circular-json/README.md b/tools/node_modules/eslint/node_modules/circular-json/README.md new file mode 100644 index 0000000000..9cc003ef28 --- /dev/null +++ b/tools/node_modules/eslint/node_modules/circular-json/README.md @@ -0,0 +1,135 @@ +CircularJSON +============ + +![Downloads](https://img.shields.io/npm/dm/circular-json.svg) [![Build Status](https://travis-ci.org/WebReflection/circular-json.svg?branch=master)](https://travis-ci.org/WebReflection/circular-json) [![Coverage Status](https://coveralls.io/repos/github/WebReflection/circular-json/badge.svg?branch=master)](https://coveralls.io/github/WebReflection/circular-json?branch=master) [![donate](https://img.shields.io/badge/$-donate-ff69b4.svg?maxAge=2592000&style=flat)](https://github.com/WebReflection/donate) + +Serializes and deserializes otherwise valid JSON objects containing circular references into and from a specialized JSON format. + +- - - + +### A Working Solution To A Common Problem +A usage example: + +```JavaScript +var object = {}; +object.arr = [ + object, object +]; +object.arr.push(object.arr); +object.obj = object; + +var serialized = CircularJSON.stringify(object); +// '{"arr":["~","~","~arr"],"obj":"~"}' +// NOTE: CircularJSON DOES NOT parse JS +// it handles receiver and reviver callbacks + +var unserialized = CircularJSON.parse(serialized); +// { arr: [ [Circular], [Circular] ], +// obj: [Circular] } + +unserialized.obj === unserialized; +unserialized.arr[0] === unserialized; +unserialized.arr.pop() === unserialized.arr; +``` + +A quick summary: + + * uses `~` as a special prefix symbol to denote which parent the reference belongs to (i.e. `~root~child1~child2`) + * reasonably fast in both serialization and deserialization + * compact serialization for easier and slimmer transportation across environments + * [tested and covered](test/circular-json.js) over nasty structures too + * compatible with all JavaScript engines + +Node Installation & Usage +============ + +```bash +npm install --save circular-json +``` + +```javascript +'use strict'; + +var + CircularJSON = require('circular-json'), + obj = { foo: 'bar' }, + str +; + +obj.self = obj; +str = CircularJSON.stringify(obj); +``` + +There are no dependencies. + +Browser Installation & Usage +================ + +* Global: <build/circular-json.js> +* AMD: <build/circular-json.amd.js> +* CommonJS: <build/circular-json.node.js> + +(generated via [gitstrap](https://github.com/WebReflection/gitstrap)) + +```html +<script src="build/circular-json.js"></script> +``` + +```javascript +'use strict'; + +var CircularJSON = window.CircularJSON + , obj = { foo: 'bar' } + , str + ; + +obj.self = obj; +str = CircularJSON.stringify(obj); +``` + +NOTE: Platforms without native JSON (i.e. MSIE <= 8) requires `json3.js` or similar. + +It is also *a bad idea* to `CircularJSON.parse(JSON.stringify(object))` because of those manipulation used in `CircularJSON.stringify()` able to make parsing safe and secure. + +As summary: `CircularJSON.parse(CircularJSON.stringify(object))` is the way to go, same is for `JSON.parse(JSON.stringify(object))`. + +API +=== + +It's the same as native JSON, except the fourth parameter `placeholder`, which circular references to be replaced with `"[Circular]"` (i.e. for logging). + +* CircularJSON.stringify(object, replacer, spacer, placeholder) +* CircularJSON.parse(string, reviver) + +Bear in mind `JSON.parse(CircularJSON.stringify(object))` will work but not produce the expected output. + +Similar Libraries +======= + +### Why Not the [@izs](https://twitter.com/izs) One +The module [json-stringify-safe](https://github.com/isaacs/json-stringify-safe) seems to be for `console.log()` but it's completely pointless for `JSON.parse()`, being latter one unable to retrieve back the initial structure. Here an example: + +```JavaScript +// a logged object with circular references +{ + "circularRef": "[Circular]", + "list": [ + "[Circular]", + "[Circular]" + ] +} +// what do we do with above output ? +``` + +Just type this in your `node` console: `var o = {}; o.a = o; console.log(o);`. The output will be `{ a: [Circular] }` ... good, but that ain't really solving the problem. + +However, if that's all you need, the function used to create that kind of output is probably faster than `CircularJSON` and surely fits in less lines of code. + + +### Why Not {{put random name}} Solution +So here the thing: circular references can be wrong but, if there is a need for them, any attempt to ignore them or remove them can be considered just a failure. + +Not because the method is bad or it's not working, simply because the circular info, the one we needed and used in the first place, is lost! + +In this case, `CircularJSON` does even more than just solve circular and recursions: it maps all same objects so that less memory is used as well on deserialization as less bandwidth too! +It's able to redefine those references back later on so the way we store is the way we retrieve and in a reasonably performant way, also trusting the snappy and native `JSON` methods to iterate. diff --git a/tools/node_modules/eslint/node_modules/circular-json/build/circular-json.js b/tools/node_modules/eslint/node_modules/circular-json/build/circular-json.js new file mode 100644 index 0000000000..acf1c2599e --- /dev/null +++ b/tools/node_modules/eslint/node_modules/circular-json/build/circular-json.js @@ -0,0 +1,2 @@ +/*! (C) WebReflection Mit Style License */ +var CircularJSON=function(e,t){function l(e,t,o){var u=[],f=[e],l=[e],c=[o?n:"[Circular]"],h=e,p=1,d;return function(e,v){return t&&(v=t.call(this,e,v)),e!==""&&(h!==this&&(d=p-a.call(f,this)-1,p-=d,f.splice(p,f.length),u.splice(p-1,u.length),h=this),typeof v=="object"&&v?(a.call(f,v)<0&&f.push(h=v),p=f.length,d=a.call(l,v),d<0?(d=l.push(v)-1,o?(u.push((""+e).replace(s,r)),c[d]=n+u.join(n)):c[d]=c[0]):v=c[d]):typeof v=="string"&&o&&(v=v.replace(r,i).replace(n,r))),v}}function c(e,t){for(var r=0,i=t.length;r<i;e=e[t[r++].replace(o,n)]);return e}function h(e){return function(t,s){var o=typeof s=="string";return o&&s.charAt(0)===n?new f(s.slice(1)):(t===""&&(s=v(s,s,{})),o&&(s=s.replace(u,"$1"+n).replace(i,r)),e?e.call(this,t,s):s)}}function p(e,t,n){for(var r=0,i=t.length;r<i;r++)t[r]=v(e,t[r],n);return t}function d(e,t,n){for(var r in t)t.hasOwnProperty(r)&&(t[r]=v(e,t[r],n));return t}function v(e,t,r){return t instanceof Array?p(e,t,r):t instanceof f?t.length?r.hasOwnProperty(t)?r[t]:r[t]=c(e,t.split(n)):e:t instanceof Object?d(e,t,r):t}function m(t,n,r,i){return e.stringify(t,l(t,n,!i),r)}function g(t,n){return e.parse(t,h(n))}var n="~",r="\\x"+("0"+n.charCodeAt(0).toString(16)).slice(-2),i="\\"+r,s=new t(r,"g"),o=new t(i,"g"),u=new t("(?:^|([^\\\\]))"+i),a=[].indexOf||function(e){for(var t=this.length;t--&&this[t]!==e;);return t},f=String;return{stringify:m,parse:g}}(JSON,RegExp);
\ No newline at end of file diff --git a/tools/node_modules/eslint/node_modules/circular-json/build/circular-json.max.js b/tools/node_modules/eslint/node_modules/circular-json/build/circular-json.max.js new file mode 100644 index 0000000000..5ad5ffad85 --- /dev/null +++ b/tools/node_modules/eslint/node_modules/circular-json/build/circular-json.max.js @@ -0,0 +1,189 @@ +/*! +Copyright (C) 2013 by WebReflection + +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. + +*/ +var CircularJSON = (function(JSON, RegExp){ +var + // should be a not so common char + // possibly one JSON does not encode + // possibly one encodeURIComponent does not encode + // right now this char is '~' but this might change in the future + specialChar = '~', + safeSpecialChar = '\\x' + ( + '0' + specialChar.charCodeAt(0).toString(16) + ).slice(-2), + escapedSafeSpecialChar = '\\' + safeSpecialChar, + specialCharRG = new RegExp(safeSpecialChar, 'g'), + safeSpecialCharRG = new RegExp(escapedSafeSpecialChar, 'g'), + + safeStartWithSpecialCharRG = new RegExp('(?:^|([^\\\\]))' + escapedSafeSpecialChar), + + indexOf = [].indexOf || function(v){ + for(var i=this.length;i--&&this[i]!==v;); + return i; + }, + $String = String // there's no way to drop warnings in JSHint + // about new String ... well, I need that here! + // faked, and happy linter! +; + +function generateReplacer(value, replacer, resolve) { + var + path = [], + all = [value], + seen = [value], + mapp = [resolve ? specialChar : '[Circular]'], + last = value, + lvl = 1, + i + ; + return function(key, value) { + // the replacer has rights to decide + // if a new object should be returned + // or if there's some key to drop + // let's call it here rather than "too late" + if (replacer) value = replacer.call(this, key, value); + + // did you know ? Safari passes keys as integers for arrays + // which means if (key) when key === 0 won't pass the check + if (key !== '') { + if (last !== this) { + i = lvl - indexOf.call(all, this) - 1; + lvl -= i; + all.splice(lvl, all.length); + path.splice(lvl - 1, path.length); + last = this; + } + // console.log(lvl, key, path); + if (typeof value === 'object' && value) { + // if object isn't referring to parent object, add to the + // object path stack. Otherwise it is already there. + if (indexOf.call(all, value) < 0) { + all.push(last = value); + } + lvl = all.length; + i = indexOf.call(seen, value); + if (i < 0) { + i = seen.push(value) - 1; + if (resolve) { + // key cannot contain specialChar but could be not a string + path.push(('' + key).replace(specialCharRG, safeSpecialChar)); + mapp[i] = specialChar + path.join(specialChar); + } else { + mapp[i] = mapp[0]; + } + } else { + value = mapp[i]; + } + } else { + if (typeof value === 'string' && resolve) { + // ensure no special char involved on deserialization + // in this case only first char is important + // no need to replace all value (better performance) + value = value .replace(safeSpecialChar, escapedSafeSpecialChar) + .replace(specialChar, safeSpecialChar); + } + } + } + return value; + }; +} + +function retrieveFromPath(current, keys) { + for(var i = 0, length = keys.length; i < length; current = current[ + // keys should be normalized back here + keys[i++].replace(safeSpecialCharRG, specialChar) + ]); + return current; +} + +function generateReviver(reviver) { + return function(key, value) { + var isString = typeof value === 'string'; + if (isString && value.charAt(0) === specialChar) { + return new $String(value.slice(1)); + } + if (key === '') value = regenerate(value, value, {}); + // again, only one needed, do not use the RegExp for this replacement + // only keys need the RegExp + if (isString) value = value .replace(safeStartWithSpecialCharRG, '$1' + specialChar) + .replace(escapedSafeSpecialChar, safeSpecialChar); + return reviver ? reviver.call(this, key, value) : value; + }; +} + +function regenerateArray(root, current, retrieve) { + for (var i = 0, length = current.length; i < length; i++) { + current[i] = regenerate(root, current[i], retrieve); + } + return current; +} + +function regenerateObject(root, current, retrieve) { + for (var key in current) { + if (current.hasOwnProperty(key)) { + current[key] = regenerate(root, current[key], retrieve); + } + } + return current; +} + +function regenerate(root, current, retrieve) { + return current instanceof Array ? + // fast Array reconstruction + regenerateArray(root, current, retrieve) : + ( + current instanceof $String ? + ( + // root is an empty string + current.length ? + ( + retrieve.hasOwnProperty(current) ? + retrieve[current] : + retrieve[current] = retrieveFromPath( + root, current.split(specialChar) + ) + ) : + root + ) : + ( + current instanceof Object ? + // dedicated Object parser + regenerateObject(root, current, retrieve) : + // value as it is + current + ) + ) + ; +} + +function stringifyRecursion(value, replacer, space, doNotResolve) { + return JSON.stringify(value, generateReplacer(value, replacer, !doNotResolve), space); +} + +function parseRecursion(text, reviver) { + return JSON.parse(text, generateReviver(reviver)); +} +return { + stringify: stringifyRecursion, + parse: parseRecursion +}; +}(JSON, RegExp));
\ No newline at end of file diff --git a/tools/node_modules/eslint/node_modules/circular-json/build/circular-json.node.js b/tools/node_modules/eslint/node_modules/circular-json/build/circular-json.node.js new file mode 100644 index 0000000000..576266fe65 --- /dev/null +++ b/tools/node_modules/eslint/node_modules/circular-json/build/circular-json.node.js @@ -0,0 +1,185 @@ +/*! +Copyright (C) 2013 by WebReflection + +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. + +*/ +var + // should be a not so common char + // possibly one JSON does not encode + // possibly one encodeURIComponent does not encode + // right now this char is '~' but this might change in the future + specialChar = '~', + safeSpecialChar = '\\x' + ( + '0' + specialChar.charCodeAt(0).toString(16) + ).slice(-2), + escapedSafeSpecialChar = '\\' + safeSpecialChar, + specialCharRG = new RegExp(safeSpecialChar, 'g'), + safeSpecialCharRG = new RegExp(escapedSafeSpecialChar, 'g'), + + safeStartWithSpecialCharRG = new RegExp('(?:^|([^\\\\]))' + escapedSafeSpecialChar), + + indexOf = [].indexOf || function(v){ + for(var i=this.length;i--&&this[i]!==v;); + return i; + }, + $String = String // there's no way to drop warnings in JSHint + // about new String ... well, I need that here! + // faked, and happy linter! +; + +function generateReplacer(value, replacer, resolve) { + var + path = [], + all = [value], + seen = [value], + mapp = [resolve ? specialChar : '[Circular]'], + last = value, + lvl = 1, + i + ; + return function(key, value) { + // the replacer has rights to decide + // if a new object should be returned + // or if there's some key to drop + // let's call it here rather than "too late" + if (replacer) value = replacer.call(this, key, value); + + // did you know ? Safari passes keys as integers for arrays + // which means if (key) when key === 0 won't pass the check + if (key !== '') { + if (last !== this) { + i = lvl - indexOf.call(all, this) - 1; + lvl -= i; + all.splice(lvl, all.length); + path.splice(lvl - 1, path.length); + last = this; + } + // console.log(lvl, key, path); + if (typeof value === 'object' && value) { + // if object isn't referring to parent object, add to the + // object path stack. Otherwise it is already there. + if (indexOf.call(all, value) < 0) { + all.push(last = value); + } + lvl = all.length; + i = indexOf.call(seen, value); + if (i < 0) { + i = seen.push(value) - 1; + if (resolve) { + // key cannot contain specialChar but could be not a string + path.push(('' + key).replace(specialCharRG, safeSpecialChar)); + mapp[i] = specialChar + path.join(specialChar); + } else { + mapp[i] = mapp[0]; + } + } else { + value = mapp[i]; + } + } else { + if (typeof value === 'string' && resolve) { + // ensure no special char involved on deserialization + // in this case only first char is important + // no need to replace all value (better performance) + value = value .replace(safeSpecialChar, escapedSafeSpecialChar) + .replace(specialChar, safeSpecialChar); + } + } + } + return value; + }; +} + +function retrieveFromPath(current, keys) { + for(var i = 0, length = keys.length; i < length; current = current[ + // keys should be normalized back here + keys[i++].replace(safeSpecialCharRG, specialChar) + ]); + return current; +} + +function generateReviver(reviver) { + return function(key, value) { + var isString = typeof value === 'string'; + if (isString && value.charAt(0) === specialChar) { + return new $String(value.slice(1)); + } + if (key === '') value = regenerate(value, value, {}); + // again, only one needed, do not use the RegExp for this replacement + // only keys need the RegExp + if (isString) value = value .replace(safeStartWithSpecialCharRG, '$1' + specialChar) + .replace(escapedSafeSpecialChar, safeSpecialChar); + return reviver ? reviver.call(this, key, value) : value; + }; +} + +function regenerateArray(root, current, retrieve) { + for (var i = 0, length = current.length; i < length; i++) { + current[i] = regenerate(root, current[i], retrieve); + } + return current; +} + +function regenerateObject(root, current, retrieve) { + for (var key in current) { + if (current.hasOwnProperty(key)) { + current[key] = regenerate(root, current[key], retrieve); + } + } + return current; +} + +function regenerate(root, current, retrieve) { + return current instanceof Array ? + // fast Array reconstruction + regenerateArray(root, current, retrieve) : + ( + current instanceof $String ? + ( + // root is an empty string + current.length ? + ( + retrieve.hasOwnProperty(current) ? + retrieve[current] : + retrieve[current] = retrieveFromPath( + root, current.split(specialChar) + ) + ) : + root + ) : + ( + current instanceof Object ? + // dedicated Object parser + regenerateObject(root, current, retrieve) : + // value as it is + current + ) + ) + ; +} + +function stringifyRecursion(value, replacer, space, doNotResolve) { + return JSON.stringify(value, generateReplacer(value, replacer, !doNotResolve), space); +} + +function parseRecursion(text, reviver) { + return JSON.parse(text, generateReviver(reviver)); +} +this.stringify = stringifyRecursion; +this.parse = parseRecursion;
\ No newline at end of file diff --git a/tools/node_modules/eslint/node_modules/circular-json/package.json b/tools/node_modules/eslint/node_modules/circular-json/package.json new file mode 100644 index 0000000000..7ed781a415 --- /dev/null +++ b/tools/node_modules/eslint/node_modules/circular-json/package.json @@ -0,0 +1,65 @@ +{ + "_from": "circular-json@^0.3.1", + "_id": "circular-json@0.3.3", + "_inBundle": false, + "_integrity": "sha512-UZK3NBx2Mca+b5LsG7bY183pHWt5Y1xts4P3Pz7ENTwGVnJOUWbRb3ocjvX7hx9tq/yTAdclXm9sZ38gNuem4A==", + "_location": "/eslint/circular-json", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "circular-json@^0.3.1", + "name": "circular-json", + "escapedName": "circular-json", + "rawSpec": "^0.3.1", + "saveSpec": null, + "fetchSpec": "^0.3.1" + }, + "_requiredBy": [ + "/eslint/flat-cache" + ], + "_resolved": "https://registry.npmjs.org/circular-json/-/circular-json-0.3.3.tgz", + "_shasum": "815c99ea84f6809529d2f45791bdf82711352d66", + "_spec": "circular-json@^0.3.1", + "_where": "/Users/cjihrig/iojs/node/tools/eslint-tmp/node_modules/eslint/node_modules/flat-cache", + "author": { + "name": "Andrea Giammarchi", + "url": "http://webreflection.blogspot.com/" + }, + "bugs": { + "url": "https://github.com/WebReflection/circular-json/issues" + }, + "bundleDependencies": false, + "deprecated": false, + "description": "JSON does not handle circular references. This version does", + "devDependencies": { + "coveralls": "^2.13.0", + "istanbul": "^0.4.5", + "tiny-cdn": "^0.7.0", + "tressa": "^0.3.1" + }, + "generator": "https://github.com/WebReflection/gitstrap", + "homepage": "https://github.com/WebReflection/circular-json", + "keywords": [ + "JSON", + "circular", + "reference", + "recursive", + "recursion", + "parse", + "stringify" + ], + "license": "MIT", + "main": "./build/circular-json.node.js", + "name": "circular-json", + "repository": { + "type": "git", + "url": "git://github.com/WebReflection/circular-json.git" + }, + "scripts": { + "coveralls": "cat ./coverage/lcov.info | coveralls", + "test": "istanbul cover test/circular-json.js", + "web": "$(sleep 2 && open http://0.0.0.0:7151/) & tiny-cdn run ./" + }, + "version": "0.3.3" +} diff --git a/tools/node_modules/eslint/node_modules/circular-json/template/license.after b/tools/node_modules/eslint/node_modules/circular-json/template/license.after new file mode 100644 index 0000000000..d7365df165 --- /dev/null +++ b/tools/node_modules/eslint/node_modules/circular-json/template/license.after @@ -0,0 +1,2 @@ + +*/ diff --git a/tools/node_modules/eslint/node_modules/circular-json/template/license.before b/tools/node_modules/eslint/node_modules/circular-json/template/license.before new file mode 100644 index 0000000000..bf11147bdb --- /dev/null +++ b/tools/node_modules/eslint/node_modules/circular-json/template/license.before @@ -0,0 +1 @@ +/*! |