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 🙏

© 2025 – Pkg Stats / Ryan Hefner

schemaparser

v0.2.2

Published

Parse data into buffer and back using multiversional binary schema

Downloads

7

Readme

SchemaParser

NPM VERSION NPM DOWNLOADS

Parse data into buffer and back using multiversional binary schema


Example

Intro

To start working with parser use the constructor:

const parser = new Parser({
  schema1,
  schema2,
  ...
  schemaN
});

Simple parsing

Just pass object or buffer to parse method, and specify schema name:

const buffer = parser.parse(
  {
     ...
  },
  'schemaName'
);

const obj = parser.parse(buffer, 'schemaName');

Or if you use one schema more frequently than others

parser.use('schemaName');
const buffer = parser.parse({
  ...
});

Schemas

Schemas specify size(in bytes) for appropriate fields in objects. So this schema

{
  packetType: '1b',
  packetId: '4b',
  payloadLength: '4b',
  payload: 'payloadLength'
}

defines that packetType needs 1 byte, packetId - 4, payloadLength - 4 and payload needs <object to parse>.payloadLength bytes. It is recommended to define static size with string, like field: 'Nb', but you can specify it with a number field: N. You can also use functions to declare the behavior of the field's size depending on object to parse. For example:

{
  id: '2b',
  length: '8b',
  payload: obj => parseInt(obj.length, '10')
}

Parser supports multiple named schemas with multuiple versions. Default version is 1.0.0. NOTE: if field's size is greater than 4 bytes(more than Int32), it should be passed within a parser as a string.

Versions

For schemas updating and versioning you can use versions extension for parser. It works like:

const parser = new Parser(/* schemas */) // create a simple parser
const versioned = parser.versions() // here will be created a new parser instance, supporting versioning
                                    // and old simple parser will not change after this

Using versions extension you can easily update schemas without losing older ones. For version updating use semver contract:

parser.updateSchema(
  schemaName,
  newSchema,
  updateType // 'major', 'minor' or 'patch'
)

You can also use any version of schema to parse data, just specify version as a last parameter of parse method, it is latest by default:

parser.parse({ ... }, `schemaName`, `version`);