Skip to content

Commit

Permalink
Run npm run lint as part of tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jul 17, 2015
1 parent 3601c93 commit a34ea05
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
54 changes: 27 additions & 27 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
var isCallable = require('is-callable');

module.exports = forEach;

var toStr = Object.prototype.toString;
var hasOwnProperty = Object.prototype.hasOwnProperty;

function forEach(list, iterator, thisArg) {
if (!isCallable(iterator)) {
throw new TypeError('iterator must be a function');
}

var receiver;
if (arguments.length >= 3) {
receiver = thisArg;
}

if (toStr.call(list) === '[object Array]') {
forEachArray(list, iterator, receiver);
} else if (typeof list === 'string') {
forEachString(list, iterator, receiver);
} else {
forEachObject(list, iterator, receiver);
}
}

function forEachArray(array, iterator, receiver) {
var forEachArray = function forEachArray(array, iterator, receiver) {
for (var i = 0, len = array.length; i < len; i++) {
if (hasOwnProperty.call(array, i)) {
if (receiver != null) {
Expand All @@ -34,9 +13,9 @@ function forEachArray(array, iterator, receiver) {
}
}
}
}
};

function forEachString(string, iterator, receiver) {
var forEachString = function forEachString(string, iterator, receiver) {
for (var i = 0, len = string.length; i < len; i++) {
// no such thing as a sparse string.
if (receiver != null) {
Expand All @@ -45,9 +24,9 @@ function forEachString(string, iterator, receiver) {
iterator(string.charAt(i), i, string);
}
}
}
};

function forEachObject(object, iterator, receiver) {
var forEachObject = function forEachObject(object, iterator, receiver) {
for (var k in object) {
if (hasOwnProperty.call(object, k)) {
if (receiver != null) {
Expand All @@ -57,4 +36,25 @@ function forEachObject(object, iterator, receiver) {
}
}
}
}
};

var forEach = function forEach(list, iterator, thisArg) {
if (!isCallable(iterator)) {
throw new TypeError('iterator must be a function');
}

var receiver;
if (arguments.length >= 3) {
receiver = thisArg;
}

if (toStr.call(list) === '[object Array]') {
forEachArray(list, iterator, receiver);
} else if (typeof list === 'string') {
forEachString(list, iterator, receiver);
} else {
forEachObject(list, iterator, receiver);
}
};

module.exports = forEach;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
}
],
"scripts": {
"test": "node test/test.js",
"test": "npm run lint && node test/test.js",
"lint": "npm run jscs && npm run eslint",
"jscs": "jscs *.js test/*.js",
"eslint": "eslint *.js test/*.js"
Expand Down

0 comments on commit a34ea05

Please sign in to comment.