pax_global_header00006660000000000000000000000064133044255540014517gustar00rootroot0000000000000052 comment=7adaf8162a12d55f6ea3fb0bf5e999035dfd303a for-each-0.3.3/000077500000000000000000000000001330442555400132065ustar00rootroot00000000000000for-each-0.3.3/.editorconfig000066400000000000000000000004361330442555400156660ustar00rootroot00000000000000root = true [*] indent_style = tab indent_size = 4 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true max_line_length = 120 [CHANGELOG.md] indent_style = space indent_size = 2 [*.json] max_line_length = off [Makefile] max_line_length = off for-each-0.3.3/.eslintrc000066400000000000000000000005721330442555400150360ustar00rootroot00000000000000{ "root": true, "extends": "@ljharb", "rules": { "eqeqeq": [2, "allow-null"], "func-name-matching": 0, "indent": [2, 4], "max-nested-callbacks": [2, 3], "max-params": [2, 3], "max-statements": [2, 14], "no-invalid-this": [1], "no-restricted-syntax": [2, "BreakStatement", "ContinueStatement", "DebuggerStatement", "LabeledStatement", "WithStatement"], } } for-each-0.3.3/.gitignore000066400000000000000000000001701330442555400151740ustar00rootroot00000000000000# gitignore node_modules *.log *.err # Only apps should have lockfiles npm-shrinkwrap.json package-lock.json yarn.lock for-each-0.3.3/.npmrc000066400000000000000000000000231330442555400143210ustar00rootroot00000000000000package-lock=false for-each-0.3.3/.travis.yml000066400000000000000000000031111330442555400153130ustar00rootroot00000000000000language: node_js os: - linux node_js: - "8" - "7" - "6" - "5" - "4" - "iojs" - "0.12" - "0.10" - "0.8" before_install: - 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ]; then npm install -g npm@1.3 ; elif [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then case "$(npm --version)" in 1.*) npm install -g npm@1.4.28 ;; 2.*) npm install -g npm@2 ;; esac ; fi' - 'if [ "${TRAVIS_NODE_VERSION}" != "0.6" ] && [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then if [ "${TRAVIS_NODE_VERSION%${TRAVIS_NODE_VERSION#[0-9]}}" = "0" ] || [ "${TRAVIS_NODE_VERSION:0:4}" = "iojs" ]; then npm install -g npm@4.5 ; else npm install -g npm; fi; fi' install: - 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ]; then nvm install 0.8 && npm install -g npm@1.3 && npm install -g npm@1.4.28 && npm install -g npm@2 && npm install && nvm use "${TRAVIS_NODE_VERSION}"; else npm install; fi;' script: - 'if [ -n "${PRETEST-}" ]; then npm run pretest ; fi' - 'if [ -n "${POSTTEST-}" ]; then npm run posttest ; fi' - 'if [ -n "${COVERAGE-}" ]; then npm run coverage ; fi' - 'if [ -n "${TEST-}" ]; then npm run tests-only ; fi' sudo: false env: - TEST=true matrix: fast_finish: true include: - node_js: "node" env: PRETEST=true - node_js: "node" env: POSTTEST=true - node_js: "0.11" env: TEST=true ALLOW_FAILURE=true - node_js: "0.9" env: TEST=true ALLOW_FAILURE=true - node_js: "0.6" env: TEST=true ALLOW_FAILURE=true - node_js: "0.4" env: TEST=true ALLOW_FAILURE=true allow_failures: - os: osx - env: TEST=true ALLOW_FAILURE=true - env: COVERAGE=true for-each-0.3.3/LICENSE000066400000000000000000000020631330442555400142140ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2012 Raynos. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. for-each-0.3.3/README.md000066400000000000000000000013521330442555400144660ustar00rootroot00000000000000# for-each [![build status][1]][2] [![browser support][3]][4] A better forEach. ## Example Like `Array.prototype.forEach` but works on objects. ```js var forEach = require("for-each") forEach({ key: "value" }, function (value, key, object) { /* code */ }) ``` As a bonus, it's also a perfectly function shim/polyfill for arrays too! ```js var forEach = require("for-each") forEach([1, 2, 3], function (value, index, array) { /* code */ }) ``` ## Installation `npm install for-each` ## Contributors - Raynos ## MIT Licenced [1]: https://secure.travis-ci.org/Raynos/for-each.png [2]: http://travis-ci.org/Raynos/for-each [3]: https://ci.testling.com/Raynos/for-each.png [4]: https://ci.testling.com/Raynos/for-each for-each-0.3.3/index.js000066400000000000000000000033411330442555400146540ustar00rootroot00000000000000'use strict'; var isCallable = require('is-callable'); var toStr = Object.prototype.toString; var hasOwnProperty = Object.prototype.hasOwnProperty; 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) { iterator(array[i], i, array); } else { iterator.call(receiver, array[i], i, array); } } } }; 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) { iterator(string.charAt(i), i, string); } else { iterator.call(receiver, string.charAt(i), i, string); } } }; var forEachObject = function forEachObject(object, iterator, receiver) { for (var k in object) { if (hasOwnProperty.call(object, k)) { if (receiver == null) { iterator(object[k], k, object); } else { iterator.call(receiver, object[k], k, object); } } } }; 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; for-each-0.3.3/package.json000066400000000000000000000027371330442555400155050ustar00rootroot00000000000000{ "name": "for-each", "version": "0.3.3", "description": "A better forEach", "keywords": [], "author": "Raynos ", "repository": "git://github.com/Raynos/for-each.git", "main": "index", "homepage": "https://github.com/Raynos/for-each", "contributors": [ { "name": "Jake Verbaten" }, { "name": "Jordan Harband", "url": "https://github.com/ljharb" } ], "bugs": { "url": "https://github.com/Raynos/for-each/issues", "email": "raynos2@gmail.com" }, "dependencies": { "is-callable": "^1.1.3" }, "devDependencies": { "@ljharb/eslint-config": "^12.2.1", "eslint": "^4.19.1", "nsp": "^3.2.1", "tape": "^4.9.0" }, "license": "MIT", "licenses": [ { "type": "MIT", "url": "http://github.com/Raynos/for-each/raw/master/LICENSE" } ], "scripts": { "pretest": "npm run lint", "test": "npm run tests-only", "tests-only": "node test/test", "posttest": "npm run security", "lint": "eslint *.js test/*.js", "security": "nsp check" }, "testling": { "files": "test/test.js", "browsers": [ "iexplore/6.0..latest", "firefox/3.0..6.0", "firefox/15.0..latest", "firefox/nightly", "chrome/4.0..10.0", "chrome/20.0..latest", "chrome/canary", "opera/10.0..latest", "opera/next", "safari/4.0..latest", "ipad/6.0..latest", "iphone/6.0..latest", "android-browser/4.2" ] } } for-each-0.3.3/test/000077500000000000000000000000001330442555400141655ustar00rootroot00000000000000for-each-0.3.3/test/.eslintrc000066400000000000000000000002101330442555400160020ustar00rootroot00000000000000{ "rules": { "array-bracket-newline": 0, "array-element-newline": 0, "max-statements-per-line": 0, "no-magic-numbers": 0, } } for-each-0.3.3/test/test.js000066400000000000000000000126431330442555400155100ustar00rootroot00000000000000'use strict'; /* globals window */ var test = require('tape'); var forEach = require('../'); test('forEach calls each iterator', function (t) { var count = 0; t.plan(4); forEach({ a: 1, b: 2 }, function (value, key) { if (count === 0) { t.equal(value, 1); t.equal(key, 'a'); } else { t.equal(value, 2); t.equal(key, 'b'); } count += 1; }); }); test('forEach calls iterator with correct this value', function (t) { var thisValue = {}; t.plan(1); forEach([0], function () { t.equal(this, thisValue); }, thisValue); }); test('second argument: iterator', function (t) { var arr = []; t['throws'](function () { forEach(arr); }, TypeError, 'undefined is not a function'); t['throws'](function () { forEach(arr, null); }, TypeError, 'null is not a function'); t['throws'](function () { forEach(arr, ''); }, TypeError, 'string is not a function'); t['throws'](function () { forEach(arr, /a/); }, TypeError, 'regex is not a function'); t['throws'](function () { forEach(arr, true); }, TypeError, 'true is not a function'); t['throws'](function () { forEach(arr, false); }, TypeError, 'false is not a function'); t['throws'](function () { forEach(arr, NaN); }, TypeError, 'NaN is not a function'); t['throws'](function () { forEach(arr, 42); }, TypeError, '42 is not a function'); t.doesNotThrow(function () { forEach(arr, function () {}); }, 'function is a function'); t.doesNotThrow(function () { forEach(arr, setTimeout); }, 'setTimeout is a function'); if (typeof window !== 'undefined') { t.doesNotThrow(function () { forEach(arr, window.alert); }, 'alert is a function'); } t.end(); }); test('array', function (t) { var arr = [1, 2, 3]; t.test('iterates over every item', function (st) { var index = 0; forEach(arr, function () { index += 1; }); st.equal(index, arr.length, 'iterates ' + arr.length + ' times'); st.end(); }); t.test('first iterator argument', function (st) { var index = 0; st.plan(arr.length); forEach(arr, function (item) { st.equal(arr[index], item, 'item ' + index + ' is passed as first argument'); index += 1; }); st.end(); }); t.test('second iterator argument', function (st) { var counter = 0; st.plan(arr.length); forEach(arr, function (item, index) { st.equal(counter, index, 'index ' + index + ' is passed as second argument'); counter += 1; }); st.end(); }); t.test('third iterator argument', function (st) { st.plan(arr.length); forEach(arr, function (item, index, array) { st.deepEqual(arr, array, 'array is passed as third argument'); }); st.end(); }); t.test('context argument', function (st) { var context = {}; forEach([], function () { st.equal(this, context, '"this" is the passed context'); }, context); st.end(); }); t.end(); }); test('object', function (t) { var obj = { a: 1, b: 2, c: 3 }; var keys = ['a', 'b', 'c']; var F = function F() { this.a = 1; this.b = 2; }; F.prototype.c = 3; var fKeys = ['a', 'b']; t.test('iterates over every object literal key', function (st) { var counter = 0; forEach(obj, function () { counter += 1; }); st.equal(counter, keys.length, 'iterated ' + counter + ' times'); st.end(); }); t.test('iterates only over own keys', function (st) { var counter = 0; forEach(new F(), function () { counter += 1; }); st.equal(counter, fKeys.length, 'iterated ' + fKeys.length + ' times'); st.end(); }); t.test('first iterator argument', function (st) { var index = 0; st.plan(keys.length); forEach(obj, function (item) { st.equal(obj[keys[index]], item, 'item at key ' + keys[index] + ' is passed as first argument'); index += 1; }); st.end(); }); t.test('second iterator argument', function (st) { var counter = 0; st.plan(keys.length); forEach(obj, function (item, key) { st.equal(keys[counter], key, 'key ' + key + ' is passed as second argument'); counter += 1; }); st.end(); }); t.test('third iterator argument', function (st) { st.plan(keys.length); forEach(obj, function (item, key, object) { st.deepEqual(obj, object, 'object is passed as third argument'); }); st.end(); }); t.test('context argument', function (st) { var context = {}; forEach({}, function () { st.equal(this, context, '"this" is the passed context'); }, context); st.end(); }); t.end(); }); test('string', function (t) { var str = 'str'; t.test('second iterator argument', function (st) { var counter = 0; st.plan((str.length * 2) + 1); forEach(str, function (item, index) { st.equal(counter, index, 'index ' + index + ' is passed as second argument'); st.equal(str.charAt(index), item); counter += 1; }); st.equal(counter, str.length, 'iterates ' + str.length + ' times'); st.end(); }); t.end(); });