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

obj-compose

v0.0.2

Published

obj-compose: A utility to compose, merge, and reuse JSON-like objects with fragments and overrides

Readme

obj-compose

“Merge your logic. Trust your types.”

obj-compose is a type-safe, override-friendly object composer for structured configuration and localization systems. Define a base, plug in reusable fragments, and override anything—statically or dynamically—with full TypeScript inference. You can also selectively pick or omit deep pieces from composed results.

Features

  • 🧠 Full type inference for deeply nested objects
  • 🔁 Composable via base + fragments + overrides
  • ⚙️ Dynamic overrides with access to the merged source
  • ✂️ Pick specific deep values by path
  • Omit deep paths from objects safely
  • 🔒 Ideal for localization, form structures, config merging, and more

Installation

npm install obj-compose
# or
yarn add obj-compose
# or
pnpm add obj-compose

Basic Usage

import { compose, pick, omit } from 'obj-compose';

const result = compose({
  base: {
    signup: {
      form: {
        fields: {
          username: 'Choose a username',
        },
        validation: {
          username: 'Must be unique',
        },
      },
    },
  },
  fragments: {
    contact: {
      form: {
        fields: {
          email: 'Email address',
          'first-name': 'First name',
          'last-name': 'Last name',
        },
        validation: {
          email: 'Invalid email',
          'first-name': 'Required',
          'last-name': 'Required',
        },
      },
    },
  },
  overrides: {
    signup: {
      form: {
        fields: (merged) =>
          pick(merged, [
            'signup.form.fields.username',
            'contact.form.fields.email',
            'contact.form.fields.first-name',
            'contact.form.fields.last-name',
          ]),
      },
    },
  },
});

console.log(result.signup.form.fields);
/*
{
  username: 'Choose a username',
  email: 'Email address',
  'first-name': 'First name',
  'last-name': 'Last name'
}
*/

// Example of omitting a deep path from the composed result
const cleaned = omit(result, ['signup.form.validation.username']);
// `cleaned.signup.form.validation` no longer has `username`

When to Use

  • 🗂️ Merge translation keys from multiple modules
  • 🧱 Compose form field definitions from base + shared parts
  • ⚙️ Create overrideable app config with dynamic fallback
  • 🔀 Build highly reusable design token objects

API

compose({ base, fragments?, overrides? })

Composes a new object by merging:

  • base: main object
  • fragments: optional reusable pieces (each must be a JsonObject)
  • overrides: optional static or dynamic overrides (can be objects or functions that receive the merged source)

Everything is type-inferred automatically, including nested structures and dynamic values.

Types

type ComposeOptions<TBase, TFragments> = {
  base: TBase;
  fragments?: TFragments; // record of JsonObject fragments
  overrides?: Overrides<TBase, TFragments>;
};

pick(source, paths)

Picks values from a source object (typically the merged result of base + fragments) by dot-notation paths.

Returns a flat object whose keys are the last segment of each path.

const picked = pick(result, [
  'signup.form.fields.username',
  'contact.form.fields.email',
]);
/*
{
  username: 'Choose a username',
  email: 'Email address'
}
*/

omit(source, paths)

Returns a deep-cloned version of source with the specified dot-notation paths removed.

const withoutValidation = omit(result, ['signup.form.validation.username']);
/*
{
  signup: {
    form: {
      fields: { username: 'Choose a username', ... },
      validation: {
        // username is omitted here
        // other validation entries remain
      }
    }
  },
  contact: { ... }
}
*/

Type Inference

All types flow automatically. If you need explicitness:

import type { ComposeOptions } from 'obj-compose';

const options: ComposeOptions<typeof base, typeof fragments> = {
  base,
  fragments,
  overrides,
};

📝 License

This project is licensed under the MIT License – see the LICENSE file for details.

Author: Estarlin R. · estarlincito.com