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

nano-json

v1.2.4

Published

A well formatted JS objects stringifyer

Downloads

28

Readme

Gitter NPM version [Build status] travis-url [Test coverage] coveralls-url Dependency Status License Downloads

nano-json

Well formatted(customizable) JSON like generator. Not compatible with pure JSON (smart strings/ids qouting).

Its very usefull for easy readble JS-objects dumps because you can define formats for sub-elements of objects deeply pretty.

API

id2str(id)

Returns quoted id value if it's keyword or not identifier.

id2str('blah'); // blah
id2str('blah-blah'); // 'blah-blah'
id2str('class'); // 'class'

str2str(str)

Returns quoted string. Automaticaly detects quotes symbols.

str2str('some string'); // 'some string'
str2str('some "" string with "double" quotes'); // 'some "" string with "double" quotes'
str2str("some '' string with 'single' quotes"); // "some '' string with 'single' quotes"

qstr(str)

Returns single qouted string.

qstr('some string'); // 'some string'
qstr('some "" string with "double" quotes'); // 'some "" string with "double" quotes'
qstr("some '' string with 'single' quotes"); // 'some \'\' string with \'single\' quotes'

dqstr(str)

Returns double quoted string.

dqstr('some string'); // "some string"
dqstr('some "" string with "double" quotes'); // "some \"\" string with \"double\" quotes"
dqstr("some '' string with 'single' quotes"); // "some '' string with 'single' quotes"

js2str(obj, default_radix, unarray)

  • obj Object;
  • default_radix Number - radix for number values (10 if undefined);
  • unarray Boolean - stringify root array as list (without square brackets).

Returns stringified object.

js2str([ 10, 20, 30 ], 10, 1); // 10,20,30
js2str([ 10, 20, 30 ], 10, 0); // [10,20,30]
js2str([ 10, 20, 30 ], 16, 0); // [0xa,0x14,0x28]
js2str({ a: 1 }); // {a:1}

render(obj[, style[, indent[, tab]]])

  • obj Object
  • style Object or String
    • String - list format string: '###'
    • Object - { '':'', ['":':1], ['<>:':][, :]* }
      • '':String - current object list format string: '###'
      • '":':Boolean - force qouting of object keys flag
      • '<>:':Number - minimal width of object keys (will be padded by spaces)
      • '#':Boolean - enable array items index number comments
      • ID:Object - style for sub-object with identifier ID
      • '*':Object - style for array sub-items
  • indent String - indent string ('' by default)
  • tab String - one indentation level spaces string

style samples

' #, # # '
var style = ' #, # # ';
render([ 1, 2, 3 ], style); // '[ 1, 2, 3 ]'
render([ 1 ], style); // '[ 1 ]'
render([ ], style); // '[ ]'
render({ a:1, b:2, c:3 }, style); // '{ a:1, b:2, c:3 }'
render({ a:1 }, style); // '{ a:1 }'
render({ }, style); // '{ }'
'#,##'
var style = '#,##';
render([ 1, 2, 3 ], style); // '[1,2,3]'
render([ 1 ], style); // '[1]'
render([ ], style); // '[]'
render({ a:1, b:2, c:3 }, style); // '{a:1,b:2,c:3}'
render({ a:1 }, style); // '{a:1}'
render({ }, style); // '{}'
'\n+#,\n+#\n=# '

Where the '+' symbol means next level of indentation.

var style = '\n+#,\n+#\n=# ';
render([ 1, 2, 3 ], style, '', ' '); // '[\n 1,\n 2,\n 3\n]'
render([ 1 ], style); // '[\n 1\n]'
render([ ], style); // '[ ]'
render({ a:1, b:2, c:3 }, style); // '{\n a:1,\n b:2,\n c:3\n}'
render({ a:1 }, style); // '{\n a:1\n}'
render({ }, style); // '{ }'