object-visit
Advanced tools
Comparing version 0.2.1 to 0.3.0
15
index.js
@@ -11,10 +11,15 @@ /*! | ||
var isObject = require('isobject'); | ||
var expected - require('expected'); | ||
module.exports = function visit(thisArg, method, target) { | ||
if (!isObject(thisArg) && typeof thisArg !== 'function') { | ||
throw new Error('object-visit expects `thisArg` to be an object.'); | ||
expected(thisArg).to.be.an('object'); | ||
} | ||
if (!isObject(target) && typeof target !== 'function') { | ||
expected(target).to.be.an('object'); | ||
} | ||
if (typeof method !== 'string') { | ||
throw new Error('object-visit expects `method` name to be a string'); | ||
expected(method).to.be.a('string'); | ||
} | ||
@@ -24,5 +29,9 @@ | ||
for (var key in target) { | ||
thisArg[method](key, target[key]); | ||
var fn = thisArg[method]; | ||
if (typeof fn !== 'function') { | ||
expected(fn).to.be.a('function'); | ||
} | ||
fn(key, target[key]); | ||
} | ||
return thisArg; | ||
}; |
{ | ||
"name": "object-visit", | ||
"description": "Call the given method on each value in the given object.", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"homepage": "https://github.com/jonschlinkert/object-visit", | ||
@@ -23,2 +23,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"dependencies": { | ||
"expected": "^0.1.0", | ||
"isobject": "^1.0.0" | ||
@@ -44,2 +45,3 @@ }, | ||
"list": [ | ||
"base-methods", | ||
"collection-visit", | ||
@@ -46,0 +48,0 @@ "map-visit" |
@@ -40,2 +40,3 @@ # object-visit [![NPM version](https://badge.fury.io/js/object-visit.svg)](http://badge.fury.io/js/object-visit) | ||
* [base-methods](https://www.npmjs.com/package/base-methods): Starter for creating a node.js application with a handful of common methods, like `set`, `get`,… [more](https://www.npmjs.com/package/base-methods) | [homepage](https://github.com/jonschlinkert/base-methods) | ||
* [collection-visit](https://www.npmjs.com/package/collection-visit): Visit a method over the items in an object, or map visit over the objects… [more](https://www.npmjs.com/package/collection-visit) | [homepage](https://github.com/jonschlinkert/collection-visit) | ||
@@ -70,2 +71,2 @@ * [map-visit](https://www.npmjs.com/package/map-visit): Map `visit` over an array of objects. | [homepage](https://github.com/jonschlinkert/map-visit) | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on August 29, 2015._ | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on October 06, 2015._ |
4808
29
2
+ Addedexpected@^0.1.0
+ Addedexpected@0.1.0(transitive)