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

@raiderb/frac_json

v0.1.5

Published

A binary JSON encoding optimized for small storage size.

Downloads

91

Readme

Fractured Binary JSON

A binary JSON encoding optimized for small storage size.

For more information, see here.

Usage

import { encode, decode, keysTableFromJson } from '@raiderb/frac_json';

// basic usage
const encodedObject = encode({ key1: "value" });
const decodedObject = decode(encodedObject);

// with compression
const largeObject = { /* ... */ };
const encodedObject2 = encode(largeObject, { compressionLevel: 3 });

// with keys table
const keysTable = keysTableFromJson(largeObject); // one time only, save this to a file
// const keysTable = keysTableFromKeys(["key", "key1", "key2", "key3"]); // or generate from keys
const encodedObject3 = encode(largeObject, { globalKeysTableBytes: keysTable });

Functions


// Encode a JSON object (object, array, string, number, boolean, null) to a Buffer.
function encode(
	value: any,
	encodeOptions?: EncodeOptions
): Buffer
interface EncodeOptions {
	// bytes of an external keys table
	// to generate a keys table from keys, use keysTableFromKeys or keysTableFromJson
	globalKeysTableBytes?: Buffer
	// compression level for zstandard. 1-22. Default is 3.
	compressionLevel?: number
	// pre trained zstandard dictionary
	zstdDict?: Buffer
}

// Decode a Buffer to a JSON object (object, array, string, number, boolean, null).
function decode(
	fracJsonBytes: Buffer,
	decodeOptions?: DecodeOptions
): any
interface DecodeOptions {
	// bytes of an external keys table
	globalKeysTableBytes?: Buffer
	// pre trained zstandard dictionary
	zstdDict?: Buffer
}

// Generate a keys table from a list of unique keys.
// To improve performance during encoding, keys should be sorted by frequency of occurrence.
function keysTableFromKeys(
	keys: Array<string>
): Buffer

// Generate a keys table from a JSON object.
function keysTableFromJson(
	// object to recursively extract keys from
	obj: any,
	// maximum number of keys to extract
	maxCount?: number,
	// minimum number of occurrences for a key to be included
	occurrenceCutoff?: number
): Buffer