Socket
Socket
Sign inDemoInstall

@sentry/utils

Package Overview
Dependencies
Maintainers
8
Versions
502
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sentry/utils - npm Package Compare versions

Comparing version 4.4.1 to 4.4.2

6

object.d.ts

@@ -64,1 +64,7 @@ /**

export declare function assign(target: any, ...args: any[]): object;
/**
* safeNormalize()
*
* Creates a copy of the input by applying standardizer function on it and parsing it back to unify the data
*/
export declare function safeNormalize(input: any): any;

199

object.js

@@ -5,81 +5,2 @@ "use strict";

/**
* Transforms Error object into an object literal with all it's attributes
* attached to it.
*
* Based on: https://github.com/ftlabs/js-abbreviate/blob/fa709e5f139e7770a71827b1893f22418097fbda/index.js#L95-L106
*
* @param error An Error containing all relevant information
* @returns An object with all error properties
*/
function objectifyError(error) {
// These properties are implemented as magical getters and don't show up in `for-in` loop
var err = {
message: error.message,
name: error.name,
stack: error.stack,
};
for (var i in error) {
if (Object.prototype.hasOwnProperty.call(error, i)) {
err[i] = error[i];
}
}
return err;
}
var NAN_VALUE = '[NaN]';
var UNDEFINED_VALUE = '[undefined]';
/**
* Serializer function used as 2nd argument to JSON.serialize in `serialize()` util function.
*/
function serializer() {
var stack = [];
var keys = [];
var cycleReplacer = function (_, value) {
if (stack[0] === value) {
return '[Circular ~]';
}
return "[Circular ~." + keys.slice(0, stack.indexOf(value)).join('.') + "]";
};
return function (key, value) {
var currentValue = value;
// NaN and undefined are not JSON.parseable, but we want to preserve this information
if (is_1.isNaN(value)) {
currentValue = NAN_VALUE;
}
else if (is_1.isUndefined(value)) {
currentValue = UNDEFINED_VALUE;
}
if (stack.length > 0) {
var thisPos = stack.indexOf(this);
if (thisPos !== -1) {
stack.splice(thisPos + 1);
keys.splice(thisPos, Infinity, key);
}
else {
stack.push(this);
keys.push(key);
}
if (stack.indexOf(currentValue) !== -1) {
currentValue = cycleReplacer.call(this, key, currentValue);
}
}
else {
stack.push(currentValue);
}
return currentValue instanceof Error ? objectifyError(currentValue) : currentValue;
};
}
/**
* Reviver function used as 2nd argument to JSON.parse in `deserialize()` util function.
*/
function reviver(_key, value) {
// NaN and undefined are not JSON.parseable, but we want to preserve this information
if (value === NAN_VALUE) {
return NaN;
}
if (value === UNDEFINED_VALUE) {
return undefined;
}
return value;
}
/**
* Serializes the given object into a string.

@@ -97,3 +18,3 @@ * Like JSON.stringify, but doesn't throw on circular references.

function serialize(object) {
return JSON.stringify(object, serializer());
return JSON.stringify(object);
}

@@ -109,3 +30,3 @@ exports.serialize = serialize;

function deserialize(str) {
return JSON.parse(str, reviver);
return JSON.parse(str);
}

@@ -284,2 +205,118 @@ exports.deserialize = deserialize;

exports.assign = assign;
/**
* Transforms Error object into an object literal with all it's attributes
* attached to it.
*
* Based on: https://github.com/ftlabs/js-abbreviate/blob/fa709e5f139e7770a71827b1893f22418097fbda/index.js#L95-L106
*
* @param error An Error containing all relevant information
* @returns An object with all error properties
*/
function objectifyError(error) {
// These properties are implemented as magical getters and don't show up in `for-in` loop
var err = {
message: error.message,
name: error.name,
stack: error.stack,
};
for (var i in error) {
if (Object.prototype.hasOwnProperty.call(error, i)) {
err[i] = error[i];
}
}
return err;
}
/**
* standardizeValue()
*
* translates undefined/NaN values to "[undefined]"/"[NaN]" respectively,
* serializes Error objects
* filter global objects
*/
function standardizeValue(value, key) {
if (key === 'domain' && typeof value === 'object' && value._events) {
return '[Domain]';
}
if (key === 'domainEmitter') {
return '[DomainEmitter]';
}
if (typeof global !== 'undefined' && value === global) {
return '[Global]';
}
if (typeof window !== 'undefined' && value === window) {
return '[Window]';
}
if (typeof document !== 'undefined' && value === document) {
return '[Document]';
}
if (value instanceof Date) {
return "[Date] " + value;
}
if (value instanceof Error) {
return objectifyError(value);
}
if (is_1.isNaN(value)) {
return '[NaN]';
}
if (is_1.isUndefined(value)) {
return '[undefined]';
}
if (typeof value === 'function') {
return "[Function] " + (value.name || '<unknown-function-name>');
}
return value;
}
/**
* standardizer()
*
* Remove circular references,
* translates undefined/NaN values to "[undefined]"/"[NaN]" respectively,
* and takes care of Error objects serialization
*/
function standardizer() {
var stack = [];
var keys = [];
/** recursive */
function cycleStandardizer(_key, value) {
if (stack[0] === value) {
return '[Circular ~]';
}
return "[Circular ~." + keys.slice(0, stack.indexOf(value)).join('.') + "]";
}
return function (key, value) {
if (stack.length > 0) {
var thisPos = stack.indexOf(this);
if (thisPos === -1) {
stack.push(this);
keys.push(key);
}
else {
stack.splice(thisPos + 1);
keys.splice(thisPos, Infinity, key);
}
if (stack.indexOf(value) !== -1) {
// tslint:disable-next-line:no-parameter-reassignment
value = cycleStandardizer.call(this, key, value);
}
}
else {
stack.push(value);
}
return standardizeValue(value, key);
};
}
/**
* safeNormalize()
*
* Creates a copy of the input by applying standardizer function on it and parsing it back to unify the data
*/
function safeNormalize(input) {
try {
return JSON.parse(JSON.stringify(input, standardizer()));
}
catch (_oO) {
return '**non-serializable**';
}
}
exports.safeNormalize = safeNormalize;
//# sourceMappingURL=object.js.map
{
"name": "@sentry/utils",
"version": "4.4.1",
"version": "4.4.2",
"description": "Utilities for all Sentry JavaScript SDKs",

@@ -16,3 +16,3 @@ "repository": "git://github.com/getsentry/raven-js.git",

"dependencies": {
"@sentry/types": "4.4.1",
"@sentry/types": "4.4.2",
"tslib": "^1.9.3"

@@ -19,0 +19,0 @@ },

Sorry, the diff of this file is not supported yet

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