@sentry/utils
Advanced tools
Comparing version 4.6.3 to 4.6.4
@@ -66,3 +66,3 @@ import { Memo } from './memo'; | ||
*/ | ||
export declare function decycle(obj: any, memo?: Memo): any; | ||
export declare function decycle(obj: any, depth?: number, memo?: Memo): any; | ||
/** | ||
@@ -73,2 +73,2 @@ * safeNormalize() | ||
*/ | ||
export declare function safeNormalize(input: any): any; | ||
export declare function safeNormalize(input: any, depth?: number): any; |
@@ -1,2 +0,2 @@ | ||
import { isArray, isNaN, isPlainObject, isPrimitive, isSyntheticEvent, isUndefined } from './is'; | ||
import { isArray, isError, isNaN, isPlainObject, isPrimitive, isSyntheticEvent, isUndefined } from './is'; | ||
import { Memo } from './memo'; | ||
@@ -104,2 +104,3 @@ import { truncate } from './string'; | ||
const type = Object.prototype.toString.call(value); | ||
// Node.js REPL notation | ||
if (typeof value === 'string') { | ||
@@ -109,11 +110,10 @@ return truncate(value, 40); | ||
else if (type === '[object Object]') { | ||
// Node.js REPL notation | ||
return '[Object]'; | ||
} | ||
else if (type === '[object Array]') { | ||
// Node.js REPL notation | ||
return '[Array]'; | ||
} | ||
else { | ||
return normalizeValue(value); | ||
const normalized = normalizeValue(value); | ||
return isPrimitive(normalized) ? `${normalized}` : type; | ||
} | ||
@@ -236,5 +236,2 @@ } | ||
} | ||
if (value instanceof Error) { | ||
return objectifyError(value); | ||
} | ||
// tslint:disable-next-line:strict-type-predicates | ||
@@ -265,25 +262,25 @@ if (typeof Event !== 'undefined' && value instanceof Event) { | ||
*/ | ||
export function decycle(obj, memo = new Memo()) { | ||
// tslint:disable-next-line:no-unsafe-any | ||
const copy = isArray(obj) ? obj.slice() : isPlainObject(obj) ? assign({}, obj) : obj; | ||
export function decycle(obj, depth = +Infinity, memo = new Memo()) { | ||
if (depth === 0) { | ||
return serializeValue(obj); | ||
} | ||
// If an object was normalized to its string form, we should just bail out as theres no point in going down that branch | ||
const normalized = normalizeValue(obj); | ||
// If an object was normalized to its string form, we should just bail out as theres no point in going down that branch | ||
if (typeof normalized === 'string') { | ||
if (isPrimitive(normalized)) { | ||
return normalized; | ||
} | ||
if (!isPrimitive(obj)) { | ||
if (memo.memoize(obj)) { | ||
return '[Circular ~]'; | ||
// tslint:disable-next-line:no-unsafe-any | ||
const source = (isError(obj) ? objectifyError(obj) : obj); | ||
const copy = isArray(obj) ? [] : {}; | ||
if (memo.memoize(obj)) { | ||
return '[Circular ~]'; | ||
} | ||
for (const key in source) { | ||
// Avoid iterating over fields in the prototype if they've somehow been exposed to enumeration. | ||
if (!Object.prototype.hasOwnProperty.call(source, key)) { | ||
continue; | ||
} | ||
// tslint:disable-next-line | ||
for (const key in obj) { | ||
// Avoid iterating over fields in the prototype if they've somehow been exposed to enumeration. | ||
if (!Object.prototype.hasOwnProperty.call(obj, key)) { | ||
continue; | ||
} | ||
// tslint:disable-next-line | ||
copy[key] = decycle(obj[key], memo); | ||
} | ||
memo.unmemoize(obj); | ||
copy[key] = decycle(source[key], depth - 1, memo); | ||
} | ||
memo.unmemoize(obj); | ||
return copy; | ||
@@ -299,4 +296,5 @@ } | ||
function serializer(options = { normalize: true }) { | ||
return (key, value) => | ||
// tslint:disable-next-line | ||
return (key, value) => (options.normalize ? normalizeValue(decycle(value), key) : decycle(value)); | ||
options.normalize ? normalizeValue(decycle(value, options.depth), key) : decycle(value, options.depth); | ||
} | ||
@@ -308,5 +306,5 @@ /** | ||
*/ | ||
export function safeNormalize(input) { | ||
export function safeNormalize(input, depth) { | ||
try { | ||
return JSON.parse(JSON.stringify(input, serializer({ normalize: true }))); | ||
return JSON.parse(JSON.stringify(input, serializer({ normalize: true, depth }))); | ||
} | ||
@@ -313,0 +311,0 @@ catch (_oO) { |
@@ -66,3 +66,3 @@ import { Memo } from './memo'; | ||
*/ | ||
export declare function decycle(obj: any, memo?: Memo): any; | ||
export declare function decycle(obj: any, depth?: number, memo?: Memo): any; | ||
/** | ||
@@ -73,2 +73,2 @@ * safeNormalize() | ||
*/ | ||
export declare function safeNormalize(input: any): any; | ||
export declare function safeNormalize(input: any, depth?: number): any; |
@@ -111,2 +111,3 @@ "use strict"; | ||
var type = Object.prototype.toString.call(value); | ||
// Node.js REPL notation | ||
if (typeof value === 'string') { | ||
@@ -116,11 +117,10 @@ return string_1.truncate(value, 40); | ||
else if (type === '[object Object]') { | ||
// Node.js REPL notation | ||
return '[Object]'; | ||
} | ||
else if (type === '[object Array]') { | ||
// Node.js REPL notation | ||
return '[Array]'; | ||
} | ||
else { | ||
return normalizeValue(value); | ||
var normalized = normalizeValue(value); | ||
return is_1.isPrimitive(normalized) ? "" + normalized : type; | ||
} | ||
@@ -254,5 +254,2 @@ } | ||
} | ||
if (value instanceof Error) { | ||
return objectifyError(value); | ||
} | ||
// tslint:disable-next-line:strict-type-predicates | ||
@@ -283,26 +280,27 @@ if (typeof Event !== 'undefined' && value instanceof Event) { | ||
*/ | ||
function decycle(obj, memo) { | ||
function decycle(obj, depth, memo) { | ||
if (depth === void 0) { depth = +Infinity; } | ||
if (memo === void 0) { memo = new memo_1.Memo(); } | ||
// tslint:disable-next-line:no-unsafe-any | ||
var copy = is_1.isArray(obj) ? obj.slice() : is_1.isPlainObject(obj) ? assign({}, obj) : obj; | ||
if (depth === 0) { | ||
return serializeValue(obj); | ||
} | ||
// If an object was normalized to its string form, we should just bail out as theres no point in going down that branch | ||
var normalized = normalizeValue(obj); | ||
// If an object was normalized to its string form, we should just bail out as theres no point in going down that branch | ||
if (typeof normalized === 'string') { | ||
if (is_1.isPrimitive(normalized)) { | ||
return normalized; | ||
} | ||
if (!is_1.isPrimitive(obj)) { | ||
if (memo.memoize(obj)) { | ||
return '[Circular ~]'; | ||
// tslint:disable-next-line:no-unsafe-any | ||
var source = (is_1.isError(obj) ? objectifyError(obj) : obj); | ||
var copy = is_1.isArray(obj) ? [] : {}; | ||
if (memo.memoize(obj)) { | ||
return '[Circular ~]'; | ||
} | ||
for (var key in source) { | ||
// Avoid iterating over fields in the prototype if they've somehow been exposed to enumeration. | ||
if (!Object.prototype.hasOwnProperty.call(source, key)) { | ||
continue; | ||
} | ||
// tslint:disable-next-line | ||
for (var key in obj) { | ||
// Avoid iterating over fields in the prototype if they've somehow been exposed to enumeration. | ||
if (!Object.prototype.hasOwnProperty.call(obj, key)) { | ||
continue; | ||
} | ||
// tslint:disable-next-line | ||
copy[key] = decycle(obj[key], memo); | ||
} | ||
memo.unmemoize(obj); | ||
copy[key] = decycle(source[key], depth - 1, memo); | ||
} | ||
memo.unmemoize(obj); | ||
return copy; | ||
@@ -320,4 +318,6 @@ } | ||
if (options === void 0) { options = { normalize: true }; } | ||
// tslint:disable-next-line | ||
return function (key, value) { return (options.normalize ? normalizeValue(decycle(value), key) : decycle(value)); }; | ||
return function (key, value) { | ||
// tslint:disable-next-line | ||
return options.normalize ? normalizeValue(decycle(value, options.depth), key) : decycle(value, options.depth); | ||
}; | ||
} | ||
@@ -329,5 +329,5 @@ /** | ||
*/ | ||
function safeNormalize(input) { | ||
function safeNormalize(input, depth) { | ||
try { | ||
return JSON.parse(JSON.stringify(input, serializer({ normalize: true }))); | ||
return JSON.parse(JSON.stringify(input, serializer({ normalize: true, depth: depth }))); | ||
} | ||
@@ -334,0 +334,0 @@ catch (_oO) { |
{ | ||
"name": "@sentry/utils", | ||
"version": "4.6.3", | ||
"version": "4.6.4", | ||
"description": "Utilities for all Sentry JavaScript SDKs", | ||
@@ -5,0 +5,0 @@ "repository": "git://github.com/getsentry/sentry-javascript.git", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
271993
3782