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

jsof

v0.5.0

Published

liberal JSON

Downloads

31

Readme

JSOF (liberal JSON)

NPM version Tests Coveralls

Uses esprima, escodegen or shift-{parser, codegen} to parse and stringify an JavaScript values.

Why?

Reason 1

Do you think, that JSON is a bit verbose? restrictive? hard to comment?

Remember, you wrote something like the text below, gave it to JSON.parse() and got 30 errors? one by one?

{
    unquoted_key: "keys must be quoted",
    a1: ["extra comma",],
    a2: ["double extra comma",,],
    // single line comment
    "Illegal expression": 1 + 2,
    "Illegal invocation": alert(),
    "Numbers cannot have leading zeroes": 013,
    "Numbers cannot be hex": 0x14,
    a3: [
        "Illegal backslash escape: \x15",
        "Illegal backslash escape: \017",
        [[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]],
        "Bad value", truth,
        'single quote',
        /* multi-line comment */
        "    tab    character    in    string    ",
        "tab\   character\   in\  string\  ",
        "line\
        break"
    ],
    "Extra comma": true,
}

So, now you can use jsof.parse(), and everything is fine!

Reason 2

JSON.stringify(obj, null, 2);

{
  "a": [
    {"b": [
      [
        "string"
      ]
    ]}
  ],
  "c": 42
}

jsof.stringify(obj);

{
  a: [{b: 'string'}],
  c: 42
}

Reason 3

colors

Reason 4

References

Reason 5

no eval() no Yaml

Reason 6

Better error messages.

Use

Node.js

npm i jsof --save
var jsof = require('jsof');

API

jsof.parse()

jsof.p()

The jsof.parse() method parses a JS value string and returns a JavaScript value. Passes all 3 JSON pass tests. Also passes 18 of 33 JSON fail tests.

value = jsof.parse(text)

jsof.stringify()

jsof.s()

The jsof.stringify() method converts a JavaScript value to a JS string.

text = jsof.stringify(value)

jsof.shift.parse()

jsof.shift.p()

The same as jsof.parse() but using shift-* tools.

jsof.shift.stringify()

jsof.shift.s()

The same as jsof.stringify() but using shift-* tools.

Testing

npm test

License

MIT LICENSE.