aboutsummaryrefslogtreecommitdiff
path: root/node_modules/map-visit
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/map-visit')
-rw-r--r--node_modules/map-visit/LICENSE2
-rw-r--r--node_modules/map-visit/README.md46
-rw-r--r--node_modules/map-visit/index.js30
-rw-r--r--node_modules/map-visit/package.json33
-rw-r--r--node_modules/map-visit/utils.js14
5 files changed, 70 insertions, 55 deletions
diff --git a/node_modules/map-visit/LICENSE b/node_modules/map-visit/LICENSE
index 652517172..83b56e709 100644
--- a/node_modules/map-visit/LICENSE
+++ b/node_modules/map-visit/LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright (c) 2015-2016, Jon Schlinkert
+Copyright (c) 2015-2017, Jon Schlinkert
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/node_modules/map-visit/README.md b/node_modules/map-visit/README.md
index c4b75985c..5ab02d450 100644
--- a/node_modules/map-visit/README.md
+++ b/node_modules/map-visit/README.md
@@ -1,6 +1,6 @@
-# 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.
## Install
@@ -16,7 +16,9 @@ $ npm install --save map-visit
var mapVisit = require('map-visit');
```
-## 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:
@@ -26,7 +28,7 @@ Let's say you want to add a `set` method to your application that will:
**Example using `extend`**
-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`):
```js
var _ = require('lodash');
@@ -52,11 +54,16 @@ console.log(obj.data);
//=> {a: 'a', b: 'b', c: 'c', d: { e: 'f' }}
```
-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
var mapVisit = require('map-visit');
@@ -70,7 +77,7 @@ var obj = {
} else if (typeof key === 'object') {
visit(obj, 'set', key);
} else {
- // some event-emitter
+ // simulate an event-emitter
console.log('emit', key, value);
obj.data[key] = value;
}
@@ -106,22 +113,29 @@ console.log(obj.data);
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
+### 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
```
### Running tests
-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
```
### Author
@@ -129,13 +143,13 @@ $ npm install -d && npm test
**Jon Schlinkert**
* [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._ \ No newline at end of file
+_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.5.0, on April 09, 2017._ \ No newline at end of file
diff --git a/node_modules/map-visit/index.js b/node_modules/map-visit/index.js
index 426735d9f..bc54ccc4e 100644
--- a/node_modules/map-visit/index.js
+++ b/node_modules/map-visit/index.js
@@ -1,6 +1,7 @@
'use strict';
-var utils = require('./utils');
+var util = require('util');
+var visit = require('object-visit');
/**
* Map `visit` over an array of objects.
@@ -10,16 +11,27 @@ var utils = require('./utils');
* @param {Object} `arr` Array of objects.
*/
-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'));
+}
diff --git a/node_modules/map-visit/package.json b/node_modules/map-visit/package.json
index d848c51da..e8d0f41c6 100644
--- a/node_modules/map-visit/package.json
+++ b/node_modules/map-visit/package.json
@@ -1,17 +1,20 @@
{
"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",
"bugs": {
"url": "https://github.com/jonschlinkert/map-visit/issues"
},
"license": "MIT",
"files": [
- "index.js",
- "utils.js"
+ "index.js"
],
"main": "index.js",
"engines": {
@@ -21,14 +24,14 @@
"test": "mocha"
},
"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"
},
"keywords": [
"array",
@@ -46,12 +49,6 @@
"visitor"
],
"verb": {
- "related": {
- "list": [
- "collection-visit",
- "object-visit"
- ]
- },
"toc": false,
"layout": "default",
"tasks": [
@@ -63,6 +60,12 @@
"lint": {
"reflinks": true
},
+ "related": {
+ "list": [
+ "collection-visit",
+ "object-visit"
+ ]
+ },
"reflinks": [
"verb",
"verb-generate-readme"
diff --git a/node_modules/map-visit/utils.js b/node_modules/map-visit/utils.js
deleted file mode 100644
index 4707585bf..000000000
--- a/node_modules/map-visit/utils.js
+++ /dev/null
@@ -1,14 +0,0 @@
-'use strict';
-
-var utils = require('lazy-cache')(require);
-var fn = require;
-
-require = utils; // trick browserify
-require('object-visit', 'visit');
-require = fn;
-
-/**
- * Expose utils
- */
-
-module.exports = utils;