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

j2n

v1.2.0

Published

A more space efficient JSON and J2N parser and J2N stringifier with comments

Downloads

3

Readme

J2N

J2N is a .json and .j2n parser. It also stringifies into .j2n format.

Main purpose of J2N is to shorten on json file size by removing any unecessary characters

It also can serialize Date $D<ms> and RegExp $E{F:<flags>,S:<source>}

It can serialize circular references $R<order>

Strings can begin with:

  • ~ - where , or array or object end is the end of the string terminator. These characters have to be backslashed inside the string.
  • ' - where ' is the string terminator. It has to be bachslashed inside the string.
  • " - where " is the string terminator. It has to be bachslashed inside the string.

Strings use \t, \n and \r. If you use an actual tab or newline, it will be ignored. You can use this for prettying your j2n.

Keywords:

  • / - undefined
  • - - false
  • + - true
  • $<k> - special. k:
    • $ - null
    • R<order> - reference to an already existing object or function
    • F<string> - Function
    • D<ms> - Date
    • E{F:<flags>,S:<source>} - RegExp

In Keys , doesn't end the key name, but : does. This character has to be bachslashed to be included in the name.

Keys behave like strings, but don't begin with ~ if they don't have to.

You can comment the file as well:

  • # opens a comment or closes it. New line closes a comment as well.
  • If you enabled tabs in the stringify method, it will comment all objects with their respective $R<order> order.

The stringify method chooses the most space efficient metod of storing a string.

The parse method accepts J2N as well as regular JSON.

Docs: J2N.stringify( value: any[, tabs: boolean[, tokenize: ( text: string, type: J2N.types, secondaryType: J2N.types ) => string ] ] ): string

  • value: Any js value to be stringified.
  • tabs: Whether to make the text formated ( default: false - single line ).
    • As of 1.2.0 the stringify method accepts a third parameter, which supplied with text and event type has to return a tokenized string. You might use this to color code your J2N files.
    • tokenize: A callback that modyfies the string for each value and keyword. See the J2N.types enum for a list of types.
  • Returns a string in J2N format.

J2N.parse( string: string ): any

  • string A string in J2N or JSON format.
  • Returns any.

J2N.types: enum

  • An enum of all value and keyword types.

Example:

const J2N = require( 'j2n' );

let value = '\n\
[\n\
    +,\n\
    -,\n\
    /,\n\
    $$,\n\
    $E{F:~g,S:~I am a regular expression}, # also this is a comment\n\
    $F~( v ) => { return v; },\n\
    $D100,\n\
    83# I can comment even there #566,\n\
    ~ Stringy   ,\n\
    \',,,,,,,,,,,,,,\',\n\
    true,\n\
    undefined,\n\
    {\n\
        key: ~value,\n\
        N: null,\n\
        F: false,\n\
        Parent: $R0,\n\
        Me: $R4,\n\
        Date: $R3,\n\
        PerentFunc: $R2,\n\
        RegExp: $R1\n\
    },\n\
    ~# but this is a part of the string #,\n\
    $R0\n\
]';

console.log( J2N.parse( value ) );

Output:

[
    true,
    false,
    undefined,
    null,
    /I am a regular expression/g,
    function (),
    Date 1970-01-01T00:00:00.100Z,
    83566,
    " Stringy   ",
    ",,,,,,,,,,,,,,",
    true,
    undefined,
    {
        key: "value",
        N: null,
        F: false,
        Parent: [ ... ],
        Me: { ... },
        Date: Date 1970-01-01T00:00:00.100Z,
        ParentFunc: function (),
        RegExp: /I am a regular expression/g
    },
    "# but this is a part of the string #",
    [ ... ]
]