Socket
Socket
Sign inDemoInstall

telejson

Package Overview
Dependencies
Maintainers
2
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

telejson - npm Package Compare versions

Comparing version 2.2.2 to 3.0.0

.babelrc.js

73

dist/index.js

@@ -8,4 +8,2 @@ "use strict";

var _global = require("global");
var _isRegex = _interopRequireDefault(require("is-regex"));

@@ -21,5 +19,7 @@

var _transform = _interopRequireDefault(require("lodash/transform"));
var _memoizerific = _interopRequireDefault(require("memoizerific"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

@@ -30,3 +30,3 @@ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

@@ -83,3 +83,3 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var cleanCode = (0, _memoizerific.default)(10000)(function (code) {
var cleanCode = (0, _memoizerific["default"])(10000)(function (code) {
return removeCodeComments(code).replace(/\n\s*/g, '') // remove indents & newlines

@@ -113,3 +113,3 @@ .trim();

if ((0, _isRegex.default)(value)) {
if ((0, _isRegex["default"])(value)) {
if (!options.allowRegExp) {

@@ -122,3 +122,3 @@ return undefined;

if ((0, _isFunction.default)(value)) {
if ((0, _isFunction["default"])(value)) {
if (!options.allowFunction) {

@@ -138,3 +138,3 @@ return undefined;

if ((0, _isSymbol.default)(value)) {
if ((0, _isSymbol["default"])(value)) {
if (!options.allowSymbol) {

@@ -183,2 +183,6 @@ return undefined;

if (typeof value === 'boolean') {
return value;
}
if (stack.length >= options.maxDepth) {

@@ -197,3 +201,3 @@ if (Array.isArray(value)) {

if (!found) {
if (value && (0, _isobject.default)(value) && value.constructor && value.constructor.name && value.constructor.name !== 'Object') {
if (value && (0, _isobject["default"])(value) && value.constructor && value.constructor.name && value.constructor.name !== 'Object') {
if (!options.allowClass) {

@@ -239,3 +243,2 @@ return undefined;

var target = _ref.target,
container = _ref.container,
replacement = _ref.replacement;

@@ -245,6 +248,6 @@

// eslint-disable-next-line no-param-reassign
container[target] = root;
value[target] = root;
} else {
// eslint-disable-next-line no-param-reassign
container[target] = (0, _get.default)(root, replacement.replace('root.', ''));
value[target] = (0, _get["default"])(root, replacement.replace('root.', ''));
}

@@ -259,3 +262,3 @@ });

if ((0, _isobject.default)(value) && value['_constructor-name_']) {
if ((0, _isobject["default"])(value) && value['_constructor-name_']) {
var name = value['_constructor-name_'];

@@ -275,11 +278,12 @@

if (typeof value === 'string' && value.startsWith('_function_')) {
var _value$match = value.match(/_function_([^|]*)\|(.*)/),
_value$match2 = _slicedToArray(_value$match, 3),
_name = _value$match2[1],
source = _value$match2[2]; // lazy eval of the function
var _ref2 = value.match(/_function_([^|]*)\|(.*)/) || [],
_ref3 = _slicedToArray(_ref2, 3),
_name = _ref3[1],
source = _ref3[2]; // lazy eval of the function
var result = function result() {
// eslint-disable-next-line no-eval
var f = eval("(".concat(source, ")"));
f.apply(void 0, arguments);
return f.apply(void 0, arguments);
};

@@ -300,6 +304,6 @@

// this split isn't working correctly
var _value$match3 = value.match(/_regexp_([^|]*)\|(.*)/),
_value$match4 = _slicedToArray(_value$match3, 3),
flags = _value$match4[1],
_source = _value$match4[2];
var _ref4 = value.match(/_regexp_([^|]*)\|(.*)/) || [],
_ref5 = _slicedToArray(_ref4, 3),
flags = _ref5[1],
_source = _ref5[2];

@@ -316,3 +320,2 @@ return new RegExp(_source, flags);

target: key,
container: this,
replacement: value.replace('_duplicate_', '')

@@ -345,4 +348,5 @@ });

};
};
}; // eslint-disable-next-line no-useless-escape
exports.reviver = reviver;

@@ -374,6 +378,25 @@

function cloneDeep(value, revive) {
// we don't want to update object if it has name
// we skip transform and return it
// Example: if we have {"_constructor-name_":"Foo"} then we want to return `Foo {}`
if ((0, _isobject["default"])(value) && value.constructor.name === 'Object') {
return (0, _transform["default"])(value, function (res, val, key) {
var v = revive(key, val);
res[key] = v !== val ? v : cloneDeep(val, revive);
}, {});
}
return value;
}
var parse = function parse(data) {
return JSON.parse(data, reviver());
var parsed = JSON.parse(data);
var revive = reviver();
var result = cloneDeep(parsed, revive); // we use blank key, because JSON.parse calls object with blank key at the end
// and we emulate JSOn.parse work
return revive('', result);
};
exports.parse = parse;
{
"name": "telejson",
"version": "2.2.2",
"version": "3.0.0",
"description": "",
"keywords": [
"JSON",
"parse",
"stringify",
"cyclic",
"cyclical",
"date",
"function",
"date",
"regex"
"parse",
"regex",
"stringify"
],
"homepage": "https://github.com/storybooks/telejson",
"publishConfig": {
"access": "public"
},
"bugs": {

@@ -28,28 +25,47 @@ "url": "https://github.com/storybooks/telejson/issues"

"main": "dist/index.js",
"jsnext:main": "src/index.js",
"types": "src/index.d.ts",
"scripts": {
"test": "jest",
"prepublish": "babel src --out-dir dist"
"build": "babel src --out-dir dist --extensions \".ts\" && tsc --emitDeclarationOnly",
"lint": "eslint src --ext .js,.ts",
"prepublish": "yarn build",
"test": "TZ=UTC jest"
},
"eslintConfig": {
"extends": [
"@storybook/eslint-config-storybook"
]
},
"jest": {
"testEnvironment": "node"
},
"dependencies": {
"global": "^4.3.2",
"@types/is-function": "^1.0.0",
"global": "^4.4.0",
"is-function": "^1.0.1",
"is-regex": "^1.0.4",
"is-symbol": "^1.0.2",
"isobject": "^3.0.1",
"lodash": "^4.17.11",
"isobject": "^4.0.0",
"lodash": "^4.17.15",
"memoizerific": "^1.11.3"
},
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.3.3",
"@babel/preset-env": "^7.3.1",
"@babel/cli": "^7.6.2",
"@babel/core": "^7.6.2",
"@babel/preset-env": "^7.6.2",
"@babel/preset-typescript": "^7.6.0",
"@storybook/eslint-config-storybook": "^1.0.0",
"@types/jest": "^24.0.18",
"@types/lodash": "^4.14.141",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "^24.1.0",
"jest": "^24.1.0",
"regenerator-runtime": "^0.13.1"
"babel-jest": "^24.9.0",
"common-tags": "^1.8.0",
"eslint": "^5.0.0",
"jest": "^24.9.0",
"prettier": "^1.18.2",
"regenerator-runtime": "^0.13.3",
"typescript": "^3.6.3"
},
"jest": {
"testEnvironment": "node"
"publishConfig": {
"access": "public"
}
}

@@ -8,4 +8,6 @@ import { stringify, parse, replacer, reviver } from '../src/index';

const fn1 = x => x + x;
const fn2 = function x(x) { return x - x };
function fn3(){
const fn2 = function x(x) {
return x - x;
};
function fn3() {
return x / x;

@@ -31,13 +33,13 @@ }

l: 'l',
}
}
}
}
}
}
}
}
}
}
}
},
},
},
},
},
},
},
},
},
},
},
};

@@ -53,4 +55,3 @@

date,
foo: new Foo,
data,
foo: new Foo(),
nested,

@@ -63,3 +64,3 @@ };

expect(true).toBe(true);
})
});

@@ -69,3 +70,3 @@ test('stringify', () => {

expect(() => stringified = stringify(data)).not.toThrow();
expect(() => (stringified = stringify(data))).not.toThrow();
expect(stringified).toMatchSnapshot();

@@ -76,4 +77,4 @@ });

const stringified = stringify(data);
let parsed
expect(() => parsed = parse(stringified)).not.toThrow();
let parsed;
expect(() => (parsed = parse(stringified))).not.toThrow();
expect(parsed).toMatchSnapshot();

@@ -97,3 +98,3 @@

expect(parsed.foo).toBeDefined();
expect(parsed.foo.constructor.name).toBe('Foo')
expect(parsed.foo.constructor.name).toBe('Foo');
expect(parsed.foo instanceof Foo).toBe(false);

@@ -126,1 +127,145 @@ });

});
test('check duplicate value', () => {
const Fruit = {
apple: true,
parent: {},
};
Fruit.parent.cyclic = Fruit;
const stringified = stringify(Fruit);
const parsed = parse(stringified);
expect(stringified).toEqual('{"apple":true,"parent":{"cyclic":"_duplicate_root"}}');
expect(parsed.cyclic.cyclic.cyclic.cyclic).toBeDefined();
expect(parsed.cyclic).toBe(parsed);
expect(parsed.cyclic.cyclic.cyclic.cyclic).toBe(parsed);
});
test('check constructor value', () => {
const data = { ConstructorFruit: new Foo() };
const stringified = stringify(data);
const parsed = parse(stringified);
expect(stringified).toEqual('{"ConstructorFruit":{"_constructor-name_":"Foo"}}');
expect(parsed.ConstructorFruit).toBeDefined();
expect(parsed.ConstructorFruit.constructor.name).toBe('Foo');
expect(parsed.foo instanceof Foo).toBe(false);
});
test('check function value', () => {
const Fruit = function(value) {
return [value, 'apple'];
};
const data = { FunctionFruit: Fruit };
const stringified = stringify(data);
const parsed = parse(stringified);
expect(stringified).toEqual(
'{"FunctionFruit":"_function_Fruit|function Fruit(value) {return [value, \'apple\'];}"}'
);
expect(parsed.FunctionFruit('orange')).toEqual(['orange', 'apple']);
expect(parsed.FunctionFruit.toString()).toEqual(
"function Fruit(value) {return [value, 'apple'];}"
);
});
test('check regExp value', () => {
const data = { RegExpFruit: /test/g };
const stringified = stringify(data);
const parsed = parse(stringified);
expect(stringified).toEqual('{"RegExpFruit":"_regexp_g|test"}');
expect(parsed).toMatchObject(data);
});
test('check date value', () => {
const data = { DateFruit: new Date('01.01.2019') };
const stringified = stringify(data);
const parsed = parse(stringified);
expect(stringified).toEqual('{"DateFruit":"_date_2019-01-01T00:00:00.000Z"}');
expect(parsed).toMatchObject(data);
expect(parsed.DateFruit.getFullYear()).toBe(2019);
});
test('check symbol value', () => {
const data = { SymbleFruit: Symbol('apple') };
const stringified = stringify(data);
const parsed = parse(stringified);
expect(stringified).toEqual('{"SymbleFruit":"_symbol_apple"}');
expect(parsed.SymbleFruit.toString()).toEqual('Symbol(apple)');
});
test('check minus Infinity value', () => {
const data = { InfinityFruit: -Infinity };
const stringified = stringify(data);
const parsed = parse(stringified);
expect(stringified).toEqual('{"InfinityFruit":"_-Infinity_"}');
expect(parsed).toMatchObject(data);
});
test('check Infinity value', () => {
const data = { InfinityFruit: Infinity };
const stringified = stringify(data);
const parsed = parse(stringified);
expect(stringified).toEqual('{"InfinityFruit":"_Infinity_"}');
expect(parsed).toMatchObject(data);
});
test('check NaN value', () => {
const data = { NaNFruit: NaN };
const stringified = stringify(data);
const parsed = parse(stringified);
expect(stringified).toEqual('{"NaNFruit":"_NaN_"}');
expect(parsed).toMatchObject(data);
});
test('check undefined value', () => {
const data = { undefinedFruit: undefined };
const stringified = stringify(data);
const parsed = parse(stringified);
expect(stringified).toEqual('{"undefinedFruit":"_undefined_"}');
expect(parsed).toMatchObject(data);
});
test('primitives should non be deduplicated', () => {
const data = {
bool: true,
a: 1,
b: '1',
c: {
bool: true,
c: 1,
d: 3,
e: '3',
f: {
bool: true,
c: '1',
d: 3,
e: '3',
},
},
};
const stringified = stringify(data);
const parsed = parse(stringified);
expect(stringified).toEqual(
'{"bool":true,"a":1,"b":"1","c":{"bool":true,"c":1,"d":3,"e":"3","f":{"bool":true,"c":"1","d":3,"e":"3"}}}'
);
expect(parsed).toMatchObject(data);
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc