0.3.0 • Published 2 years ago

@whi/object-walk v0.3.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

npm.io

Object.walk( obj, replacer )

This module is intended to help with recursively traversing an object and optionally replacing values.

npm.io npm.io npm.io

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

0.3.0

2 years ago

0.2.0

2 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago