js-object-utilities is a lightweight JavaScript package providing a collection of helper methods designed for working with nested objects. It simplifies common tasks like accessing, setting, deleting, and transforming deeply nested properties using dot-notation paths. Currently at version 2.2.1, the library maintains a stable release cadence. Key differentiators include its focus on handling complex object structures gracefully, providing utilities for deep equality checks, detecting circular references, and clearing empty objects, which are often overlooked in more general-purpose utility libraries. It ships with TypeScript type definitions, enhancing development experience for TypeScript users.
npm install js-object-utilitiesVerified import paths — ran on the pinned version, not inferred.
Demonstrates `get`, `set`, `pick`, `delete`, `clearEmpties`, and `isCircular` on a nested object, including how to set up a circular reference.
If immutability is required, ensure you clone the object before passing it to mutating functions (e.g., using `structuredClone` or a deep merge utility) or use functions that explicitly return new objects, like `pick`.
When using `objectutils.pick`, expect it to return a *new* object containing only the specified keys, leaving the original object unchanged. Do not confuse it with `delete`'s in-place mutation.
Always use `objectUtils.isCircular(obj)` before performing operations like `JSON.stringify()` on objects that might contain self-referential structures.
Use the correct default import pattern: `import objectUtils from 'js-object-utilities';` then access methods as `objectUtils.get(obj, key);`.
Ensure the object passed to `objectUtils.get` is not `undefined` or `null`. Always check the return value of `objectUtils.get` before attempting further property access, e.g., `const value = objectUtils.get(obj, 'path'); if (value !== undefined) { /* use value */ }`.Before performing operations sensitive to circular references, use `objectUtils.isCircular(obj)` to check for their presence. If detected, you'll need to either remove the circular reference, transform the object, or use a custom replacer function for `JSON.stringify`.
No dependency data recorded yet.