NaturalIntelligence / nimnjs

JS implementation of nimn specification
https://solothought.com/nimn
Other
45 stars 6 forks source link
compression decoder encoder json nimn nimnjs

nimnjs-node

JS implementation of nimn specification. Highly Compressed JS object/JSON. 60% or more compressed than JSON, 40% or more compressed than msgpack

Stubmatic donate button

Introduction

NIMN JS can parse JS object to nimn data and vice versa. See Nimn specification for more detail.

Usages

First install or add to your npm package

$npm install nimnjs
var nimn = require("nimnjs");

var objStructure = {
    type : "list",
    detail : {
        type : "map",
        detail : [{
            name : "name",
            type : "string"
        },{
            name : "age",
            type : "number"
        },{
            name : "isHuman",
            type : "boolean"
        },{
            name : "address",
            type : "string"
        },{
            name : "hobbies",
            type : "list",
            detail : {
                type : "string"
            }
        },{
            name : "project",
            type : "map",
            detail: [{
                name: "title",
                type : "string"
            },{
                name: "description",
                type : "string"
            },{
                name: "status",
                type : "string"
            }
            ]
        }
        ]
    }
}

var schema = nimn.buildSchema(objStructure);

var jData = [{
    "name" : "somename",
    "isHuman" : true,
    "age": 32,
    "address" : "I'll not tell you",
    hobbies : [ 
        null
        , "not reading "+ parser.chars.missingPremitive +" book"
        , "watching \\"+ parser.chars.nilPremitive +" movie"
    ],
    project : {
        title : "nimn",
        //description : "it is 80% smaller",
        status : "rocking"
    }
}]

var nimnDataString = nimn.stringify(schema, jData);
var result = nimn.parse(schema, nimnDataString);
expect(result).toEqual(jData); 

Flexibility

Note that the fields must be added or deleted in the end of the map (object)

Supported type

Include dist in your HTML to use it in browser.

Check the demo for instant use. It generates schema automatically with the help of schema builder when sample json is provided.

Support

Join the official organization on github to support it. It can not only save bandwidth but speed up communication, search and much more.