Socket
Socket
Sign inDemoInstall

telejson

Package Overview
Dependencies
Maintainers
4
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 5.3.3 to 6.0.0

77

dist/cjs/index.js

@@ -128,10 +128,31 @@ "use strict";

function convertUnconventionalData(data) {
// `Event` has a weird structure, for details see `extractEventHiddenProperties` doc
if (!isObject(data)) {
return data;
}
var result = data;
var wasMutated = false; // `Event` has a weird structure, for details see `extractEventHiddenProperties` doc
// Plus we need to check if running in a browser to ensure `Event` exist and
// is really the dom Event class.
if (isRunningInBrowser && data instanceof Event) {
return (0, _domEvent.extractEventHiddenProperties)(data);
result = (0, _domEvent.extractEventHiddenProperties)(result);
wasMutated = true;
}
return data;
result = Object.keys(result).reduce(function (acc, key) {
try {
var _result$key;
// Try accessing a property to test if we are allowed to do so
// eslint-disable-next-line no-unused-expressions
(_result$key = result[key]) === null || _result$key === void 0 ? void 0 : _result$key.toJSON;
acc[key] = result[key];
} catch (err) {
wasMutated = true;
}
return acc;
}, {});
return wasMutated ? result : data;
}

@@ -141,2 +162,3 @@

var objects;
var map;
var stack;

@@ -150,2 +172,3 @@ var keys;

objects = new Map([[value, '[]']]);
map = new Map();
stack = [];

@@ -157,3 +180,5 @@ return value;

while (stack.length && this !== stack[0]) {
var origin = map.get(this) || this;
while (stack.length && origin !== stack[0]) {
stack.shift();

@@ -175,2 +200,6 @@ keys.pop();

if (value === null) {
return null;
}
if (typeof value === 'number') {

@@ -253,12 +282,19 @@ if (value === -Infinity) {

if (value === this) {
return "_duplicate_".concat(JSON.stringify(keys));
} // when it's a class and we don't want to support classes, skip
if (value.constructor && value.constructor.name && value.constructor.name !== 'Object' && !Array.isArray(value) && !options.allowClass) {
return undefined;
}
var found = objects.get(value);
if (!found) {
if (value && isObject(value) && value.constructor && value.constructor.name && value.constructor.name !== 'Object') {
if (!options.allowClass) {
return undefined;
}
var converted = Array.isArray(value) ? value : convertUnconventionalData(value);
if (value.constructor && value.constructor.name && value.constructor.name !== 'Object' && !Array.isArray(value) && options.allowClass) {
try {
Object.assign(value, {
Object.assign(converted, {
'_constructor-name_': value.constructor.name

@@ -273,5 +309,10 @@ });

keys.push(key);
stack.unshift(value);
stack.unshift(converted);
objects.set(value, JSON.stringify(keys));
return convertUnconventionalData(value);
if (value !== converted) {
map.set(value, converted);
}
return converted;
} // actually, here's the only place where the keys keeping is useful

@@ -318,3 +359,3 @@

if (isObject(value) && value['_constructor-name_']) {
if (isObject(value) && value['_constructor-name_'] && options.allowFunction) {
var name = value['_constructor-name_'];

@@ -324,3 +365,3 @@

// eslint-disable-next-line no-new-func
var Fn = new Function("return function ".concat(name, "(){}"))();
var Fn = new Function("return function ".concat(name.replace(/[\W_]+/g, ''), "(){}"))();
Object.setPrototypeOf(value, new Fn());

@@ -334,3 +375,3 @@ } // eslint-disable-next-line no-param-reassign

if (typeof value === 'string' && value.startsWith('_function_')) {
if (typeof value === 'string' && value.startsWith('_function_') && options.allowFunction) {
var _ref2 = value.match(/_function_([^|]*)\|(.*)/) || [],

@@ -367,3 +408,3 @@ _ref3 = _slicedToArray(_ref2, 3),

if (typeof value === 'string' && value.startsWith('_regexp_')) {
if (typeof value === 'string' && value.startsWith('_regexp_') && options.allowRegExp) {
// this split isn't working correctly

@@ -378,3 +419,3 @@ var _ref4 = value.match(/_regexp_([^|]*)\|(.*)/) || [],

if (typeof value === 'string' && value.startsWith('_date_')) {
if (typeof value === 'string' && value.startsWith('_date_') && options.allowDate) {
return new Date(value.replace('_date_', ''));

@@ -392,7 +433,7 @@ }

if (typeof value === 'string' && value.startsWith('_symbol_')) {
if (typeof value === 'string' && value.startsWith('_symbol_') && options.allowSymbol) {
return Symbol(value.replace('_symbol_', ''));
}
if (typeof value === 'string' && value.startsWith('_gsymbol_')) {
if (typeof value === 'string' && value.startsWith('_gsymbol_') && options.allowSymbol) {
return Symbol["for"](value.replace('_gsymbol_', ''));

@@ -399,0 +440,0 @@ }

@@ -109,10 +109,31 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function convertUnconventionalData(data) {
// `Event` has a weird structure, for details see `extractEventHiddenProperties` doc
if (!isObject(data)) {
return data;
}
var result = data;
var wasMutated = false; // `Event` has a weird structure, for details see `extractEventHiddenProperties` doc
// Plus we need to check if running in a browser to ensure `Event` exist and
// is really the dom Event class.
if (isRunningInBrowser && data instanceof Event) {
return extractEventHiddenProperties(data);
result = extractEventHiddenProperties(result);
wasMutated = true;
}
return data;
result = Object.keys(result).reduce(function (acc, key) {
try {
var _result$key;
// Try accessing a property to test if we are allowed to do so
// eslint-disable-next-line no-unused-expressions
(_result$key = result[key]) === null || _result$key === void 0 ? void 0 : _result$key.toJSON;
acc[key] = result[key];
} catch (err) {
wasMutated = true;
}
return acc;
}, {});
return wasMutated ? result : data;
}

@@ -122,2 +143,3 @@

var objects;
var map;
var stack;

@@ -131,2 +153,3 @@ var keys;

objects = new Map([[value, '[]']]);
map = new Map();
stack = [];

@@ -138,3 +161,5 @@ return value;

while (stack.length && this !== stack[0]) {
var origin = map.get(this) || this;
while (stack.length && origin !== stack[0]) {
stack.shift();

@@ -156,2 +181,6 @@ keys.pop();

if (value === null) {
return null;
}
if (typeof value === 'number') {

@@ -234,12 +263,19 @@ if (value === -Infinity) {

if (value === this) {
return "_duplicate_".concat(JSON.stringify(keys));
} // when it's a class and we don't want to support classes, skip
if (value.constructor && value.constructor.name && value.constructor.name !== 'Object' && !Array.isArray(value) && !options.allowClass) {
return undefined;
}
var found = objects.get(value);
if (!found) {
if (value && isObject(value) && value.constructor && value.constructor.name && value.constructor.name !== 'Object') {
if (!options.allowClass) {
return undefined;
}
var converted = Array.isArray(value) ? value : convertUnconventionalData(value);
if (value.constructor && value.constructor.name && value.constructor.name !== 'Object' && !Array.isArray(value) && options.allowClass) {
try {
Object.assign(value, {
Object.assign(converted, {
'_constructor-name_': value.constructor.name

@@ -254,5 +290,10 @@ });

keys.push(key);
stack.unshift(value);
stack.unshift(converted);
objects.set(value, JSON.stringify(keys));
return convertUnconventionalData(value);
if (value !== converted) {
map.set(value, converted);
}
return converted;
} // actually, here's the only place where the keys keeping is useful

@@ -296,3 +337,3 @@

if (isObject(value) && value['_constructor-name_']) {
if (isObject(value) && value['_constructor-name_'] && options.allowFunction) {
var name = value['_constructor-name_'];

@@ -302,3 +343,3 @@

// eslint-disable-next-line no-new-func
var Fn = new Function("return function ".concat(name, "(){}"))();
var Fn = new Function("return function ".concat(name.replace(/[\W_]+/g, ''), "(){}"))();
Object.setPrototypeOf(value, new Fn());

@@ -312,3 +353,3 @@ } // eslint-disable-next-line no-param-reassign

if (typeof value === 'string' && value.startsWith('_function_')) {
if (typeof value === 'string' && value.startsWith('_function_') && options.allowFunction) {
var _ref2 = value.match(/_function_([^|]*)\|(.*)/) || [],

@@ -345,3 +386,3 @@ _ref3 = _slicedToArray(_ref2, 3),

if (typeof value === 'string' && value.startsWith('_regexp_')) {
if (typeof value === 'string' && value.startsWith('_regexp_') && options.allowRegExp) {
// this split isn't working correctly

@@ -356,3 +397,3 @@ var _ref4 = value.match(/_regexp_([^|]*)\|(.*)/) || [],

if (typeof value === 'string' && value.startsWith('_date_')) {
if (typeof value === 'string' && value.startsWith('_date_') && options.allowDate) {
return new Date(value.replace('_date_', ''));

@@ -370,7 +411,7 @@ }

if (typeof value === 'string' && value.startsWith('_symbol_')) {
if (typeof value === 'string' && value.startsWith('_symbol_') && options.allowSymbol) {
return Symbol(value.replace('_symbol_', ''));
}
if (typeof value === 'string' && value.startsWith('_gsymbol_')) {
if (typeof value === 'string' && value.startsWith('_gsymbol_') && options.allowSymbol) {
return Symbol["for"](value.replace('_gsymbol_', ''));

@@ -377,0 +418,0 @@ }

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

export declare function extractEventHiddenProperties(event: Event): unknown;
export declare function extractEventHiddenProperties(event: Event): any;

@@ -13,10 +13,5 @@ export interface Options {

export declare const isJSON: (input: string) => RegExpMatchArray | null;
export declare const replacer: (options: Options) => (this: any, key: string, value: any) => any;
interface ValueContainer {
'_constructor-name_'?: string;
[keys: string]: any;
}
export declare const reviver: (options: Options) => (this: any, key: string, value: ValueContainer | string) => any;
export declare const replacer: (options: Options) => any;
export declare const reviver: (options: Options) => any;
export declare const stringify: (data: unknown, options?: Partial<Options>) => string;
export declare const parse: (data: string, options?: Partial<Options>) => any;
export {};
{
"name": "telejson",
"version": "5.3.3",
"version": "6.0.0",
"description": "",

@@ -15,9 +15,9 @@ "keywords": [

],
"homepage": "https://github.com/storybooks/telejson",
"homepage": "https://github.com/storybookjs/telejson",
"bugs": {
"url": "https://github.com/storybooks/telejson/issues"
"url": "https://github.com/storybookjs/telejson/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/storybooks/telejson.git"
"url": "https://github.com/storybookjs/telejson.git"
},

@@ -24,0 +24,0 @@ "files": [

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