@fullstory/safe-stringify
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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"}'
}

Readme

Keywords

none

Package Sidebar

Install

npm i @fullstory/safe-stringify

Weekly Downloads

2

Version

1.0.0

License

ISC

Unpacked Size

16.6 kB

Total Files

5

Last publish

Collaborators

  • fs-npm-bot
  • patrick-fs