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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@atlaschain/nominal-types

v3.0.1

Published

Type utilties for creating nominal/branded types in TypeScript

Readme

npm npm-downloads code-style-prettier

@atlas/nominal-types

This package contains type utilities for creating nominal types in TypeScript.

Brands make otherwise equal values distinct at the type level

Use the Brand utility to produce a new type that satisfies the original type, but not the other way around. That is to say, the branded type is acceptable wherever the original type is specified, but wherever the branded type is specified, the original type will be insufficient.

You can use this to create specialized instances of strings, numbers, objects, and more which you would like to assert are special in some way (eg. numbers that are non-negative, strings which represent the names of foods, objects that have passed validation).

const unverifiedName = 'Alice';
const verifiedName = unverifiedName as Brand<'Alice', 'VerifiedName'>;

'Alice' satisfies Brand<string, 'VerifiedName'>; // ERROR
'Alice' satisfies Brand<'Alice', 'VerifiedName'>; // ERROR
unverifiedName satisfies Brand<string, 'VerifiedName'>; // ERROR
verifiedName satisfies Brand<'Bob', 'VerifiedName'>; // ERROR
verifiedName satisfies Brand<'Alice', 'VerifiedName'>; // OK
verifiedName satisfies Brand<string, 'VerifiedName'>; // OK

Values can be tagged as compressed data

Use the CompressedData utility to produce a new type that satisfies the original type, but adds extra type information that marks the type as containing compressed data.

const untaggedData = new Uint8Array([/ ... *\/]);
const compressedData = untaggedData as CompressedData<typeof untaggedData, 'zstd'>;

compressedData satisfies CompressedData<Uint8Array, 'zstd'>; // OK
untaggedData satisfies CompressedData<Uint8Array, 'zstd'>; // ERROR

Strings can be tagged as being encoded using a particular scheme

const untaggedString = 'dv1ZAGvdsz5hHLwWXsVnM94hWf1pjbKVau1QVkaMJ92';
const encodedString = untaggedString as EncodedString<typeof untaggedString, 'base58'>;

encodedString satisfies EncodedString<'dv1ZAGvdsz5hHLwWXsVnM94hWf1pjbKVau1QVkaMJ92', 'base58'>; // OK
encodedString satisfies EncodedString<string, 'base58'>; // OK
encodedString satisfies EncodedString<string, 'base64'>; // ERROR
untaggedString satisfies EncodedString<string, 'base58'>; // ERROR

Brands, compression, and encodings can be combined

const encodedCompressedString = 'abc' as Brand<
    EncodedString<CompressedData<'abc', 'zstd'>, 'base64'>,
    'Base64ZstdCompressedData'
>;

encodedCompressedString satisfies Brand<'abc', 'Base64ZstdCompressedData'>; // OK
encodedCompressedString satisfies Brand<string, 'Base64ZstdCompressedData'>; // OK
encodedCompressedString satisfies CompressedData<'abc', 'zstd'>; // OK
encodedCompressedString satisfies CompressedData<string, 'zstd'>; // OK
encodedCompressedString satisfies EncodedString<'abc', 'base64'>; // OK
encodedCompressedString satisfies EncodedString<string, 'base64'>; // OK
encodedCompressedString satisfies EncodedString<string, 'base58'>; // ERROR

Custom nominal types

type SweeteningSubstance = 'aspartame' | 'cane-sugar' | 'stevia';
type Sweetener<T extends SweeteningSubstance> = NominalType<'sweetener', T>;

// This function accepts sweetened foods, except those with aspartame.
declare function eat(food: string & Sweetener<Exclude<SweeteningSubstance, 'aspartame'>>): void;

const artificiallySweetenedDessert = 'ice-cream' as string & Sweetener<'aspartame'>;
eat(artificiallySweetenedDessert); // ERROR