Comparing version 3.0.3-debug.0 to 3.0.3-debug.1
@@ -12,3 +12,3 @@ interface Options { | ||
export declare const replacer: (options: Options) => (this: any, key: string, value: any) => any; | ||
export declare const reviver: () => (key: string, value: any) => any; | ||
export declare const reviver: () => (this: any, key: string, value: any) => any; | ||
export declare const isJSON: (input: string) => RegExpMatchArray | null; | ||
@@ -15,0 +15,0 @@ export declare const stringify: (data: any, options?: Partial<Options>) => string; |
@@ -232,2 +232,3 @@ "use strict"; | ||
var target = _ref.target, | ||
container = _ref.container, | ||
replacement = _ref.replacement; | ||
@@ -237,6 +238,6 @@ | ||
// eslint-disable-next-line no-param-reassign | ||
value[target] = root; | ||
container[target] = root; | ||
} else { | ||
// eslint-disable-next-line no-param-reassign | ||
value[target] = (0, _get["default"])(root, replacement.replace('root.', '')); | ||
container[target] = (0, _get["default"])(root, replacement.replace('root.', '')); | ||
} | ||
@@ -306,2 +307,3 @@ }); | ||
target: key, | ||
container: this, | ||
replacement: value.replace('_duplicate_', '') | ||
@@ -371,2 +373,3 @@ }); | ||
if (v === '_undefined_') { | ||
// eslint-disable-next-line no-param-reassign | ||
value[k] = undefined; | ||
@@ -379,2 +382,9 @@ } else if (!mutated.includes(v)) { | ||
} | ||
if (Array.isArray(value)) { | ||
value.forEach(function (v) { | ||
mutated.push(v); | ||
mutateUndefined(v); | ||
}); | ||
} | ||
}; | ||
@@ -381,0 +391,0 @@ }; |
{ | ||
"name": "telejson", | ||
"version": "3.0.3-debug.0", | ||
"version": "3.0.3-debug.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -208,3 +208,3 @@ import isRegExp from 'is-regex'; | ||
return function revive(key: string, value: any) { | ||
return function revive(this: any, key: string, value: any) { | ||
// last iteration = root | ||
@@ -215,9 +215,9 @@ if (key === '') { | ||
// restore cyclic refs | ||
refs.forEach(({ target, replacement }) => { | ||
refs.forEach(({ target, container, replacement }) => { | ||
if (replacement === 'root') { | ||
// eslint-disable-next-line no-param-reassign | ||
value[target] = root; | ||
container[target] = root; | ||
} else { | ||
// eslint-disable-next-line no-param-reassign | ||
value[target] = get(root, replacement.replace('root.', '')); | ||
container[target] = get(root, replacement.replace('root.', '')); | ||
} | ||
@@ -273,3 +273,3 @@ }); | ||
if (typeof value === 'string' && value.startsWith('_duplicate_')) { | ||
refs.push({ target: key, replacement: value.replace('_duplicate_', '') }); | ||
refs.push({ target: key, container: this, replacement: value.replace('_duplicate_', '') }); | ||
return null; | ||
@@ -324,12 +324,19 @@ } | ||
Object.entries(value).forEach(([k, v]) => { | ||
if(v === '_undefined_') { | ||
if (v === '_undefined_') { | ||
// eslint-disable-next-line no-param-reassign | ||
value[k] = undefined; | ||
} else if(!mutated.includes(v)) { | ||
} else if (!mutated.includes(v)) { | ||
mutated.push(v); | ||
mutateUndefined(v); | ||
} | ||
}) | ||
}); | ||
} | ||
} | ||
} | ||
if (Array.isArray(value)) { | ||
value.forEach(v => { | ||
mutated.push(v); | ||
mutateUndefined(v); | ||
}); | ||
} | ||
}; | ||
}; | ||
@@ -339,5 +346,5 @@ export const parse = (data: any) => { | ||
mutator()(result) | ||
mutator()(result); | ||
return result; | ||
}; |
@@ -126,7 +126,7 @@ import { stringify, parse, replacer, reviver } from '../src/index'; | ||
}; | ||
Fruit.parent.cyclic = Fruit; | ||
Fruit.cyclic = Fruit; | ||
const stringified = stringify(Fruit); | ||
const parsed = parse(stringified); | ||
expect(stringified).toEqual('{"apple":true,"parent":{"cyclic":"_duplicate_root"}}'); | ||
expect(stringified).toEqual('{"apple":true,"parent":{},"cyclic":"_duplicate_root"}'); | ||
expect(parsed.cyclic.cyclic.cyclic.cyclic).toBeDefined(); | ||
@@ -133,0 +133,0 @@ expect(parsed.cyclic).toBe(parsed); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46023
1108