The `object-traversal` package provides a flexible and highly performant utility for depth-first or breadth-first traversal of JavaScript objects. Currently at stable version 1.0.1, the library maintains an active release cadence, with recent updates fixing minor issues after a major breaking change. Its key differentiators include exceptional speed, claiming to traverse over 20 million nodes per second and being approximately 10 times faster than popular alternatives, along with extensive configurability options for traversal order, maximum depth, and cycle handling. The library is lightweight with zero external dependencies, making it suitable for both Node.js (>=10) and browser environments, and it ships with full TypeScript support, providing robust type definitions for callbacks and options.
npm install object-traversalVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use `traverse` to modify an object in-place by doubling all numeric values and finding a specific node while halting traversal early.
Update all callback function implementations to reference `meta.nodePath` instead of `meta.currentPath`.
If re-visiting nodes is essential and you can manage cycles, set `cycleHandling: false` in `TraversalOpts`. Otherwise, rely on the default to avoid infinite loops.
If a full traversal is always required, ensure `haltOnTruthy` is explicitly set to `false` in `TraversalOpts`. When searching, return `true` from the callback to optimize performance by halting early.
Add a check within the callback function to ensure `parent` and `key` are not `null` before attempting to modify `parent[key]`. For example: `if (parent && key && typeof value === 'number') { parent[key] = value * 2; }`.For ESM, use `import { traverse } from 'object-traversal';`. For CommonJS in Node.js, use `const { traverse } = require('object-traversal');`. Ensure your project's module resolution is correctly configured.Update your code to use the new property name `meta.nodePath` instead of `meta.currentPath`.
No dependency data recorded yet.