Registry / serialization / js-utils-deep

js-utils-deep

JSON →
library1.1.4jsnpmunverified

js-utils-deep is a lightweight JavaScript utility package providing a focused set of functions for deep, recursive manipulation of objects. It includes `recursiveOmit`, which removes null, empty string, and undefined values from all nested levels of an object; `deepExtend`, designed for deeply merging properties from a source object into a target object; and `diffObject`, which identifies key-value differences between two objects, including nested structures. Currently at version 1.1.4, the library appears to be in a maintenance phase, offering stable and tested functionalities without frequent updates. Its primary differentiator is its straightforward API for common deep object tasks, providing essential recursive utilities without the added complexity of larger, more generalized utility libraries.

npm install js-utils-deep
INSTALL
IMPORT
SIG · JS-UTILS-DEEP
J
js-utils-deep
serializationjavascriptv1.1.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

recursiveOmit
import { recursiveOmit } from 'js-utils-deep';
const { recursiveOmit } = require('js-utils-deep');
Use named import for ESM environments. CommonJS users should use `require` with destructuring.
deepExtend
import { deepExtend } from 'js-utils-deep';
import * as deepUtils from 'js-utils-deep'; deepUtils.deepExtend(...);
Functions are exported as named exports. Avoid importing the entire module as a namespace unless specifically needed for multiple calls.
All functions (CommonJS)
const { recursiveOmit, deepExtend, diffObject } = require('js-utils-deep');
const deepExtend = require('js-utils-deep/deepExtend');
For CommonJS environments, destructure specific functions from the main module export. The library does not support direct subpath imports for individual functions.

Demonstrates the core functionalities of `js-utils-deep`: `recursiveOmit` to clean deeply nested objects, `deepExtend` to merge objects recursively, and `diffObject` to find differences, highlighting their usage and mutation behavior.

import { recursiveOmit, deepExtend, diffObject } from 'js-utils-deep'; // Example for recursiveOmit: Removes null, '', undefined from deeply nested objects let objToOmit = { x: { y: { z: '' }, a: { b: null, c: undefined }, d: null }, e: 0, f: 'hello', g: [] }; console.log('Original object for omit:', JSON.stringify(objToOmit)); const omitted = recursiveOmit(objToOmit); // Mutates objToOmit console.log('Object after recursiveOmit:', JSON.stringify(omitted)); // Expected: {"e":0,"f":"hello","g":[]} // Example for deepExtend: Deeply merges source into target object let targetObj = { x: { y: { z: '' }, a: { b: null, c: undefined } }, existing: 'value' }; let sourceObj = { x: { y: { z: 'new_z' }, a: { b: 'new_b', c: 'new_c' }, d: 'new_d' }, newProp: 'added' }; console.log('Target object before extend:', JSON.stringify(targetObj)); deepExtend(targetObj, sourceObj); // Mutates targetObj console.log('Target object after deepExtend:', JSON.stringify(targetObj)); // Expected: {"x":{"y":{"z":"new_z"},"a":{"b":"new_b","c":"new_c"},"d":"new_d"},"existing":"value","newProp":"added"} // Example for diffObject: Compares two objects and returns differing key-value pairs let obj1 = { id: 1, name: 'Alpha', details: { version: '1.0', status: 'active' } }; let obj2 = { id: 1, name: 'Beta', details: { version: '1.1', owner: 'Org' }, tags: ['new'] }; console.log('Object 1 for diff:', JSON.stringify(obj1)); console.log('Object 2 for diff:', JSON.stringify(obj2)); const differences = diffObject(obj1, obj2); console.log('Differences between objects:', JSON.stringify(differences)); // Expected: {"name":"Beta","details":{"version":"1.1","status":"active","owner":"Org"},"tags":["new"]}
Debug
Known issues
gotchaBoth `deepExtend` and `recursiveOmit` functions mutate their first argument (the target object) in place. If you need to preserve the original object, ensure you pass a deep clone of it as the first argument.
fix
Before calling `deepExtend(obj1, obj2)` or `recursiveOmit(obj)`, create a deep clone of `obj1` or `obj` (e.g., `const clonedObj = JSON.parse(JSON.stringify(obj));`) and pass the clone to the function.
affects: >=1.0.0
gotchaFunctions that perform deep object traversal, such as `recursiveOmit`, `deepExtend`, and `diffObject`, may encounter infinite loops and throw a 'Maximum call stack size exceeded' error if presented with objects containing circular references.
fix
Ensure objects passed to deep utility functions do not contain circular references. Pre-process objects to remove or break cycles if necessary, or use a library designed to handle circular references explicitly.
affects: >=1.0.0
gotchaThe `recursiveOmit` function treats empty strings `''` as values to be omitted, similar to `null` and `undefined`. Be aware of this behavior if empty strings have semantic meaning in your data and should be preserved.
fix
If empty strings need to be preserved, consider pre-processing your object to replace empty strings with a placeholder or use a custom recursive function for omission.
affects: >=1.0.0
Errors
Common errors & fixes
RangeError: Maximum call stack size exceeded
An object with circular references was passed to a recursive function like `recursiveOmit` or `deepExtend`.
fix
Inspect the object structure for circular references. Refactor your object to avoid them, or preprocess the object to break cycles (e.g., by setting circular references to `null`) before passing it to `js-utils-deep` functions.
TypeError: Cannot convert undefined or null to object
Attempting to call a deep utility function (e.g., `deepExtend`, `recursiveOmit`) with `null` or `undefined` as a primary object argument.
fix
Ensure all arguments passed to `js-utils-deep` functions, especially the target or source objects, are valid JavaScript objects (non-null, non-undefined).
TypeError: Cannot set properties of undefined (setting 'propertyName')
This error can occur within `deepExtend` if a nested property path in the source object points to an `undefined` or `null` path in the target object where it's attempting to create a new object or set a value.
fix
Ensure that intermediate objects exist in the target where `deepExtend` is expected to merge. For example, if `source.a.b` exists, but `target.a` is `undefined`, `deepExtend` might fail. Pre-initialize empty objects for paths if necessary, or ensure your target object's structure is compatible with the source.
Upgrade
Version history
1.1.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
js-utils-deep — npm install js-utils-deep · libregistry