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

joscompress

v0.5.8

Published

Optimizes JSON sizes through a schema format.

Downloads

12

Readme

JS Object Schema Compression

Optimizes JSON sizes through a schema format.

The Front-end build can be accessed here

Tutorial

Schema

The first step to using JOSC is to initialize the schema. The schema must be either an object or an array, the first entry of an array and each property should indicate the type of data contained. This is not checked, but could cause unforseen errors if you do not. As of the types are denonted as so:

  • Arrays are indicate with brackets containing the data type. | Example: ['int']
  • Objects are indicated with braces and contain the keys and data types. | Example: {foobar: 'string'}
  • Strings, ints, bools, and floats can be indicated with their names, as a lowercase string. | 'string', 'int', 'bool', 'float'
  • Other types it is recommended you JSON.stringify() them then pass as 'string', after decoding put them through JSON.parse().

You can now initialize the main class of the library with that object/array. This returns a new Schema object.

Encoding

The rest of the usage is very simple. All you need to do with your new Schema object is to run the function encode inputting the object you want to encode, it does not have to match the Schema. This will return an encoded string to be used how you like.

Decoding

Simply pass the encoded string to the Schema objects decode function. This string must match the Schema. It will return the decoded object.

Example

var JOSC = require('JOSC');
var schema = new JOSC(
  {
    A: "string",
    B: "string",
    C: ["int"],
    D: {
        a: {},
        b: [{c: "float"}]
    },
    E: "float",
    F: "bool"
  }
);

var object = {
    A: "foobar",
    B: "this will be for escape testing",
    C: [1,2,3],
    D: {
        a: {},
        b: [{c: 4.2}]
    },
    E: 12.312,
    F: true
};

//  Encode the object
var encoded_string = schema.encode(object);

// Decode the object
var decoded_object = schema.decode(encoded_string);

// The decoded_object and object should be equal.