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

@abcnews/hash-codec

v2.0.0

Published

A JavaScript library for encoding and decoding values to strings with validation support. This library provides various codecs and utilities for data transformation and serialization.

Readme

Hash Codec

A JavaScript library for encoding and decoding values to strings with validation support. This library provides various codecs and utilities for data transformation and serialization.

Features

  • Multiple encoding/decoding strategies:
    • Gzip compression
    • Run-Length Encoding (RLE)
    • Binary encoding
  • Schema-based validation
  • Svelte store integration

Installation

npm install hash-codec

Usage

This library works well with @abcnews/alternating-case-to-object (ACTO), but isn't prescriptive about it.

For this reason the library takes an object as an input and returns an object as an output. Since libraries like svelte-scrollyteller automatically decode ACTO objects, we don't attempt to handle that in the main schema functionality. So you may sometimes need to use both libraries in conjunction.

Basic Encoding/Decoding

import { encodeSchema, decodeSchema } from 'hash-codec';

// Define a schema with proper type definitions and keys
const schema = {
  version: {
    // Number types are rounded to the nearest whole number.
    type: 'number',
    key: 'ver'
  },
  name: {
    // String types are free text. You must sanitise these yourself,
    // especially if passing them to ACTO encode.
    type: 'string',
    key: 'n'
  },
  name: {
    // String type, encoded as base36. Safe to pass to ACTO without
    // any sanitisation
    type: 'base36string',
    key: 'n'
  },
  isActive: {
    // Boolean type, true or false.
    type: 'boolean',
    key: 'ia',
    defaultValue: false
  },
  status: {
    // Enum values are translated into an integer for the matching array index.
    // Be careful to keep your arrays in a consistent order, or your outputs
    // will change.
    type: 'enum',
    key: 's',
    defaultValue: 'pending',
    values: ['pending', 'active', 'inactive']
  },
  customData: {
    // A custom codec. Specify an encode and decode functino of your own to
    // sanitise/encode data for this field.
    type: 'custom',
    key: 'cd',
    codec: {
      encode: (data) => customEncode(data),
      decode: (encoded) => customDecode(encoded)
    }
  }
};

// Encode data
const encoded = encodeSchema({name: 'grug', age: 99}, schema);

// Decode data
const decoded = decodeSchema(encoded, schema);

Using Codecs

import { getRleCodec, getBinaryCodec } from 'hash-codec';

// Run-Length Encoding
const rleDelineator = 'q';
const rleCodec = getRleCodec({ delineator: rleDelineator });
const encoded = rle.encode('aaaaaaaabaaaxyzaaaaa');
// a8qba3xyza5
const decoded = rle.decode(encoded);
// Binary encoding
const binary = getBinaryCodec();
const binaryData = binary.encode([true,false,false,false,true,true]);
const original = binary.decode(binaryData);

Codecs can be used as-is in the schema:

const schema = {
    myField: {
        key:'x',
        type: 'custom',
        codec: rleCodec,
    }
}

Writing custom codecs

You can write a codec of your own, as long as it has an encode() and decode() function. These may be synchronous or async.

const twoDecimalPointCodec = {
    encode: num => Math.round(num*100),
    decode: string => Number(string)/100
}

Svelte Integration

The svelte store is useful for builders and contexts where you want to sync the data to and from a hash in the URL bar. This is probably not useful as a production-facing utility.

import { makeSvelteStore } from 'hash-codec';

const store = makeSvelteStore(initialData, schema);

Or with Typescript, specify a type for your store:

const store = makeSvelteStore<HashConfigType>(initialData, schema);

Development

# Install dependencies
npm install

# Run tests
npm test