Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

use component/to-function #6

Merged
merged 1 commit into from

2 participants

@yields
Owner

No description provided.

@tj tj merged commit 188d754 into component:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 26, 2013
  1. @yields

    use component/to-function

    yields authored
This page is out of date. Refresh to see the latest.
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
3  component.json
@@ -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
12 index.js
@@ -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
6 package.json
@@ -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
10 test/index.js
@@ -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');
+ })
+})
Something went wrong with that request. Please try again.