@fullstory/safe-stringify
v1.0.0
Published
Fullstory safe stringify
Downloads
5
Readme
Fullstory safe stringify
Safe stringify is a utility function that stringifies a variety of JavaScript data types and structures like Objects, Arrays, and Dates. It tries its best to mirror what console.log
would print in the JS console.
Installation
with npm
npm i @fullstory/safe-stringify --save
with yarn
yarn add @fullstory/safe-stringify
Exports
safeStringify(o, maxChars)
Parameters
o
|<any>
The data to stringify.maxChars
|<number>
The length of the stringified result before truncation. Defaults to 1024.
Usage
Returns a stringified version of the data passed.
Examples
{
const arr = [1, 2, 3, [4, 5, [6, 7, 8], 9], 10];
const resultArr = safeStringify(arr);
// resultArr === "[1,2,3,[4,5,[6,7,8],9],10]"
const obj = { a: 1, b: 2, c: null, d: undefined, e: 'asdf' };
const resultObj = safeStringify(obj);
// resultObj === '{"a":1,"b":2,"c":null,"d":"undefined","e":"asdf"}'
}