Skip to content

Commit

Permalink
Merge branch 'master' into pr/JesusTheHun/56
Browse files Browse the repository at this point in the history
  • Loading branch information
ndelangen committed Apr 6, 2021
2 parents a1bc322 + 4176566 commit 763c843
Show file tree
Hide file tree
Showing 3 changed files with 1,879 additions and 2,237 deletions.
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "telejson",
"version": "5.1.0",
"version": "5.1.1",
"description": "",
"keywords": [
"JSON",
Expand Down Expand Up @@ -44,28 +44,28 @@
"@types/is-function": "^1.0.0",
"global": "^4.4.0",
"is-function": "^1.0.2",
"is-regex": "^1.1.1",
"is-regex": "^1.1.2",
"is-symbol": "^1.0.3",
"isobject": "^4.0.0",
"lodash": "^4.17.20",
"lodash": "^4.17.21",
"memoizerific": "^1.11.3"
},
"devDependencies": {
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.3",
"@babel/preset-env": "^7.12.1",
"@babel/preset-typescript": "^7.12.1",
"@storybook/eslint-config-storybook": "^2.4.0",
"@types/jest": "^26.0.15",
"@types/lodash": "^4.14.165",
"@babel/cli": "^7.13.14",
"@babel/core": "^7.13.14",
"@babel/preset-env": "^7.13.12",
"@babel/preset-typescript": "^7.13.0",
"@storybook/eslint-config-storybook": "^3.0.0",
"@types/jest": "^26.0.22",
"@types/lodash": "^4.14.168",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "^26.6.3",
"common-tags": "^1.8.0",
"eslint": "^7.13.0",
"eslint": "^7.23.0",
"jest": "^26.6.3",
"prettier": "^2.1.2",
"prettier": "^2.2.1",
"regenerator-runtime": "^0.13.7",
"typescript": "^4.0.5"
"typescript": "^4.2.3"
},
"publishConfig": {
"access": "public"
Expand Down
15 changes: 9 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import isObjectAny from 'isobject';
import get from 'lodash/get';
import memoize from 'memoizerific';

// eslint-disable-next-line @typescript-eslint/ban-types, no-use-before-define
const isObject = isObjectAny as <T = object>(val: any) => val is T;

const removeCodeComments = (code: string) => {
Expand Down Expand Up @@ -96,6 +97,9 @@ export interface Options {
lazyEval: boolean;
}

// eslint-disable-next-line no-useless-escape
export const isJSON = (input: string) => input.match(/^[\[\{\"\}].*[\]\}\"]$/);

export const replacer = function replacer(options: Options) {
let objects: Map<any, string>;
let stack: any[];
Expand Down Expand Up @@ -280,20 +284,22 @@ export const reviver = function reviver(options: Options) {

if (typeof value === 'string' && value.startsWith('_function_')) {
const [, name, source] = value.match(/_function_([^|]*)\|(.*)/) || [];
// eslint-disable-next-line no-useless-escape
const sourceSanitized = source.replace(/[(\(\))|\\| |\]|`]*$/, '');

if (!options.lazyEval) {
// eslint-disable-next-line no-eval
return eval(`(${source})`);
return eval(`(${sourceSanitized})`);
}

// lazy eval of the function
const result = (...args: any[]) => {
// eslint-disable-next-line no-eval
const f = eval(`(${source})`);
const f = eval(`(${sourceSanitized})`);
return f(...args);
};
Object.defineProperty(result, 'toString', {
value: () => source,
value: () => sourceSanitized,
});
Object.defineProperty(result, 'name', {
value: name,
Expand Down Expand Up @@ -340,9 +346,6 @@ export const reviver = function reviver(options: Options) {
};
};

// eslint-disable-next-line no-useless-escape
export const isJSON = (input: string) => input.match(/^[\[\{\"\}].*[\]\}\"]$/);

const defaultOptions: Options = {
maxDepth: 10,
space: undefined,
Expand Down
Loading

0 comments on commit 763c843

Please sign in to comment.