Socket
Socket
Sign inDemoInstall

flatted

Package Overview
Dependencies
0
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.1 to 3.0.2

es.js

176

cjs/index.js

@@ -1,114 +0,86 @@

var Flatted = (function (Primitive, primitive) {
'use strict';
/*! (c) 2020 Andrea Giammarchi */
/*!
* ISC License
*
* Copyright (c) 2018, Andrea Giammarchi, @WebReflection
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
const {parse: $parse, stringify: $stringify} = JSON;
const {keys} = Object;
var Flatted = {
const Primitive = String; // it could be Number
const primitive = 'string'; // it could be 'number'
parse: function parse(text, reviver) {
var input = JSON.parse(text, Primitives).map(primitives);
var value = input[0];
var $ = reviver || noop;
var tmp = typeof value === 'object' && value ?
revive(input, new Set, value, $) :
value;
return $.call({'': tmp}, '', tmp);
},
const object = 'object';
stringify: function stringify(value, replacer, space) {
for (var
firstRun,
known = new Map,
input = [],
output = [],
$ = replacer && typeof replacer === typeof input ?
function (k, v) {
if (k === '' || -1 < replacer.indexOf(k)) return v;
} :
(replacer || noop),
i = +set(known, input, $.call({'': value}, '', value)),
replace = function (key, value) {
if (firstRun) {
firstRun = !firstRun;
return value;
}
var after = $.call(this, key, value);
switch (typeof after) {
case 'object':
if (after === null) return after;
case primitive:
return known.get(after) || set(known, input, after);
}
return after;
};
i < input.length; i++
) {
firstRun = true;
output[i] = JSON.stringify(input[i], replace, space);
}
return '[' + output.join(',') + ']';
}
const noop = (_, value) => value;
};
const primitives = value => (
value instanceof Primitive ? Primitive(value) : value
);
return Flatted;
const Primitives = (_, value) => (
typeof value === primitive ? new Primitive(value) : value
);
function noop(key, value) {
return value;
}
const revive = (input, parsed, output, $) => keys(output).reduce(
(output, key) => {
const value = output[key];
if (value instanceof Primitive) {
const tmp = input[value];
if (typeof tmp === object && !parsed.has(tmp)) {
parsed.add(tmp);
output[key] = $.call(output, key, revive(input, parsed, tmp, $));
} else {
output[key] = $.call(output, key, tmp);
}
} else
output[key] = $.call(output, key, value);
return output;
},
output
);
function revive(input, parsed, output, $) {
return Object.keys(output).reduce(
function (output, key) {
var value = output[key];
if (value instanceof Primitive) {
var tmp = input[value];
if (typeof tmp === 'object' && !parsed.has(tmp)) {
parsed.add(tmp);
output[key] = $.call(output, key, revive(input, parsed, tmp, $));
} else {
output[key] = $.call(output, key, tmp);
}
} else
output[key] = $.call(output, key, value);
return output;
},
output
);
}
const set = (known, input, value) => {
const index = Primitive(input.push(value) - 1);
known.set(value, index);
return index;
};
function set(known, input, value) {
var index = Primitive(input.push(value) - 1);
known.set(value, index);
return index;
}
const parse = (text, reviver) => {
const input = $parse(text, Primitives).map(primitives);
const value = input[0];
const $ = reviver || noop;
const tmp = typeof value === object && value ?
revive(input, new Set, value, $) :
value;
return $.call({'': tmp}, '', tmp);
};
exports.parse = parse;
// the two kinds of primitives
// 1. the real one
// 2. the wrapped one
function primitives(value) {
return value instanceof Primitive ? Primitive(value) : value;
const stringify = (value, replacer, space) => {
const $ = replacer && typeof replacer === object ?
(k, v) => (k === '' || -1 < replacer.indexOf(k) ? v : void 0) :
(replacer || noop);
const known = new Map;
const input = [];
const output = [];
let i = +set(known, input, $.call({'': value}, '', value));
let firstRun = !i;
while (i < input.length) {
firstRun = true;
output[i] = $stringify(input[i++], replace, space);
}
function Primitives(key, value) {
return typeof value === primitive ? new Primitive(value) : value;
return '[' + output.join(',') + ']';
function replace(key, value) {
if (firstRun) {
firstRun = !firstRun;
return value;
}
const after = $.call(this, key, value);
switch (typeof after) {
case object:
if (after === null) return after;
case primitive:
return known.get(after) || set(known, input, after);
}
return after;
}
}(String, 'string'));
module.exports = Flatted;
};
exports.stringify = stringify;

@@ -1,115 +0,83 @@

var Flatted = (function (Primitive, primitive) {
/*! (c) 2020 Andrea Giammarchi */
/*!
* ISC License
*
* Copyright (c) 2018, Andrea Giammarchi, @WebReflection
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
const {parse: $parse, stringify: $stringify} = JSON;
const {keys} = Object;
var Flatted = {
const Primitive = String; // it could be Number
const primitive = 'string'; // it could be 'number'
parse: function parse(text, reviver) {
var input = JSON.parse(text, Primitives).map(primitives);
var value = input[0];
var $ = reviver || noop;
var tmp = typeof value === 'object' && value ?
revive(input, new Set, value, $) :
value;
return $.call({'': tmp}, '', tmp);
},
const object = 'object';
stringify: function stringify(value, replacer, space) {
for (var
firstRun,
known = new Map,
input = [],
output = [],
$ = replacer && typeof replacer === typeof input ?
function (k, v) {
if (k === '' || -1 < replacer.indexOf(k)) return v;
} :
(replacer || noop),
i = +set(known, input, $.call({'': value}, '', value)),
replace = function (key, value) {
if (firstRun) {
firstRun = !firstRun;
return value;
}
var after = $.call(this, key, value);
switch (typeof after) {
case 'object':
if (after === null) return after;
case primitive:
return known.get(after) || set(known, input, after);
}
return after;
};
i < input.length; i++
) {
firstRun = true;
output[i] = JSON.stringify(input[i], replace, space);
}
return '[' + output.join(',') + ']';
}
const noop = (_, value) => value;
};
const primitives = value => (
value instanceof Primitive ? Primitive(value) : value
);
return Flatted;
const Primitives = (_, value) => (
typeof value === primitive ? new Primitive(value) : value
);
function noop(key, value) {
return value;
}
const revive = (input, parsed, output, $) => keys(output).reduce(
(output, key) => {
const value = output[key];
if (value instanceof Primitive) {
const tmp = input[value];
if (typeof tmp === object && !parsed.has(tmp)) {
parsed.add(tmp);
output[key] = $.call(output, key, revive(input, parsed, tmp, $));
} else {
output[key] = $.call(output, key, tmp);
}
} else
output[key] = $.call(output, key, value);
return output;
},
output
);
function revive(input, parsed, output, $) {
return Object.keys(output).reduce(
function (output, key) {
var value = output[key];
if (value instanceof Primitive) {
var tmp = input[value];
if (typeof tmp === 'object' && !parsed.has(tmp)) {
parsed.add(tmp);
output[key] = $.call(output, key, revive(input, parsed, tmp, $));
} else {
output[key] = $.call(output, key, tmp);
}
} else
output[key] = $.call(output, key, value);
return output;
},
output
);
}
const set = (known, input, value) => {
const index = Primitive(input.push(value) - 1);
known.set(value, index);
return index;
};
function set(known, input, value) {
var index = Primitive(input.push(value) - 1);
known.set(value, index);
return index;
}
export const parse = (text, reviver) => {
const input = $parse(text, Primitives).map(primitives);
const value = input[0];
const $ = reviver || noop;
const tmp = typeof value === object && value ?
revive(input, new Set, value, $) :
value;
return $.call({'': tmp}, '', tmp);
};
// the two kinds of primitives
// 1. the real one
// 2. the wrapped one
function primitives(value) {
return value instanceof Primitive ? Primitive(value) : value;
export const stringify = (value, replacer, space) => {
const $ = replacer && typeof replacer === object ?
(k, v) => (k === '' || -1 < replacer.indexOf(k) ? v : void 0) :
(replacer || noop);
const known = new Map;
const input = [];
const output = [];
let i = +set(known, input, $.call({'': value}, '', value));
let firstRun = !i;
while (i < input.length) {
firstRun = true;
output[i] = $stringify(input[i++], replace, space);
}
function Primitives(key, value) {
return typeof value === primitive ? new Primitive(value) : value;
return '[' + output.join(',') + ']';
function replace(key, value) {
if (firstRun) {
firstRun = !firstRun;
return value;
}
const after = $.call(this, key, value);
switch (typeof after) {
case object:
if (after === null) return after;
case primitive:
return known.get(after) || set(known, input, after);
}
return after;
}
}(String, 'string'));
export var parse = Flatted.parse;
export var stringify = Flatted.stringify;
};

@@ -1,113 +0,106 @@

var Flatted = (function (Primitive, primitive) {
self.Flatted = (function (exports) {
'use strict';
/*!
* ISC License
*
* Copyright (c) 2018, Andrea Giammarchi, @WebReflection
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
var Flatted = {
/*! (c) 2020 Andrea Giammarchi */
var $parse = JSON.parse,
$stringify = JSON.stringify;
var keys = Object.keys;
var Primitive = String; // it could be Number
parse: function parse(text, reviver) {
var input = JSON.parse(text, Primitives).map(primitives);
var value = input[0];
var $ = reviver || noop;
var tmp = typeof value === 'object' && value ?
revive(input, new Set, value, $) :
value;
return $.call({'': tmp}, '', tmp);
},
var primitive = 'string'; // it could be 'number'
stringify: function stringify(value, replacer, space) {
for (var
firstRun,
known = new Map,
input = [],
output = [],
$ = replacer && typeof replacer === typeof input ?
function (k, v) {
if (k === '' || -1 < replacer.indexOf(k)) return v;
} :
(replacer || noop),
i = +set(known, input, $.call({'': value}, '', value)),
replace = function (key, value) {
if (firstRun) {
firstRun = !firstRun;
return value;
}
var after = $.call(this, key, value);
switch (typeof after) {
case 'object':
if (after === null) return after;
case primitive:
return known.get(after) || set(known, input, after);
}
return after;
};
i < input.length; i++
) {
firstRun = true;
output[i] = JSON.stringify(input[i], replace, space);
}
return '[' + output.join(',') + ']';
}
var object = 'object';
var noop = function noop(_, value) {
return value;
};
return Flatted;
var primitives = function primitives(value) {
return value instanceof Primitive ? Primitive(value) : value;
};
function noop(key, value) {
return value;
}
var Primitives = function Primitives(_, value) {
return typeof(value) === primitive ? new Primitive(value) : value;
};
function revive(input, parsed, output, $) {
return Object.keys(output).reduce(
function (output, key) {
var value = output[key];
if (value instanceof Primitive) {
var tmp = input[value];
if (typeof tmp === 'object' && !parsed.has(tmp)) {
parsed.add(tmp);
output[key] = $.call(output, key, revive(input, parsed, tmp, $));
} else {
output[key] = $.call(output, key, tmp);
}
} else
output[key] = $.call(output, key, value);
return output;
},
output
);
}
var revive = function revive(input, parsed, output, $) {
return keys(output).reduce(function (output, key) {
var value = output[key];
function set(known, input, value) {
if (value instanceof Primitive) {
var tmp = input[value];
if (typeof(tmp) === object && !parsed.has(tmp)) {
parsed.add(tmp);
output[key] = $.call(output, key, revive(input, parsed, tmp, $));
} else {
output[key] = $.call(output, key, tmp);
}
} else output[key] = $.call(output, key, value);
return output;
}, output);
};
var set = function set(known, input, value) {
var index = Primitive(input.push(value) - 1);
known.set(value, index);
return index;
}
};
// the two kinds of primitives
// 1. the real one
// 2. the wrapped one
var parse = function parse(text, reviver) {
var input = $parse(text, Primitives).map(primitives);
var value = input[0];
var $ = reviver || noop;
var tmp = typeof(value) === object && value ? revive(input, new Set(), value, $) : value;
return $.call({
'': tmp
}, '', tmp);
};
var stringify = function stringify(value, replacer, space) {
var $ = replacer && typeof(replacer) === object ? function (k, v) {
return k === '' || -1 < replacer.indexOf(k) ? v : void 0;
} : replacer || noop;
var known = new Map();
var input = [];
var output = [];
var i = +set(known, input, $.call({
'': value
}, '', value));
var firstRun = !i;
function primitives(value) {
return value instanceof Primitive ? Primitive(value) : value;
}
while (i < input.length) {
firstRun = true;
output[i] = $stringify(input[i++], replace, space);
}
function Primitives(key, value) {
return typeof value === primitive ? new Primitive(value) : value;
}
return '[' + output.join(',') + ']';
}(String, 'string'));
function replace(key, value) {
if (firstRun) {
firstRun = !firstRun;
return value;
}
var after = $.call(this, key, value);
switch (typeof(after)) {
case object:
if (after === null) return after;
case primitive:
return known.get(after) || set(known, input, after);
}
return after;
}
};
exports.parse = parse;
exports.stringify = stringify;
return exports;
}({}));

@@ -1,2 +0,2 @@

/*! (c) 2018, Andrea Giammarchi, (ISC) */
var Flatted=function(o,l){return{parse:function(n,t){var e=JSON.parse(n,i).map(f),r=e[0],u=t||s,c="object"==typeof r&&r?function u(c,f,n,i){return Object.keys(n).reduce(function(n,t){var e,r=n[t];return r instanceof o?"object"!=typeof(e=c[r])||f.has(e)?n[t]=i.call(n,t,e):(f.add(e),n[t]=i.call(n,t,u(c,f,e,i))):n[t]=i.call(n,t,r),n},n)}(e,new Set,r,u):r;return u.call({"":c},"",c)},stringify:function(n,e,t){function r(n,t){if(u)return u=!u,t;var e=o.call(this,n,t);switch(typeof e){case"object":if(null===e)return e;case l:return c.get(e)||p(c,f,e)}return e}for(var u,c=new Map,f=[],i=[],o=e&&typeof e==typeof f?function(n,t){if(""===n||-1<e.indexOf(n))return t}:e||s,a=+p(c,f,o.call({"":n},"",n));a<f.length;a++)u=!0,i[a]=JSON.stringify(f[a],r,t);return"["+i.join(",")+"]"}};function s(n,t){return t}function p(n,t,e){var r=o(t.push(e)-1);return n.set(e,r),r}function f(n){return n instanceof o?o(n):n}function i(n,t){return typeof t==l?new o(t):t}}(String,"string");
self.Flatted=function(n){"use strict";
/*! (c) 2020 Andrea Giammarchi */function s(n,t){return t}function c(n){return n instanceof y?y(n):n}function f(n,t){return typeof t==v?new y(t):t}function l(n,t,r){var e=y(t.push(r)-1);return n.set(r,e),e}var a=JSON.parse,p=JSON.stringify,o=Object.keys,y=String,v="string",d="object";return n.parse=function(n,t){var r=a(n,f).map(c),e=r[0],u=t||s,i=typeof e==d&&e?function u(i,c,n,f){return o(n).reduce(function(n,t){var r,e=n[t];return e instanceof y?typeof(r=i[e])!=d||c.has(r)?n[t]=f.call(n,t,r):(c.add(r),n[t]=f.call(n,t,u(i,c,r,f))):n[t]=f.call(n,t,e),n},n)}(r,new Set,e,u):e;return u.call({"":i},"",i)},n.stringify=function(n,r,t){for(var e=r&&typeof r==d?function(n,t){return""===n||-1<r.indexOf(n)?t:void 0}:r||s,u=new Map,i=[],c=[],f=+l(u,i,e.call({"":n},"",n)),a=!f;f<i.length;)a=!0,c[f]=p(i[f++],o,t);return"["+c.join(",")+"]";function o(n,t){if(a)return a=!a,t;var r=e.call(this,n,t);switch(typeof r){case d:if(null===r)return r;case v:return u.get(r)||l(u,i,r)}return r}},n}({});
{
"name": "flatted",
"version": "3.0.1",
"version": "3.0.2",
"description": "A super light and fast circular JSON parser.",
"unpkg": "min.js",
"types": "types.d.ts",
"main": "./cjs/index.js",
"scripts": {
"bench": "node test/bench.js",
"build": "npm run cjs && npm test && npm run esm && npm run min && npm run size",
"cjs": "cp index.js cjs/index.js; echo 'module.exports = Flatted;' >> cjs/index.js",
"esm": "cp index.js esm/index.js; echo 'export var parse = Flatted.parse;' >> esm/index.js; echo 'export var stringify = Flatted.stringify;' >> esm/index.js",
"min": "echo '/*! (c) 2018, Andrea Giammarchi, (ISC) */'>min.js && uglifyjs index.js --support-ie8 -c -m >> min.js",
"size": "cat index.js | wc -c;cat min.js | wc -c;gzip -c9 min.js | wc -c;cat min.js | brotli | wc -c",
"build": "npm run cjs && npm run rollup:es && npm run rollup:babel && npm run min && npm run test && npm run size",
"cjs": "ascjs esm cjs",
"rollup:es": "rollup --config rollup/es.config.js && sed -i.bck 's/^var /self./' es.js && rm -rf es.js.bck",
"rollup:babel": "rollup --config rollup/babel.config.js && sed -i.bck 's/^var /self./' index.js && rm -rf index.js.bck && drop-babel-typeof index.js",
"min": "uglifyjs index.js --support-ie8 --comments=/^!/ -c -m -o min.js",
"size": "cat index.js | wc -c;cat min.js | wc -c;gzip -c9 min.js | wc -c;cat min.js | brotli | wc -c; cat es.js | brotli | wc -c",
"coveralls": "nyc report --reporter=text-lcov | coveralls",

@@ -28,9 +29,2 @@ "test": "nyc node test/index.js"

],
"type": "module",
"main": "./cjs/index.js",
"module": "./esm/index.js",
"exports": {
"import": "./esm/index.js",
"default": "./cjs/index.js"
},
"author": "Andrea Giammarchi",

@@ -43,9 +37,23 @@ "license": "ISC",

"devDependencies": {
"@babel/core": "^7.9.6",
"@babel/preset-env": "^7.9.6",
"ascjs": "^4.0.1",
"circular-json": "^0.5.9",
"circular-json-es6": "^2.0.2",
"coveralls": "^3.1.0",
"drop-babel-typeof": "^1.0.3",
"jsan": "^3.1.13",
"nyc": "^15.0.1",
"rollup": "^2.10.9",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-terser": "^6.1.0",
"uglify-js": "^3.9.3"
},
"module": "./esm/index.js",
"type": "module",
"exports": {
"import": "./esm/index.js",
"default": "./cjs/index.js"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc