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

mini-object-diff

v0.0.4

Published

Lightweight configurable object diff utility (wildcards, path-based, value tracking) - vanilla JS

Downloads

12

Readme

mini-obj-diff

npm version License: MIT Node.js Version

Lightweight, configurable object diffing utility for TypeScript/JavaScript. Analyze changes between objects using configurable path rules with wildcard support, nested ID tracking, and optional value change tracking.

Features

  • 🎯 Configurable Path Rules: Define exactly which paths to track
  • 🌟 Wildcard Support: Use [*] to match arrays and objects
  • 🔍 ID-Based Array Tracking: Track array changes using nested ID fields
  • 📊 Value Change Tracking: Optional tracking of old/new values
  • 🚀 Zero Dependencies: Lightweight and fast
  • 📝 Full TypeScript Support: Complete type definitions included
  • Type-Safe: Built with strict TypeScript

Installation

npm install mini-obj-diff

Quick Start

import { analyzeChanges } from 'mini-obj-diff';

const oldObj = {
  status: 'active',
  users: [{ id: 1, name: 'Alice' }],
};

const newObj = {
  status: 'inactive',
  users: [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }],
};

const result = analyzeChanges(oldObj, newObj, {
  pathConfigs: [
    { path: 'status', name: 'status', trackValues: true },
    { path: 'users.[*]', name: 'user', idField: 'id' },
  ],
});

console.log(result.updatedItems); // ['status']
console.log(result.addedItems);   // ['user']
console.log(result.valueChanges.status); // [{ oldValue: 'active', newValue: 'inactive', ... }]

Usage

Basic Example

import { analyzeChanges, type PathConfig } from 'mini-obj-diff';

const config: PathConfig[] = [
  { path: 'status', name: 'status', trackValues: true },
  { path: 'count', name: 'count' },
];

const oldState = { status: 'active', count: 5 };
const newState = { status: 'inactive', count: 10 };

const result = analyzeChanges(oldState, newState, { pathConfigs: config });

// result.addedItems = []
// result.updatedItems = ['status', 'count']
// result.removedItems = []
// result.valueChanges.status = [{ oldValue: 'active', newValue: 'inactive', ... }]

Wildcard Paths

Use [*] to match arrays and objects:

const config: PathConfig[] = [
  { path: 'users.[*].name', name: 'userName' },
  { path: 'users.[*].email', name: 'userEmail', trackValues: true },
];

const oldObj = {
  users: [
    { name: 'Alice', email: '[email protected]' },
    { name: 'Bob', email: '[email protected]' },
  ],
};

const newObj = {
  users: [
    { name: 'Alice', email: '[email protected]' },
    { name: 'Bob', email: '[email protected]' },
    { name: 'Charlie', email: '[email protected]' },
  ],
};

const result = analyzeChanges(oldObj, newObj, { pathConfigs: config });
// Detects changes in user names and emails across all users

Array Tracking with ID Fields

Track array changes using ID fields:

const config: PathConfig[] = [
  {
    path: 'products.[*]',
    name: 'product',
    idField: 'id', // Track by product.id
    trackValues: true,
  },
];

const oldProducts = [
  { id: 1, name: 'Widget', price: 10 },
  { id: 2, name: 'Gadget', price: 20 },
];

const newProducts = [
  { id: 1, name: 'Widget', price: 15 }, // price updated
  { id: 3, name: 'Tool', price: 30 },   // new product
  // id: 2 removed
];

const result = analyzeChanges(
  { products: oldProducts },
  { products: newProducts },
  { pathConfigs: config },
);

// result.updatedItems = ['product'] (price changed for id: 1)
// result.addedItems = ['product'] (id: 3 added)
// result.removedItems = ['product'] (id: 2 removed)

API Reference

analyzeChanges(oldObject, newObject, options)

Analyzes changes between two objects according to provided path configurations.

Parameters

  • oldObject (unknown): The previous state of the object
  • newObject (unknown): The new state of the object
  • options (AnalyzeChangesOptions): Configuration options
    • pathConfigs (PathConfig[]): Array of path configurations to track
    • optimizeCache (boolean, optional): Cache resolved wildcard paths (default: true)

Returns

AnalyzeChangesResult:

  • addedItems: Array of logical names that were added
  • updatedItems: Array of logical names that were updated
  • removedItems: Array of logical names that were removed
  • valueChanges: Map of property names to their value change entries (if trackValues: true)

PathConfig

interface PathConfig {
  path: string;           // Dot-separated path (supports `[*]` wildcards)
  name: string;          // Logical name for this path (used in results)
  idField?: string;       // Optional nested path to ID field (for array tracking)
  trackValues?: boolean;  // Whether to track old/new values
}

TypeScript Support

Full TypeScript support with comprehensive type definitions:

import {
  analyzeChanges,
  type PathConfig,
  type AnalyzeChangesResult,
  type ValueChangeEntry,
} from 'mini-obj-diff';

// All types are fully typed and exported

Requirements

  • Node.js >= 18.0.0
  • TypeScript >= 5.0 (if using TypeScript)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development

# Install dependencies
npm install

# Run tests
npm test

# Build
npm run build

# Lint
npm run lint

# Format code
npm run format

License

MIT © Akarshit Batra

Changelog

See CHANGELOG.md for details.