What is object-visit?
The object-visit npm package is designed to simplify the process of visiting and invoking methods on an object. It allows you to call a specified method on each property of an object, which can be particularly useful for tasks like data transformation, validation, or applying a series of operations to an object's properties.
What are object-visit's main functionalities?
Invoke a method on each property of an object
This feature allows you to invoke a specified method on each property of an object. In this example, the 'greet' method is called on each property of the object, transforming the 'greet' property to its return value.
const visit = require('object-visit');
const obj = {
name: 'John',
age: 30,
greet: function() { return `Hello, my name is ${this.name}`; }
};
visit(obj, 'greet');
// Output: { name: 'John', age: 30, greet: 'Hello, my name is John' }
Invoke a method with arguments on each property of an object
This feature allows you to invoke a specified method with arguments on each property of an object. In this example, the 'greet' method is called with the argument 'Hi' on each property of the object, transforming the 'greet' property to its return value.
const visit = require('object-visit');
const obj = {
name: 'John',
age: 30,
greet: function(greeting) { return `${greeting}, my name is ${this.name}`; }
};
visit(obj, 'greet', 'Hi');
// Output: { name: 'John', age: 30, greet: 'Hi, my name is John' }
Other packages similar to object-visit
lodash
Lodash is a modern JavaScript utility library delivering modularity, performance, and extras. It provides a wide range of utility functions for common programming tasks, including object manipulation. Compared to object-visit, Lodash offers a broader set of functionalities but may be more complex to use for simple method invocation tasks.
underscore
Underscore is a JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects. It includes utilities for working with objects, arrays, and functions. While it offers similar object manipulation capabilities, it is not as focused on method invocation as object-visit.
ramda
Ramda is a practical functional library for JavaScript programmers. It makes it easy to create functional pipelines and work with immutable data structures. Ramda provides utilities for object manipulation, but its primary focus is on functional programming paradigms, making it different in scope compared to object-visit.
object-visit

Call a specified method on each value in the given object.
Install
Install with npm:
$ npm install --save object-visit
Usage
var visit = require('object-visit');
var ctx = {
data: {},
set: function (key, value) {
if (typeof key === 'object') {
visit(ctx, 'set', key);
} else {
ctx.data[key] = value;
}
}
};
ctx.set('a', 'a');
ctx.set('b', 'b');
ctx.set('c', 'c');
ctx.set({d: {e: 'f'}});
console.log(ctx.data);
About
Related projects
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Building docs
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb
Running tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
Author
Jon Schlinkert
License
Copyright Ā© 2017, Jon Schlinkert.
Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on May 30, 2017.