@whi/object-walk

0.3.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @whi/object-walk

Weekly Downloads

8

Version

0.3.0

License

ISC

Unpacked Size

5.54 kB

Total Files

3

Last publish

Collaborators

  • brisebom