Mixme Object Merger

2.0.2 · active · verified Tue Apr 21

Mixme is a JavaScript/TypeScript library (currently at v2.0.2) designed for recursively merging and manipulating JavaScript objects. It provides immutable merging via `merge` and mutable in-place modification via `mutate`. Key differentiators include its zero-dependency footprint, minimal size, and pure function approach for `merge`. It offers comprehensive TypeScript type definitions and supports both ES Modules (ESM) and CommonJS environments. While a specific release cadence isn't explicitly published, the project appears actively maintained with a streamlined release process via GitHub Actions. A notable behavior is that arrays are always overwritten during merges, not recursively combined, which is a common point of confusion for users expecting deep array merging.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates `merge` for immutable object combination, `mutate` for in-place modification, and `snake_case` utility, highlighting how arrays are overwritten.

import { merge, mutate, clone, snake_case } from 'mixme';

interface Config {
  appName: string;
  version: string;
  settings: {
    theme: string;
    notifications: boolean;
  };
  features: string[];
}

const defaultAppConfig: Config = {
  appName: 'My App',
  version: '1.0.0',
  settings: {
    theme: 'dark',
    notifications: true,
  },
  features: ['dashboard', 'reports'],
};

const userConfig: Partial<Config> = {
  appName: 'My Custom App',
  settings: {
    theme: 'light',
  },
  features: ['dashboard', 'analytics'],
};

// Immutable merge: creates a new object
const finalConfig = merge(defaultAppConfig, userConfig);
console.log('Final Config (merged):', finalConfig);
// Expected: { appName: 'My Custom App', version: '1.0.0', settings: { theme: 'light', notifications: true }, features: ['dashboard', 'analytics'] }

// Mutable merge: modifies the first object
const baseConfigCopy = clone(defaultAppConfig); // Clone to avoid modifying original defaultAppConfig
mutate(baseConfigCopy, userConfig);
console.log('Mutated Config:', baseConfigCopy);
// Expected: { appName: 'My Custom App', version: '1.0.0', settings: { theme: 'light', notifications: true }, features: ['dashboard', 'analytics'] }

// Example of snake_case utility
const camelCaseObject = { userFirstName: 'John', userLastName: 'Doe' };
const snakeCaseObject = snake_case(camelCaseObject);
console.log('Snake Case Object:', snakeCaseObject);
// Expected: { user_first_name: 'John', user_last_name: 'Doe' }

view raw JSON →