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 🙏

© 2026 – Pkg Stats / Ryan Hefner

nl-marshal

v0.2.0-rc.10

Published

Simple NodeJS utility to serialize or deserialize JS objects to Buffer or JSON.

Readme

NL-Marshal

Simple NodeJS utility to serialize or deserialize JS objects to Buffer or JSON.

Serializers

Boolean

Serialized buffer is 0x01 if serialized value is true and 0x00 otherwise.

import { bool } from "nl-marshal";
console.log(bool.toJSON(true)); // true
console.log(bool.fromJSON(false)); // false
const buffer = bool.toBuffer(true);
console.log(buffer); // 0x01
console.log(bool.toBuffer(false)); // 0x00
console.log(bool.fromBuffer(buffer)); // true

Empty

Serialized buffer is always empty. In JSON representation null will be used.

import { empty } from "nl-marshal";
console.log(empty.toJSON(undefined)); // null
console.log(empty.toJSON(null)); // null
console.log(empty.fromJSON(null)); // null
console.log(empty.toBuffer(undefined)); // <Buffer >
console.log(empty.toBuffer(null)); // <Buffer >
console.log(empty.fromBuffer(Buffer.from([]))); // null

Optional

Used to serialize optional values. Serialized buffer contains bool-byte at the start to show, value provided or not. In JSON representation returns null if no value provided.

import { optional, bool } from "nl-marshal";
const serializer = optional(bool);
console.log(serializer.toJSON(true)); // true
console.log(serializer.toJSON(undefined)); // null
console.log(serializer.toJSON(null)); // null
console.log(serializer.fromJSON(false)); // false
console.log(serializer.fromJSON(null)); // null
console.log(serializer.toBuffer(true)); // <Buffer 01 01>
console.log(serializer.toBuffer(undefined)); // <Buffer 00>
console.log(serializer.fromBuffer(Buffer.from('0100', 'hex'))); // false
console.log(serializer.fromBuffer(Buffer.from([0]))); // null

String

Serialized buffer contains length of string as varuint and utf-8 string.

import { string } from "nl-marshal";
console.log(string.toJSON('qwe')); // "qwe"
console.log(string.fromJSON('qwe')); // "qwe"
console.log(string.toBuffer('qwe')); // <Buffer 83 71 77 65>
console.log(string.fromBuffer(Buffer.from('83717765', 'hex'))); // "qwe"

Struct

import { struct, bool, string } from "nl-marshal";
const serializer = struct({ b: bool, s: string });
console.log(serializer.toJSON({ b: true, s: 'qwe' }));
// { b: true, s: "qwe" }
console.log(serializer.fromJSON({ s: 'qwe', b: true }));
// { b: true, s: "qwe" }
console.log(serializer.toBuffer({ s: 'qwe', b: true }));
// <Buffer 01 83 71 77 65>
console.log(serializer.fromBuffer(Buffer.from('0183717765', 'hex')));
// { b: true, s: "qwe" }

Varuint

Serializer for unsigned integers of unknown size. Serialized value can be string, number or BigNumber.

import { varuint, BigNumber } from "nl-marshal";
console.log(varuint.toJSON(123));
// 123
console.log(varuint.toJSON('123'));
// 123
console.log(varuint.toJSON(new BigNumber(123456789123456789)));
// "123456789123456789"
console.log(varuint.fromJSON('123'));
// <BigNumber 123>
console.log(varuint.toBuffer(123));
// <Buffer fb>
console.log(varuint.fromBuffer(Buffer.from('fb', 'hex')));
// <BigNumber 123>

UFixed

Serializer for unsigned fixed point numbers. Serialized value can be string, number or BigNumber. First argument is decimal places. The second one is boolean round, default is true.

import { ufixed, BigNumber } from "nl-marshal";
console.log(ufixed(4).toJSON(123.45678));
// 123.45678
console.log(ufixed(4).toJSON('123.45678'));
// 123.45678
console.log(ufixed(4).toJSON(new BigNumber('123456789123456789.987654321')));
// "123456789123456789.9877"
console.log(ufixed(4).fromJSON('123.456789'));
// <BigNumber 123.456789>
console.log(ufixed(4).toBuffer(123.456789));
// <Buffer 4b 2d 88>
console.log(ufixed(4).fromBuffer(Buffer.from('4b2d88', 'hex')));
// <BigNumber 123.4568>

Vector

Serializer for vector of static type. Serialized buffer starts with length of value as varuint

import { vector, varuint, BigNumber } from "nl-marshal";
const serializer = vector(varuint);
console.log(serializer.toJSON([123, '234', new BigNumber(345)]));
// ["123", "234", "345"]
console.log(serializer.fromJSON(['123', '234', '345']));
// [<BigNumber 123>, <BigNumber 234>, <BigNumber 345>]
console.log(serializer.toBuffer([123, '234', new BigNumber(345)]));
// <Buffer 83 fb 01 ea 02 d9>
console.log(serializer.fromBuffer(Buffer.from('83fb01ea02d9', 'hex')));
// [<BigNumber 123>, <BigNumber 234>, <BigNumber 345>]