{"id":11156,"library":"js-object-utilities","title":"JavaScript Object Utilities","description":"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.","status":"active","version":"2.2.1","language":"javascript","source_language":"en","source_url":"https://github.com/rrainn/js-object-utilities","tags":["javascript","object","utilities","nested","helper","typescript"],"install":[{"cmd":"npm install js-object-utilities","lang":"bash","label":"npm"},{"cmd":"yarn add js-object-utilities","lang":"bash","label":"yarn"},{"cmd":"pnpm add js-object-utilities","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library is exported as a default object containing all utilities. Named imports like `{ get }` are not supported directly from the root module.","wrong":"import { objectUtils } from 'js-object-utilities';","symbol":"objectUtils","correct":"import objectUtils from 'js-object-utilities';"},{"note":"For CommonJS environments, the entire utility object is exported as default, requiring the module as a single variable.","wrong":"const { get } = require('js-object-utilities');","symbol":"objectUtils (CommonJS)","correct":"const objectUtils = require('js-object-utilities');"},{"note":"The package ships with TypeScript definitions. If you need to type the imported utility object, you can use the `ObjectUtilities` interface.","symbol":"Type definitions","correct":"import type { ObjectUtilities } from 'js-object-utilities';"}],"quickstart":{"code":"import objectUtils from 'js-object-utilities';\n\ninterface MyObject {\n  data: {\n    hello: string;\n    space?: string;\n    node?: string;\n    otherData?: Record<string, unknown>;\n  };\n  array?: { first: number };\n  array2?: MyObject;\n}\n\nlet myObject: MyObject = {\n  data: {\n    hello: 'world',\n    space: 'travel',\n    node: 'npm',\n    otherData: {}\n  }\n};\n\nconsole.log('Original object:', JSON.stringify(myObject, null, 2));\n\n// Get a nested value\nconst helloValue = objectUtils.get(myObject, 'data.hello');\nconsole.log(`Value of 'data.hello': ${helloValue}`); // Expected: world\n\n// Set a nested value\nobjectUtils.set(myObject, 'data.hello', 'universe');\nconsole.log('After setting data.hello:', JSON.stringify(myObject, null, 2)); // Expected: universe\n\n// Pick specific keys to create a new object\nconst pickedObject = objectUtils.pick(myObject, ['data.hello', 'data.space']);\nconsole.log('Picked object:', JSON.stringify(pickedObject, null, 2)); // Expected: { \"data\": { \"hello\": \"universe\", \"space\": \"travel\" } }\n\n// Delete a nested key\nobjectUtils.delete(myObject, 'data.node');\nconsole.log('After deleting data.node:', JSON.stringify(myObject, null, 2));\n\n// Clear empty objects\nobjectUtils.clearEmpties(myObject);\nconsole.log('After clearing empties:', JSON.stringify(myObject, null, 2)); // 'otherData' should be removed\n\n// Check for circularity\nlet circularObject: MyObject = {\n  data: { hello: 'circular' }\n};\ncircularObject.array2 = circularObject; // Create circular reference\nconsole.log('Is circular object circular?', objectUtils.isCircular(circularObject)); // Expected: true","lang":"typescript","description":"Demonstrates `get`, `set`, `pick`, `delete`, `clearEmpties`, and `isCircular` on a nested object, including how to set up a circular reference."},"warnings":[{"fix":"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`.","message":"Several utility functions like `set`, `delete`, and `clearEmpties` mutate the original object directly. Be mindful of this behavior when working with immutable state patterns or shared objects.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"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.","message":"The README example for `objectutils.pick` incorrectly shows `objectutils.delete` being called, but the description correctly states `pick` returns a new object with selected keys. Rely on the description and the expected behavior of a 'pick' function rather than the erroneous code snippet in the README.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always use `objectUtils.isCircular(obj)` before performing operations like `JSON.stringify()` on objects that might contain self-referential structures.","message":"The `isCircular` function is crucial for preventing infinite loops or stack overflows when stringifying or processing objects with circular references. Failing to check for circularity can lead to runtime errors in JSON serialization or other recursive operations.","severity":"gotcha","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":"Use the correct default import pattern: `import objectUtils from 'js-object-utilities';` then access methods as `objectUtils.get(obj, key);`.","cause":"Attempting to use named imports (e.g., `import { get } from 'js-object-utilities'`) when the package only provides a default export object.","error":"TypeError: objectutils.get is not a function"},{"fix":"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 */ }`.","cause":"This error occurs when a property is accessed on an `undefined` or `null` object during a nested path traversal, indicating an intermediate path segment does not exist. While `objectUtils.get` handles non-existent paths by returning `undefined`, this error typically arises when you try to access a sub-property of the `undefined` result from `get` without null-checking.","error":"Cannot read properties of undefined (reading 'hello')"},{"fix":"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`.","cause":"Attempting to stringify (`JSON.stringify`) or deeply clone an object that contains circular references without first detecting and handling them.","error":"RangeError: Maximum call stack size exceeded"}],"ecosystem":"npm"}