Permalink
Browse files

Merge pull request #6 from yields/master

use component/to-function
  • Loading branch information...
2 parents 2b33467 + 711ed6b commit 188d75431152ddebab6de44f650c1b05a7e89842 @tj tj committed Jul 29, 2013
Showing with 25 additions and 6 deletions.
  1. +2 −1 component.json
  2. +10 −2 index.js
  3. +4 −2 package.json
  4. +9 −1 test/index.js
View
@@ -5,10 +5,11 @@
"version": "0.0.1",
"keywords": ["object", "string", "array", "each", "utility"],
"dependencies": {
+ "component/to-function": "*",
"component/type": "*"
},
"development": {},
"scripts": [
"index.js"
]
-}
+}
View
@@ -3,7 +3,14 @@
* Module dependencies.
*/
-var type = require('type');
+var toFunction = require('to-function');
+var type;
+
+try {
+ type = require('type-component');
+} catch (e) {
+ type = require('type');
+}
/**
* HOP reference.
@@ -20,6 +27,7 @@ var has = Object.prototype.hasOwnProperty;
*/
module.exports = function(obj, fn){
+ fn = toFunction(fn);
switch (type(obj)) {
case 'array':
return array(obj, fn);
@@ -73,4 +81,4 @@ function array(obj, fn) {
for (var i = 0; i < obj.length; ++i) {
fn(obj[i], i);
}
-}
+}
View
@@ -3,10 +3,12 @@
"version": "0.0.1",
"description": "Array / object / string iteration utility",
"dependencies": {
- "type": "component/type"
+ "type-component": "*",
+ "to-function": "*"
},
"browser": {
- "type": "node_modules/component-type/index.js"
+ "type": "node_modules/component-type/index.js",
+ "to-function": "node_modules/to-function/index.js"
},
"devDependencies": {
"mocha": "*",
View
@@ -49,4 +49,12 @@ describe('each(str, fn)', function(){
});
vals.should.eql(['h', 0, 'e', 1, 'y', 2]);
})
-})
+})
+
+describe('each(users, fn)', function(){
+ it('should use toFunction', function(){
+ var users = [{ name: 'john' }];
+ each(users, '.name = "baz"');
+ users[0].name.should.equal('baz');
+ })
+})

0 comments on commit 188d754

Please sign in to comment.