New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

stringify-x

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stringify-x

Enhanced object stringifier for JavaScript

latest
Source
npmnpm
Version
3.0.0
Version published
Maintainers
1
Created
Source

stringifyX.js

Enhanced object stringifier for JavaScript

Features

stringify-x works similar to JSON.stringify with the following enhancements:

  • Regex values are displayed in their string form
  • undefined values are written out as the string "*undefined*"
  • null values are written out as the string "*null*"
  • Functions are displayed as their name suffixed by parentheses e.g., fn()
  • Circular references can be handled up to a specified maximum depth
  • Other primitive values are displayed as their string representation

API

stringify(obj, maxDepth); // stringifies obj up to optional maxDepth

Example

var stringify = require("stringify-x");

var _object = {
    _boolean: false,
    _string: "Hello",
    _date: new Date(),
    _number: 123,
    _null: null,
    _undefined: undefined,
    _regexp: /abc[0-9]+/g,
    _array: [1, 2, "three"],
    _function: function hello() {},
    _object: {
        _boolean: true,
        _string: "World",
        _date: new Date(2011, 10, 30),
        _number: -123.123456789,
        _regexp: new RegExp('a-z'),
        _array: ["a", "b", "c"],
        _function: function() {},
        _object: {
            _boolean: true,
            _string: "Hello World",
            _date: new Date(2011, 10, 30),
            _number: -123.123456789,
            _regexp: new RegExp('a-z'),
            _array: ["a", "b", "c"],
            _function: function() {}
        }
    }
}

// use custom maxDepth of 1
console.log(stringify(_object, 1));

// use default maxDepth (10)
console.log(stringify(_object));

console.log("implicit undefined value: " + stringify());
console.log("undefined value: " + stringify(undefined));
console.log('"undefined" string: ' + stringify("undefined"));
console.log("null value: " + stringify(null));
console.log('"null" string: ' + stringify("null"));

Result:

{_boolean: false,_string: "Hello",_date: Mon Sep 12 2016 13:53:07 GMT-0700 (PDT),_number: 123,_null: *null*,_undefined: *undefined*,_regexp: /abc[0-9]+/g,_array: "1,2,three",_function: hello(),_object: "[object Object]"}
{_boolean: false,_string: "Hello",_date: Mon Sep 12 2016 13:53:07 GMT-0700 (PDT),_number: 123,_null: *null*,_undefined: *undefined*,_regexp: /abc[0-9]+/g,_array: [1,2,"three"],_function: hello(),_object: {_boolean: true,_string: "World",_date: Wed Nov 30 2011 00:00:00 GMT-0800 (PST),_number: -123.123456789,_regexp: /a-z/,_array: ["a","b","c"],_function: (),_object: {_boolean: true,_string: "Hello World",_date: Wed Nov 30 2011 00:00:00 GMT-0800 (PST),_number: -123.123456789,_regexp: /a-z/,_array: ["a","b","c"],_function: ()}}}

implicit undefined value: *undefined*
undefined value: *undefined*
"undefined" string: "undefined"
null value: *null*
"null" string: "null"

Install

npm install stringify-x --save

Keywords

stringify

FAQs

Package last updated on 12 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts