Comparing version 3.0.3 to 3.1.0
@@ -12,6 +12,10 @@ interface Options { | ||
export declare const replacer: (options: Options) => (this: any, key: string, value: any) => any; | ||
export declare const reviver: () => (this: any, key: string, value: any) => any; | ||
interface ValueContainer { | ||
'_constructor-name_': string; | ||
[keys: string]: any; | ||
} | ||
export declare const reviver: () => (this: any, key: string, value: string | ValueContainer) => string | number | symbol | RegExp | Date | ValueContainer | ((...args: any[]) => any) | null; | ||
export declare const isJSON: (input: string) => RegExpMatchArray | null; | ||
export declare const stringify: (data: any, options?: Partial<Options>) => string; | ||
export declare const parse: (data: any) => any; | ||
export declare const parse: (data: string) => any; | ||
export {}; |
@@ -30,2 +30,4 @@ "use strict"; | ||
var isObject = _isobject["default"]; | ||
var removeCodeComments = function removeCodeComments(code) { | ||
@@ -192,3 +194,3 @@ var inQuoteChar = null; | ||
if (!found) { | ||
if (value && (0, _isobject["default"])(value) && value.constructor && value.constructor.name && value.constructor.name !== 'Object') { | ||
if (value && isObject(value) && value.constructor && value.constructor.name && value.constructor.name !== 'Object') { | ||
if (!options.allowClass) { | ||
@@ -252,3 +254,3 @@ return undefined; | ||
if ((0, _isobject["default"])(value) && value['_constructor-name_']) { | ||
if (isObject(value) && value['_constructor-name_']) { | ||
var name = value['_constructor-name_']; | ||
@@ -366,3 +368,3 @@ | ||
// we map over a deeply nester object, if we find any value with `_undefined_`, we mutate it to be undefined | ||
if ((0, _isobject["default"])(value)) { | ||
if (isObject(value)) { | ||
Object.entries(value).forEach(function (_ref6) { | ||
@@ -369,0 +371,0 @@ var _ref7 = _slicedToArray(_ref6, 2), |
{ | ||
"name": "telejson", | ||
"version": "3.0.3", | ||
"version": "3.1.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
import isRegExp from 'is-regex'; | ||
import isFunction from 'is-function'; | ||
import isSymbol from 'is-symbol'; | ||
import isObject from 'isobject'; | ||
import isObjectAny from 'isobject'; | ||
import get from 'lodash/get'; | ||
@@ -9,2 +9,4 @@ import transform from 'lodash/transform'; | ||
const isObject = isObjectAny as <T = object>(val: any) => val is T; | ||
const removeCodeComments = (code: string) => { | ||
@@ -78,3 +80,3 @@ let inQuoteChar = null; | ||
export const replacer = function replacer(options: Options) { | ||
let objects: any[]; | ||
let objects: { keys: string; value: any }[]; | ||
let stack: any[]; | ||
@@ -206,7 +208,12 @@ let keys: string[]; | ||
interface ValueContainer { | ||
'_constructor-name_': string; | ||
[keys: string]: any; | ||
} | ||
export const reviver = function reviver() { | ||
const refs: any[] = []; | ||
const refs: { target: string; container: { [keys: string]: any }; replacement: string }[] = []; | ||
let root: any; | ||
return function revive(this: any, key: string, value: any) { | ||
return function revive(this: any, key: string, value: ValueContainer | string) { | ||
// last iteration = root | ||
@@ -233,3 +240,3 @@ if (key === '') { | ||
// deal with instance names | ||
if (isObject(value) && value['_constructor-name_']) { | ||
if (isObject<ValueContainer>(value) && value['_constructor-name_']) { | ||
const name = value['_constructor-name_']; | ||
@@ -323,3 +330,3 @@ if (name !== 'Object') { | ||
// we map over a deeply nester object, if we find any value with `_undefined_`, we mutate it to be undefined | ||
if (isObject(value)) { | ||
if (isObject<{ [keys: string]: any }>(value)) { | ||
Object.entries(value).forEach(([k, v]) => { | ||
@@ -344,3 +351,3 @@ if (v === '_undefined_') { | ||
export const parse = (data: any) => { | ||
export const parse = (data: string) => { | ||
const result = JSON.parse(data, reviver()); | ||
@@ -347,0 +354,0 @@ |
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
40405
917