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

@avandar/models

v0.1.2

Published

Core model primitives for typed, discriminated data objects

Readme

@avandar/models

A lightweight library for representing typed, discriminated data models. The only export is Model, a small bundle of helpers built around the __type discriminator convention.

A model is just an object with a __type string and arbitrary additional properties. The value of this library isn't in enforcing any clever representation — it's the shared convention that lets the rest of the Avandar packages (@avandar/clients, @avandar/query-hooks) auto-generate parsers, CRUD clients, and React Query hooks against any model.

ESM only. Requires Node 22+.

Install

pnpm add @avandar/models

zod is an optional peer dependency, needed only if you import @avandar/models/zod.

Entry points

| Entry | Contents | | --------------------- | -------------------------------------------------- | | @avandar/models | Model — the value helpers and the type namespace | | @avandar/models/zod | Zod schema builders for models |

Usage

import { Model } from "@avandar/models";

// Create a model instance
const user = Model.make("User", { id: "u1", name: "Alice" });

// Pattern-match on a discriminated union of models
const label = Model.match(model, {
  User: (m) => m.name,
  Admin: (m) => `admin:${m.level}`,
});

// Extract the id coupled with the model type
const typedId = Model.getTypedId(user); // { id: 'u1', __type: 'User' }

// Runtime type guards
Model.isModel(value);                 // true if value has a `__type` string
Model.isOfModelType(value, "User");   // true if `__type === "User"`

// Higher-order guard for use with `.filter`, `.find`, etc.
users.filter(Model.valIsOfModelType("Admin"));

API

Constructors

Model.make(modelType, modelProps)

Returns { __type: modelType, ...modelProps }. The return type carries the literal __type so unions of models remain discriminated.

Pattern matching

Model.match(model, fns)

Pattern-matches a model union by its __type, calling the corresponding function. Throws if no branch matches.

type Shape = Model.Base<"Circle", { r: number }> | Model.Base<"Square", { s: number }>;
const area = Model.match(shape, {
  Circle: ({ r }) => Math.PI * r * r,
  Square: ({ s }) => s * s,
});

Identity helpers

Model.getTypedId(model)

Returns { __type, id } from a model with an id property, discarding every other property. Useful for keying lookups or passing references.

Type guards

| Function | Returns | | ------------------------------------- | ------------------------------------------- | | Model.isModel(val) | val is Model.Base | | Model.isOfModelType(val, modelType) | val is Model.Base<modelType> | | Model.valIsOfModelType(modelType) | Curried guard for .filter / .find calls |

Types

| Type | Description | | ----------------- | ---------------------------------------------------------------------------- | | Model.Base<T,P> | Base model shape: { __type: T } & P (defaults: string, EmptyObject) | | Model.Versioned | Base model extended with a numeric version field | | Model.Type<M> | Utility type: extracts the __type string literal from a model | | Model.TypedId<M>| Utility type: { __type, id } picked from a model with an id property |

Dependencies

Runtime

  • type-fest — utility types (types only, zero runtime cost)

Development

  • vitest — test runner
  • typescript — type checking

License

MIT