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

@xlabs-xyz/utils

v5.1.0

Published

misc utils

Readme

@xlabs-xyz/utils

npm version

Common runtime utilities: encoding, hashing, JSON with bigint support, and simple assertions.

Encoding

hex

hex.decode("deadbeef");             // => Uint8Array
hex.decode("0xdeadbeef");           // => Uint8Array (0x prefix stripped)
hex.encode(bytes);                  // => "deadbeef"
hex.encode(bytes, true);            // => "0xdeadbeef"
hex.isValid("0xdeadbeef");          // => true

base58 / base64

base58.decode("3yZe7d");            // => Uint8Array
base58.encode(bytes);               // => "3yZe7d"

base64.decode("SGVsbG8=");          // => Uint8Array
base64.encode(bytes);               // => "SGVsbG8="
base64.isValid("SGVsbG8=");         // => true

bech32

bech32.decode("cosmos1...");        // => Uint8Array (bytes only, no prefix)

bignum

Conversions between bigint, hex strings, and bytes.

bignum.decode("0xff");              // => 255n
bignum.decode(bytes);               // => bigint from bytes
bignum.encode(255n);                // => "ff"
bignum.encode(255n, true);          // => "0xff"
bignum.toBytes(255n);               // => Uint8Array([0xff])
bignum.toBytes(255n, 4);            // => Uint8Array([0, 0, 0, 0xff]) (zero-padded)
bignum.toNumber(255n);              // => 255 (throws if out of safe integer range)
bignum.toBigInt(255);               // => 255n (throws if not safe integer)

bytes

UTF-8 and byte array utilities.

bytes.encode("hello");              // => Uint8Array (UTF-8)
bytes.decode(arr);                  // => "hello"
bytes.equals(a, b);                 // => true/false
bytes.zpad(arr, 32);                // => zero-padded to 32 bytes (left)
bytes.zpad(arr, 32, false);         // => zero-padded to 32 bytes (right)
bytes.concat(a, b, c);              // => concatenated Uint8Array

BigInt JSON

JSON doesn't support bigint natively. This module provides serialization that wraps bigints as { $type: "bigint", value: "123" }.

const obj = { amount: 123456789012345678901234567890n };

stringifyWithBigints(obj);
// => '{"amount":{"$type":"bigint","value":"123456789012345678901234567890"}}'

parseWithBigints<typeof obj>(jsonString);
// => { amount: 123456789012345678901234567890n }

For use with JSON.stringify/JSON.parse directly:

JSON.stringify(obj, bigintReplacer);
JSON.parse(str, bigintReviver);

For transforming objects in-place:

serializeBigints(obj);    // bigints → { $type, value }
deserializeBigints(obj);  // { $type, value } → bigints

Hashing & Curves

Re-exports from @noble/hashes and @noble/curves:

import { sha256, sha512_256, keccak256, sha3_256 } from "@xlabs-xyz/utils";
import { secp256k1, ed25519 } from "@xlabs-xyz/utils";

Assertions

Simple runtime checks that throw on failure.

assertEqual(a, b);                  // throws if a !== b
assertEqual(a, b, "custom message");

assertDistinct(1, 2, 3);            // ok
assertDistinct(1, 2, 2);            // throws "Values are not distinct: 1, 2, 2"

Misc

definedOrThrow(value);              // returns value, throws if undefined
definedOrThrow(value, "not found"); // custom error message

throws(() => someFn());             // => true if someFn throws, false otherwise

definedOrThrow is a checked ! assertion – useful in chains where breaking into an if block would be awkward:

// instead of:
const result = await fetchMaybe();
if (result === undefined)
  throw new Error("not found");
await process(result);

// you can write:
await fetchMaybe().then(r => process(definedOrThrow(r, "not found")));