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

v0.1.2

Published

Composable object modules via createModule, replacing class hierarchies

Readme

@avandar/modules

A small library for building composable object modules in place of class hierarchies. A module is a plain object with auto-generated getters/setters over its state plus whatever members its builder defines, and can be incrementally extended via mixin().

State is immutable: every setter call returns a new module instance, leaving the original untouched.

ESM only. Requires Node 22+.

Install

pnpm add @avandar/modules

No peer dependencies.

Usage

import { createModule, createModuleFactory, withNewMembers } from "@avandar/modules";

const Counter = createModule("Counter", {
  state: { count: 0 },
  builder: (m) => ({
    increment: () => m.setCount((c) => c + 1),
    double:    () => m.setCount((c) => c * 2),
  }),
});

Counter.getCount();        // 0
const next = Counter.increment().double();
next.getCount();           // 2
Counter.getCount();        // still 0 (immutable)

Mixins

mixin() extends a module with extra state and members. Returns a new module with the merged types.

const WithLabel = Counter.mixin((prev) => ({
  state: { label: "count" },
  members: {
    describe: () => `${prev.getLabel()}: ${prev.getCount()}`,
  },
}));

WithLabel.describe(); // "count: 0"

The withNewMembers helper is a convenience shortcut for mixins that only add members (no new state):

const WithReset = Counter.mixin(withNewMembers({
  reset: () => Counter.setCount(0),
}));

Factories

createModuleFactory produces a factory module whose .create(state) call returns a fresh child module each time. Useful when each instance needs its own state but should share members.

type CounterModule = Module<"Counter", { count: number }, { increment: () => CounterModule }>;

const CounterFactory = createModuleFactory<CounterModule>("Counter", {
  childBuilder: (m) => ({
    increment: () => m.setCount((c) => c + 1),
  }),
});

const a = CounterFactory.create({ count: 0 });
const b = CounterFactory.create({ count: 100 });

API

createModule(moduleName, options?)

Creates a module.

| Option | Type | Description | | --------- | ----------------------------------------- | -------------------------------------------------------------------------- | | state | object | Initial state. Auto-generates getX() / setX() accessors for each key. | | builder | (accessors) => members or members obj | Returns the module's members (functions, data) given its base accessors. |

Every module instance has the following base accessors:

| Member | Description | | --------------------------- | --------------------------------------------------------------------------------- | | getModuleName() | Returns the module's name string | | getState() | Returns the full current state object | | setState(partial) | Returns a new module with partial merged into state | | set(keyPath, value) | Returns a new module with value set at a dot-notation keyPath in state | | get<Key>() (per state key)| Returns the value of state[key] | | set<Key>(value) (per key) | Returns a new module with state[key] replaced. Accepts a value or (prev) => v | | mixin(mixinFn) | Returns a new module with extra state/members merged in |

createModuleFactory<ChildModule>(moduleName, options)

Creates a factory module that produces child instances on demand. The factory itself is a module named ${moduleName}Factory with a single create(state) member.

| Option | Type | Description | | -------------- | ----------------------------- | -------------------------------------------------------- | | childBuilder | (accessors) => childMembers | Members each created child should have given its accessors |

withNewMembers(members)

Mixin helper that returns a () => { members } function. Use this when your mixin only adds members and doesn't depend on the previous module's state or accessors.

Types

| Type | Description | | ------------------------ | -------------------------------------------------------------------------------------- | | Module<Name, State, M> | A full module: base accessors + state getters/setters + mixin + your custom members | | BaseModule<...> | Alias for Accessors — the auto-generated accessor surface, without mixin or members | | ModuleFactory<Child> | The factory module type produced by createModuleFactory | | EmptyObject | Re-export from @avandar/utils; the default state/members shape |

License

MIT