Last change
on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
806 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | /*!
|
---|
| 2 | * object-visit <https://github.com/jonschlinkert/object-visit>
|
---|
| 3 | *
|
---|
| 4 | * Copyright (c) 2015, 2017, Jon Schlinkert.
|
---|
| 5 | * Released under the MIT License.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | 'use strict';
|
---|
| 9 |
|
---|
| 10 | var isObject = require('isobject');
|
---|
| 11 |
|
---|
| 12 | module.exports = function visit(thisArg, method, target, val) {
|
---|
| 13 | if (!isObject(thisArg) && typeof thisArg !== 'function') {
|
---|
| 14 | throw new Error('object-visit expects `thisArg` to be an object.');
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | if (typeof method !== 'string') {
|
---|
| 18 | throw new Error('object-visit expects `method` name to be a string');
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | if (typeof thisArg[method] !== 'function') {
|
---|
| 22 | return thisArg;
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | var args = [].slice.call(arguments, 3);
|
---|
| 26 | target = target || {};
|
---|
| 27 |
|
---|
| 28 | for (var key in target) {
|
---|
| 29 | var arr = [key, target[key]].concat(args);
|
---|
| 30 | thisArg[method].apply(thisArg, arr);
|
---|
| 31 | }
|
---|
| 32 | return thisArg;
|
---|
| 33 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.