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

@untheme/utils

v0.2.1

Published

Common structural helpers for untheme's theme shape. Types come from [`@untheme/schema`](../schema); guards and generic helpers come from [`objectively`](https://www.npmjs.com/package/objectively).

Downloads

766

Readme

@untheme/utils

Common structural helpers for untheme's theme shape. Types come from @untheme/schema; guards and generic helpers come from objectively.

Exports

merge(theme, ...overlays)

Merges overlays over a complete theme into a fresh theme, left to right: later overlays win where they bind the same token, token by token and context by context. Identity and order transfer from the last overlay that carries them. No input is mutated; with no overlays the result is a plain copy.

import { merge } from "@untheme/utils";

merge(theme, patch); // patch has no identity → identity preserved (update)
merge(theme, layer); // layer carries id/name → identity adopted (apply)
merge(theme, layer, patch); // layer applied, then patched — last binding wins

extend(base, extension)

Widens a base contract with an extension into a fresh contract over the union token and modifier sets. New tokens and new modifiers join; existing tokens are overridden; existing modifier contexts are deep-merged leaf by leaf, so the base's other tokens in that context are kept. The order the extension lists wins — any modifier it names is dropped from the base order, then the extension's order is appended. Neither input is mutated.

import { extend } from "@untheme/utils";

const wide = extend(base, {
  id: "wide",
  name: "Wide",
  tokens: { accent: "#0090ff", bg: "{accent}" }, // new token + override existing
  modifiers: {
    color: { dark: { fg: "{accent}" } }, // override an existing context (leaf)
    density: { compact: {}, cozy: {} }, // a new modifier
  },
  order: ["density", "color"],
});

Unlike merge, which stays within one contract, extend is the widening primitive: the result's token and modifier sets grow to include the extension's.

diff(from, to)

Computes the patch that turns from into to: every binding to holds that deviates from from, token by token and context by context. At the token level only the bound $value is compared and emitted — a token's metadata cannot drift through the patch pipeline. Identity and order are not compared. Empty maps mean the themes bind identically; applying the result to from via merge restores every binding to carries. A patch can add and override, never remove — a context override from holds that to dropped survives the restoration, and identity, order, and slot metadata are not part of it.

import { diff, merge } from "@untheme/utils";

const deviation = diff(pristine, edited);
merge(pristine, deviation); // ≅ edited

Primitives

Supporting helpers that merge, extend, and diff are built on.

clone(theme)

Deep copy of a theme, facet by facet: identity, tokens, modifiers, and order are each rebuilt through copy, so no definition object, nested $value structure, or override map is shared with the source. Because copy reaches every value through plain property access, cloning a reactive proxy yields an inert, plain snapshot. clone throws a TypeError if the rebuilt theme isn't structurally equal to the source.

import { clone } from "@untheme/utils";

const snapshot = clone(theme); // detached from any reactive proxy

copy(value)

Deep copy of plain data: records and arrays are rebuilt from fresh containers, so mutating the copy never reaches the source. Non-plain values — functions and class instances, such as those a token's $extensions may carry — pass through by reference rather than being duplicated. structuredClone is never used: it throws on functions and detaches proxies through a mechanism copy deliberately avoids.

delta(from, to)

The entries of to that deviate from from: every key to holds whose value is not structurally equal to the one from holds. Emitted values are copies, so the result shares no structure with to. Keys with structurally equal values drop out; two objects that bind identically yield an empty result.

traverse(modifiers, fn)

Rebuilds a modifiers structure leaf by leaf: every context of every modifier is mapped through the callback, each modifier keeping its own context keys. The callback's at accessor indexes another (possibly sparse) modifiers structure at the same modifier/context coordinates, so a leaf can be combined with its counterpart elsewhere. This is the primitive diff, merge, and extend are all built on.

Types

  • Overlay<T> — the shape merge accepts: any subset of identity, tokens, modifiers, and order. Both a Layer and a Patch from @untheme/schema fit it.
  • Extension<Tok, Mod, XTok, XMod> — the shape extend accepts: new tokens (XTok) and new modifiers (XMod) over a base contract's tokens (Tok) and modifiers (Mod). An existing base token accepts an optional bare binding that rebinds its $value only; a new token requires a full slot definition. New modifier axes carry their complete context maps; existing axes take optional overrides.
  • Diff<T> — the shape diff returns: token and per-context override maps, always present (empty when nothing deviates).

Related