Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

map-visit

Package Overview
Dependencies
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

map-visit - npm Package Compare versions

Comparing version 0.1.5 to 1.0.0

30

index.js
'use strict';
var utils = require('./utils');
var util = require('util');
var visit = require('object-visit');

@@ -13,14 +14,25 @@ /**

module.exports = function mapVisit(collection, method, arr) {
if (!Array.isArray(arr)) {
throw new TypeError('expected an array');
module.exports = function mapVisit(collection, method, val) {
if (isObject(val)) {
return visit.apply(null, arguments);
}
arr.forEach(function(val) {
if (typeof val === 'string') {
collection[method](val);
if (!Array.isArray(val)) {
throw new TypeError('expected an array: ' + util.inspect(val));
}
var args = [].slice.call(arguments, 3);
for (var i = 0; i < val.length; i++) {
var ele = val[i];
if (isObject(ele)) {
visit.apply(null, [collection, method, ele].concat(args));
} else {
utils.visit(collection, method, val);
collection[method].apply(collection, [ele].concat(args));
}
});
}
};
function isObject(val) {
return val && (typeof val === 'function' || (!Array.isArray(val) && typeof val === 'object'));
}
{
"name": "map-visit",
"description": "Map `visit` over an array of objects.",
"version": "0.1.5",
"version": "1.0.0",
"homepage": "https://github.com/jonschlinkert/map-visit",
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"contributors": [
"Brian Woodward <brian.woodward@gmail.com> (https://twitter.com/doowb)",
"Jon Schlinkert <jon.schlinkert@sellside.com> (http://twitter.com/jonschlinkert)"
],
"repository": "jonschlinkert/map-visit",

@@ -13,4 +17,3 @@ "bugs": {

"files": [
"index.js",
"utils.js"
"index.js"
],

@@ -25,10 +28,10 @@ "main": "index.js",

"dependencies": {
"lazy-cache": "^2.0.1",
"object-visit": "^0.3.4"
"object-visit": "^1.0.0"
},
"devDependencies": {
"gulp-format-md": "^0.1.10",
"lodash": "^4.14.1",
"mocha": "^3.0.1",
"should": "^10.0.0"
"clone-deep": "^0.2.4",
"extend-shallow": "^2.0.1",
"gulp-format-md": "^0.1.12",
"lodash": "^4.17.4",
"mocha": "^3.2.0"
},

@@ -51,8 +54,2 @@ "keywords": [

"verb": {
"related": {
"list": [
"collection-visit",
"object-visit"
]
},
"toc": false,

@@ -69,2 +66,8 @@ "layout": "default",

},
"related": {
"list": [
"collection-visit",
"object-visit"
]
},
"reflinks": [

@@ -71,0 +74,0 @@ "verb",

@@ -1,4 +0,4 @@

# map-visit [![NPM version](https://img.shields.io/npm/v/map-visit.svg?style=flat)](https://www.npmjs.com/package/map-visit) [![NPM downloads](https://img.shields.io/npm/dm/map-visit.svg?style=flat)](https://npmjs.org/package/map-visit) [![Build Status](https://img.shields.io/travis/jonschlinkert/map-visit.svg?style=flat)](https://travis-ci.org/jonschlinkert/map-visit)
# map-visit [![NPM version](https://img.shields.io/npm/v/map-visit.svg?style=flat)](https://www.npmjs.com/package/map-visit) [![NPM monthly downloads](https://img.shields.io/npm/dm/map-visit.svg?style=flat)](https://npmjs.org/package/map-visit) [![NPM total downloads](https://img.shields.io/npm/dt/map-visit.svg?style=flat)](https://npmjs.org/package/map-visit) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/map-visit.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/map-visit)
Map `visit` over an array of objects.
> Map `visit` over an array of objects.

@@ -19,4 +19,6 @@ ## Install

## Assign or Merge vs. Visit
## What does this do?
**Assign/Merge/Extend vs. Visit**
Let's say you want to add a `set` method to your application that will:

@@ -30,3 +32,3 @@

Here is one way to accomplish this using Lo-Dash's `extend`:
Here is one way to accomplish this using Lo-Dash's `extend` (comparable to `Object.assign`):

@@ -57,8 +59,13 @@ ```js

The above approach works fine for most use cases. But **if you also want to emit an event** each time a property is added to the `data` object. A better approach would be to use `visit`.
The above approach works fine for most use cases. However, **if you also want to emit an event** each time a property is added to the `data` object, or you want more control over what happens as the object is extended, a better approach would be to use `visit`.
**Example using `visit`**
In this approach, when an array is passed to `set`, `mapVisit` calls `set` on each object in the array. When an object is passed, `visit` calls `set` on each property in the object. As a result, the `data` event will be emitted every time a property is added to `data`.
In this approach:
* when an array is passed to `set`, the `mapVisit` library calls the `set` method on each object in the array.
* when an object is passed, `visit` calls `set` on each property in the object.
As a result, the `data` event will be emitted every time a property is added to `data` (events are just an example, you can use this approach to perform any necessary logic every time the method is called).
```js

@@ -76,3 +83,3 @@ var mapVisit = require('map-visit');

} else {
// some event-emitter
// simulate an event-emitter
console.log('emit', key, value);

@@ -113,10 +120,17 @@ obj.data[key] = value;

### Contributors
| **Commits** | **Contributor** |
| --- | --- |
| 15 | [jonschlinkert](https://github.com/jonschlinkert) |
| 7 | [doowb](https://github.com/doowb) |
### Building docs
_(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
To generate the readme and API documentation with [verb](https://github.com/verbose/verb):
To generate the readme, run the following command:
```sh
$ npm install -g verb verb-generate-readme && verb
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```

@@ -126,6 +140,6 @@

Install dev dependencies:
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:
```sh
$ npm install -d && npm test
$ npm install && npm test
```

@@ -138,11 +152,11 @@

* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
### License
Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT license](https://github.com/jonschlinkert/map-visit/blob/master/LICENSE).
Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).
***
_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on August 05, 2016._
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.5.0, on April 09, 2017._

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc