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/common

v5.1.0

Published

[![npm version](https://img.shields.io/npm/v/@xlabs-xyz/common.svg)](https://www.npmjs.com/package/@xlabs-xyz/common)

Downloads

37

Readme

@xlabs-xyz/common

npm version

Glue layer that ties together the lower-level packages (const-utils, utils, binary-layout, amount) into practical building blocks.

  • Layout Items – binary-layout items that serialize/deserialize to Amount types
  • Units – predefined Amount kinds for common units (currencies, duration, bytes, etc.)
  • Utilities

Layout Items

Binary-layout items that serialize to/from Amount and related types.

amountItem

Deserialize numeric bytes directly to an Amount:

const layout = [
  { name: "balance", ...amountItem(8, Sol) },  // uses atomic (lamports) by default
  { name: "timeout", ...amountItem(4, Duration, "second") },  // explicit unit
] as const;

With a transform for scaled and/or shifted values:

import { linearTransform } from "@xlabs-xyz/common";

//Sol amount squeezed into 4 bytes with kLamport precision (0 to ~4k SOL range)
amountItem(4, Sol, linearTransform("stored", 1_000));

conversionItem

For exchange rates / conversion factors. Has many overloads – can wrap an existing amountItem or be built from scratch:

// Wrap an existing amountItem
const priceItem = amountItem(8, Sol, "lamport");
conversionItem(priceItem, Usd);          // => Conversion<Sol, Usd>

// Or build from scratch: size, numKind, numUnit, denKind, [denUnit], [transform]
conversionItem(8, Sol, "lamport", Usd);  // => Conversion<Sol, Usd>

Other Items

timestampItem("uint", 4);  // unix timestamp → Date (use "int" for signed, e.g. Solana)
hashItem;                  // 32-byte hash field
paddingItem(4);            // 4 bytes of padding (omitted in output)

byteSwitchItem / enumSwitchVariants – helpers for byte-discriminated tagged unions; see source for details.

Units

Predefined Amount kinds for common use cases. These are sensible defaults – not authoritative definitions. Feel free to roll your own if they don't fit your needs.

  • Currencies: Usd, Usdt, Usdc, Btc, Eth, Sol – each with a CurrencyKind type and three formatting systems:
    • default – native symbols where available ($, ₿, Ξ)
    • uniform – ticker-style (USD, BTC, ETH)
    • fancy – unicode symbols (₿, Ξ, USD₮)
  • Percentage – supports %, bp (basis points), and x (scalar)
  • Duration – seconds through years, with long and short formatting systems
  • Byte – SI (kB, MB, GB) and binary (KiB, MiB, GiB) systems

Unit Definition Helpers

For defining your own kinds:

toDecimalUnits([
  [0,  [{ symbol: "FOO" }]],        // oom: 0 (base unit)
  [-6, [{ symbol: "µFOO" }]],       // oom: -6 (micro)
]);

toCompoundUnits([
  [1,    [withPluralS("second")]],  // scale: 1
  [60,   [withPluralS("minute")]],  // scale: 60
]);

withPluralS("hour");                // => { symbol: "hour", plural: "hours" }
allowPluralS("hour");               // => [{ symbol: "hour" }, { symbol: "hours" }]
allowOtherCap("Gwei");              // => [{ symbol: "Gwei" }, { symbol: "gwei" }]

Utilities

fromAtomicIfKind(1_000_000n);       // => 1_000_000n (no kind, returns bigint)
fromAtomicIfKind(1_000_000n, Sol);  // => Amount<Sol> (=0.001 SOL)