{"id":11396,"library":"ngraph.merge","title":"ngraph.merge","description":"ngraph.merge is a minimalist JavaScript utility designed to extend target objects with properties from source objects without introducing external dependencies. It primarily operates as a shallow merge. Its key differentiator is a specific, somewhat unconventional, conflict resolution strategy: properties from the source will overwrite existing target properties only if their types differ. If the target already contains a property with the same name and type, it is *not* overwritten by the source property. The package is currently at version 1.0.0, with its last commit in 2017, indicating it is no longer actively maintained and has an abandoned release cadence. Its zero-dependency footprint makes it suitable for environments where bundle size and dependency chain control are critical, though its unique merge logic requires careful consideration.","status":"abandoned","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/anvaka/ngraph.merge","tags":["javascript","merge","utility"],"install":[{"cmd":"npm install ngraph.merge","lang":"bash","label":"npm"},{"cmd":"yarn add ngraph.merge","lang":"bash","label":"yarn"},{"cmd":"pnpm add ngraph.merge","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only and does not provide ES module exports. Direct ESM imports will fail.","wrong":"import merge from 'ngraph.merge';","symbol":"merge","correct":"const merge = require('ngraph.merge');"}],"quickstart":{"code":"const merge = require('ngraph.merge');\n\nconst defaults = {\n  name: 'Guest',\n  age: 30,\n  isActive: true,\n  settings: { theme: 'dark' }\n};\n\nconst userOptions = {\n  name: 'Alice',       // Same type as default, will not overwrite\n  age: 'thirty',      // Different type (string vs number), will overwrite\n  isAdmin: false,\n  settings: { debug: true } // New property for settings, will overwrite entire settings object if it's not a deep merge\n};\n\nconst finalOptions = {};\nmerge(finalOptions, defaults);\nconsole.log('1. After merging with defaults:', finalOptions);\n// Expected: { name: 'Guest', age: 30, isActive: true, settings: { theme: 'dark' } }\n\nmerge(finalOptions, userOptions);\nconsole.log('2. After merging with user options:', finalOptions);\n// Expected: { name: 'Guest', age: 'thirty', isActive: true, isAdmin: false, settings: { theme: 'dark' } }\n// Note: `name` remains 'Guest' because types match. `age` becomes 'thirty' due to type mismatch.\n// `settings` in `userOptions` will not overwrite because the `settings` property in `finalOptions` already exists and has the same object type.\n\nconsole.log('Final Name:', finalOptions.name);     // Expected: 'Guest'\nconsole.log('Final Age:', finalOptions.age);       // Expected: 'thirty'\nconsole.log('Final Is Admin:', finalOptions.isAdmin); // Expected: false\nconsole.log('Final Settings:', finalOptions.settings); // Expected: { theme: 'dark' } - not affected by userOptions.settings because it's a shallow merge and type match.","lang":"javascript","description":"This quickstart demonstrates basic usage and highlights the specific shallow merge logic and overwrite behavior based on type matching."},"warnings":[{"fix":"Be aware of this specific merge logic. If you need a standard deep merge or consistent overwrite behavior, consider an alternative utility like `lodash.merge` or `deepmerge`.","message":"Properties are only overwritten if the target object's existing property has a *different* type than the source property. If the types are the same, the existing property in the target object is preserved.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For deep merging of nested objects, you will need to use a different utility specifically designed for deep merges.","message":"This utility performs a shallow merge. Nested objects within the source will not be deeply merged into nested objects in the target; instead, they will be assigned by reference or entirely replaced if types differ.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For new projects or if active maintenance is required, consider modern, actively maintained alternatives that support ES Modules and have more conventional merge behaviors.","message":"The package has not been updated since 2017 and is considered abandoned. It uses older CommonJS modules and Travis CI for builds, which are indicators of inactivity. There will likely be no further updates or security patches.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"This package is CommonJS-only. If you are in an ES module environment (e.g., `\"type\": \"module\"` in package.json), you may need to use `import merge from 'ngraph.merge';` (which will likely fail if a CJS wrapper is not provided) or revert to a CJS environment. Alternatively, use a bundler that handles CJS modules in an ESM project.","cause":"Attempting to use `require` in an ES module context or a browser environment without a CommonJS bundler.","error":"TypeError: require is not a function"},{"fix":"This package is CommonJS-only. Use `const merge = require('ngraph.merge');` instead of `import` statements.","cause":"Attempting to use `import merge from 'ngraph.merge';` in a CommonJS context.","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"Review the documentation and examples. If this behavior is not desired, consider using a different merge utility with standard overwrite behavior.","cause":"Misunderstanding of `ngraph.merge`'s specific overwrite logic: it only overwrites if the types of the source and target properties differ. If types are the same, the target property is retained.","error":"Property value not updated as expected during merge."}],"ecosystem":"npm"}