{"id":16125,"library":"mixme","title":"Mixme Object Merger","description":"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.","status":"active","version":"2.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/adaltas/node-mixme","tags":["javascript","clone","copy","deep","extend","merge","objects","recursive","typescript"],"install":[{"cmd":"npm install mixme","lang":"bash","label":"npm"},{"cmd":"yarn add mixme","lang":"bash","label":"yarn"},{"cmd":"pnpm add mixme","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Mixme v2 supports both ESM and CommonJS. For CommonJS, named exports like `merge` must be accessed as properties of the `require` result.","wrong":"const merge = require('mixme').merge;","symbol":"merge","correct":"import { merge } from 'mixme';"},{"note":"All primary functions (`merge`, `mutate`, `clone`, etc.) are named exports, not default exports. Attempting a default import will result in `undefined`.","wrong":"import mutate from 'mixme';","symbol":"mutate","correct":"import { mutate } from 'mixme';"},{"note":"While `const { clone } = require('mixme');` works in CommonJS, `const clone = require('mixme').clone;` is also common but slightly less idiomatic for multiple exports.","wrong":"const { clone } = require('mixme');","symbol":"clone","correct":"import { clone } from 'mixme';"}],"quickstart":{"code":"import { merge, mutate, clone, snake_case } from 'mixme';\n\ninterface Config {\n  appName: string;\n  version: string;\n  settings: {\n    theme: string;\n    notifications: boolean;\n  };\n  features: string[];\n}\n\nconst defaultAppConfig: Config = {\n  appName: 'My App',\n  version: '1.0.0',\n  settings: {\n    theme: 'dark',\n    notifications: true,\n  },\n  features: ['dashboard', 'reports'],\n};\n\nconst userConfig: Partial<Config> = {\n  appName: 'My Custom App',\n  settings: {\n    theme: 'light',\n  },\n  features: ['dashboard', 'analytics'],\n};\n\n// Immutable merge: creates a new object\nconst finalConfig = merge(defaultAppConfig, userConfig);\nconsole.log('Final Config (merged):', finalConfig);\n// Expected: { appName: 'My Custom App', version: '1.0.0', settings: { theme: 'light', notifications: true }, features: ['dashboard', 'analytics'] }\n\n// Mutable merge: modifies the first object\nconst baseConfigCopy = clone(defaultAppConfig); // Clone to avoid modifying original defaultAppConfig\nmutate(baseConfigCopy, userConfig);\nconsole.log('Mutated Config:', baseConfigCopy);\n// Expected: { appName: 'My Custom App', version: '1.0.0', settings: { theme: 'light', notifications: true }, features: ['dashboard', 'analytics'] }\n\n// Example of snake_case utility\nconst camelCaseObject = { userFirstName: 'John', userLastName: 'Doe' };\nconst snakeCaseObject = snake_case(camelCaseObject);\nconsole.log('Snake Case Object:', snakeCaseObject);\n// Expected: { user_first_name: 'John', user_last_name: 'Doe' }","lang":"typescript","description":"Demonstrates `merge` for immutable object combination, `mutate` for in-place modification, and `snake_case` utility, highlighting how arrays are overwritten."},"warnings":[{"fix":"If deep array merging is required, you must preprocess arrays manually before passing them to `mixme` or use a different library designed for deep array merging.","message":"When merging objects with `merge` or `mutate`, arrays are always overwritten by the subsequent object's array value, not recursively merged. This differs from some other deep merge utilities.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use `const myObjectCopy = clone(myObject); mutate(myObjectCopy, changes);` if you intend to keep the original object intact. Use `merge` for an immutable approach that always returns a new object.","message":"The `mutate` function directly modifies its first argument. If you need to preserve the original object, always pass a `clone()` of the original object as the first argument to `mutate`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure your project's module system is correctly configured. For ESM, use `import { func } from 'mixme';`. For CJS, use `const { func } = require('mixme');`. Refer to Node.js documentation on ESM/CJS interoperability.","message":"While `mixme` v2 supports both ESM and CommonJS, migrating older CommonJS-only projects to `import` statements may require configuring 'type': 'module' in `package.json` or changing file extensions to `.mjs` for Node.js environments.","severity":"breaking","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure your `package.json` contains `\"type\": \"module\"` for ESM, or rename `.js` files using `import` to `.mjs`. Alternatively, if staying with CommonJS, use `const { merge } = require('mixme');`.","cause":"Attempting to use `import` syntax in a CommonJS file or a Node.js project not configured for ES Modules.","error":"Cannot use import statement outside a module"},{"fix":"In CommonJS, you must destructure the named export: `const { merge } = require('mixme');` or access it as a property: `const mixme = require('mixme'); const result = mixme.merge(...);`.","cause":"This typically happens when trying to `require('mixme')` and then calling `mixme.merge()` without destructuring or accessing the named export properly in a CommonJS environment.","error":"TypeError: mixme.merge is not a function"},{"fix":"Switch to `import` syntax: `import { merge } from 'mixme';` instead of `const { merge } = require('mixme');`. If legacy CommonJS modules are needed in an ESM project, consider dynamic `import()` or specific tools like `createRequire`.","cause":"This occurs when trying to use `require()` in an ES Module context (e.g., a file with `\"type\": \"module\"` or `.mjs` extension).","error":"ReferenceError: require is not defined"}],"ecosystem":"npm"}