@whi/object-walk
v0.3.0
Published
A method for traversing an object and optionally replacing values
Downloads
34
Readme
Object.walk( obj, replacer )
This module is intended to help with recursively traversing an object and optionally replacing values.
Overview
Doesn't traverse
do this?
Traverse is a great library, but it hasn't been updated since 2013. The internal assumptions
(specifically around the immutable/copy feature) do not support newer types such as Node's Buffer
class. You may see this error message when using traverse
with Buffer
TypeError: Method get TypedArray.prototype.length called on incompatible receiver [object Object]
Another reason you might use Object.walk
instead of traverse
is to avoid dependence on this
context. I don't see anything wrong with the object oriented approach, but this library is intended
to feel like a native method. Other native implementations with callbacks (such as
JSON.stringify
) don't add contextual API's to this
.
Install
npm i @whi/object-walk
Usage
const { walk } = require('@whi/object-walk');
walk( some_obj, function ( key, value ) {
return value;
});
Alternatively, attach walk
to the native Object
as a method.
require('@whi/object-walk').bindNative();
Object.walk( some_obj, function ( key, value ) {
return value;
});
API Reference
See docs/API.md
Contributing
See CONTRIBUTING.md