npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

yea-stringify

v1.0.1

Published

Yet Another JSON.stringify with some additional features.

Downloads

9

Readme

yea-stringify

DESCRIPTION

Yet another JSON.stringify implementation. Some extra features are available. It can remove the properties by the replacer function and render the circular reference objects.

Repositories

OPTIONS

Following options are available to change the bahavior. For detail, see the sample 'Change the rendering options'.

| option | Description | Default setting | |:--------------------------|:----------------------------------------------------------------------|:-----------------:| |eliminate-undefined | The value of undefined will be eliminated | false | |eliminate-recursive | The circular referencing object will be eliminated | false | |show-recursive-reference | The original object path that is circular referenced will be shown | true | |show-function | The function object apears in list | false | |show-index | The index of array apears as comment | false | |show-length | The length of array or object's keys apear as comment | false | |sort-keys | The keys of object are sorted by the name | false |

Using replacer function's extra parameter

Replacer function accepts an extra 3rd parameter. It is an object that contains following keys to notify the item status or manipurate the behavior.

|Property | Description | |:--------------|:----------------------------------------------------------------------| | recursive | This indicates the value is circular referencing the other object | | eliminate | If the replacer set this true, the key and value will not be listed |

For detail, see the sample 'Using replacer function'.

SAMPLE

Stringify the circular referencing object

This can stringify the object having circular reference member like global.

sample/circular-ref.js

(function() {
    "use strict";
    const JSON_stringify = require("yea-stringify");
    var global_object = new Function("return this")();
    console.log("global =", JSON_stringify(global_object, null, 4));
}());

outputs:

$ node sample/circular-ref.js
global = {
    "global": { /* RECURSIVE REFERENCE to $(ROOT) */ },
    "process": {
        "title": "....",
        "version": "v4.4.1",
        "moduleLoadList": [
            "Binding contextify",
            "Binding natives",
            "NativeModule events",
            "NativeModule buffer",
            "Binding buffer",

            .
            .
            .

        "stdin": {
            "_connecting": false,
            "_hadError": false,
            "_handle": {
                "_externalStream": {},
                "fd": -1,
                "writeQueueSize": 0,
                "owner": { /* RECURSIVE REFERENCE to $(ROOT).process */ },
                "reading": false
            },

By default, the circular reference objects are rendered as empty object with comment. This can be changed by option.

Change the rendering options

sample/change-opts.js

(function() {
    "use strict";
    const JSON_stringify = require("yea-stringify");
    JSON_stringify.setOption({
        "eliminate-undefined": false,
        "eliminate-recursive": false,
        "show-recursive-reference": true,
        "show-function": true,
        "show-index" : true,
        "show-length" : true,
        "sort-keys" : true
    });
    var obj = new Function("return this")();
    console.log("global =", JSON_stringify(obj, null, 4));
}());

outputs:

$ node sample/change-opts.js
global = { /* 24 keys */
    "Buffer": function(){},
    "COUNTER_HTTP_CLIENT_REQUEST": function(){},
    "COUNTER_HTTP_CLIENT_RESPONSE": function(){},
    "COUNTER_HTTP_SERVER_REQUEST": function(){},

                .
                .
                .

    "root": { /* RECURSIVE REFERENCE to $(ROOT) */ },
    "setImmediate": function(){},
    "setInterval": function(){},
    "setTimeout": function(){}
}

Using replacer function

In replacer, extra option parameter is available.

sample/use-replacer.js

(function() {
    "use strict";
    const JSON_stringify = require("yea-stringify").setOption({
        "show-length" : true,
    });
    var obj = new Function("return this")();
    var replacer = function(key, value, opt) {
        if(opt) {
            // eliminate primitive properties.
            if(value == null || typeof(value) != "object") {
                opt.eliminate = true;
                return undefined;
            }
        }
        return value;
    };
    console.log("global =", JSON_stringify(obj, replacer, 4));
}());

outputs:

$ node sample/use-replacer.js
global = { /* 24 keys */
    "global": { /* RECURSIVE REFERENCE to $(ROOT) */ },
    "process": { /* 55 keys */
        "moduleLoadList": [ /* 38 elements */ ],
        "versions": { /* 9 keys */ },
        "release": { /* 5 keys */ },
        "argv": [ /* 2 elements */ ],
        "execArgv": [ /* 0 elements */ ],
        "env": { /* 65 keys */ },
        "features": { /* 7 keys */ },
        "_events": { /* 3 keys */
            "SIGWINCH": [ /* 2 elements */ ]
        },
        "config": { /* 2 keys */
            "target_defaults": { /* 5 keys */
                "cflags": [ /* 0 elements */ ],
                "defines": [ /* 0 elements */ ],
                "include_dirs": [ /* 0 elements */ ],
                "libraries": [ /* 0 elements */ ]
            },
            "variables": { /* 34 keys */ }
        },
        "stdout": { /* 30 keys */
            "_handle": { /* 5 keys */
                "_externalStream": { /* 0 keys */ },
                "owner": { /* RECURSIVE REFERENCE to $(ROOT).process */ }
            },
            "_readableState": { /* 21 keys */
                "buffer": [ /* 0 elements */ ]
            },
            "_events": { /* 3 keys */ },
            "_writableState": { /* 23 keys */
                "corkedRequestsFree": { /* 3 keys */
                    "next": { /* 3 keys */ }
                }
            }
        },
        "stderr": { /* 30 keys */
            "_handle": { /* 5 keys */
                "_externalStream": { /* 0 keys */ },
                "owner": { /* RECURSIVE REFERENCE to $(ROOT).process */ }
            },
            "_readableState": { /* 21 keys */
                "buffer": [ /* 0 elements */ ]
            },
            "_events": { /* 3 keys */ },
            "_writableState": { /* 23 keys */
                "corkedRequestsFree": { /* 3 keys */
                    "next": { /* 3 keys */ }
                }
            }
        },
        "stdin": { /* 26 keys */
            "_handle": { /* 6 keys */
                "_externalStream": { /* 0 keys */ },
                "owner": { /* RECURSIVE REFERENCE to $(ROOT).process */ }
            },
            "_readableState": { /* 21 keys */
                "buffer": [ /* 0 elements */ ]
            },
            "_events": { /* 4 keys */ },
            "_writableState": { /* 23 keys */
                "corkedRequestsFree": { /* 3 keys */
                    "next": { /* 3 keys */ }
                }
            }
        },
        "mainModule": { /* 7 keys */
            "exports": { /* 0 keys */ },
            "children": [ /* 1 elements */
                { /* 7 keys */
                    "parent": { /* RECURSIVE REFERENCE to $(ROOT).process */ },
                    "children": [ /* 0 elements */ ],
                    "paths": [ /* 7 elements */ ]
                }
            ],
            "paths": [ /* 7 elements */ ]
        }
    },
    "GLOBAL": { /* RECURSIVE REFERENCE to $(ROOT) */ },
    "root": { /* RECURSIVE REFERENCE to $(ROOT) */ },
    "console": { /* 10 keys */ }
}

LICENSE

MIT