# object-walker

> Walk Objects like an Acrobat

Latest version **0.0.4** (published 2014-01-24) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install object-walker
pnpm add object-walker
yarn add object-walker
bun add object-walker
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2014-01-24 |
| First published | 2014-01-16 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Adriaan Pelzer |
| Maintainers | 4dr144n |
| Keywords | object, walker |

## Links

- npm: https://www.npmjs.com/package/object-walker
- Repository: https://github.com/adriaan-pelzer/object-walker
- Issues: https://github.com/adriaan-pelzer/object-walker/issues
- npm.io page: https://npm.io/package/object-walker

## Dependencies (2)

- [eyes](https://npm.io/package/eyes.md) ~0.1.8
- [underscore](https://npm.io/package/underscore.md) ~1.5.2

## Recent versions

- 0.0.4 (latest) — 2014-01-24
- 0.0.3 — 2014-01-23
- 0.0.2 — 2014-01-22
- 0.0.1 — 2014-01-16

## README

object-walker
=============

Walk Objects like an Acrobat
----------------------------

A functional object walker node module, with user-settable handlers for each of the following value types:

- Object
- Array
- Number
- Boolean
- Date
- String
- Null
- Undefined

**Install like this:**

```js
npm install object-walker
```

**Use like this:**

```js
var walker = require ( 'object-walker' );

var inputObject = {
    a: null,
    b: 123,
    c: {
        a: 'hello world',
        b: undefined
    }
};

/* Using your own iterator: */

walker.walkObject ( inputObject, function ( keys, value ) {

    /* 'keys' is an array, representing the tree-of-keys,
     * from root to where you are now
     * 'value' is the value of the node on which you are now
     */

    walker.walkObject ( value, iterator, keys );
} );

/* Using the built-in iterator, and setting some handlers */

walker.setCustomHandler ( 'Null', function ( keys, value ) {
    console.log ( keys[keys.length - 1] + ' is null' );
} );

walker.setCustomHandler ( 'Object', function ( keys, value ) {
    console.log ( keys[keys.length - 1] + ' is an object' );
} );

walker.walkObject ( inputObject, walker.iterator );

/* Outputs:
 * a is null
 * c is an object
 */

/* To reuse walker, call clearCustomHandlers, to clean up after
 * your previous walk.
 */

walker.clearCustomHandlers ();

 /* Using the built-in iterator, with custom handlers, and
  * populating a user context that gets passed along the
  * entire walk.
  */

walker.setCustomHandler ( 'Null', function ( keys, value, userCtx ) {
    var returnedCtx = userCtx;

    returnedCtx.push ( value );

    return returnedCtx;
} );

walker.setCustomHandler ( 'Object', function ( keys, value, userCtx ) {
    var returnedCtx = userCtx;

    returnedCtx.push ( value );

    return returnedCtx;
} );

userCtx = walker.walkObject ( inputObject, walker.iterator, [] );

/*
 * userCtx is: [ null, { a: 'hello world', b: undefined } ]
 */
```

---
_Source: https://npm.io/package/object-walker · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
