diff options
author | Minteck <contact@minteck.org> | 2021-12-21 16:52:28 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2021-12-21 16:52:28 +0100 |
commit | 46e43f4bde4a35785b4997b81e86cd19f046b69b (patch) | |
tree | c53c2f826f777f9d6b2d249dab556feb72a6c3a6 /src/node_modules/foreach | |
download | langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.gz langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.bz2 langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.zip |
Commit
Diffstat (limited to 'src/node_modules/foreach')
-rw-r--r-- | src/node_modules/foreach/.npmignore | 3 | ||||
-rw-r--r-- | src/node_modules/foreach/LICENSE | 24 | ||||
-rw-r--r-- | src/node_modules/foreach/Makefile | 11 | ||||
-rw-r--r-- | src/node_modules/foreach/Readme.md | 30 | ||||
-rw-r--r-- | src/node_modules/foreach/component.json | 11 | ||||
-rw-r--r-- | src/node_modules/foreach/index.js | 22 | ||||
-rw-r--r-- | src/node_modules/foreach/package.json | 57 | ||||
-rw-r--r-- | src/node_modules/foreach/test.js | 153 |
8 files changed, 311 insertions, 0 deletions
diff --git a/src/node_modules/foreach/.npmignore b/src/node_modules/foreach/.npmignore new file mode 100644 index 0000000..d135df6 --- /dev/null +++ b/src/node_modules/foreach/.npmignore @@ -0,0 +1,3 @@ +node_modules +components +build
\ No newline at end of file diff --git a/src/node_modules/foreach/LICENSE b/src/node_modules/foreach/LICENSE new file mode 100644 index 0000000..3032d6e --- /dev/null +++ b/src/node_modules/foreach/LICENSE @@ -0,0 +1,24 @@ +The MIT License + +Copyright (c) 2013 Manuel Stofer + +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. diff --git a/src/node_modules/foreach/Makefile b/src/node_modules/foreach/Makefile new file mode 100644 index 0000000..eae4117 --- /dev/null +++ b/src/node_modules/foreach/Makefile @@ -0,0 +1,11 @@ + +build: components + @component build + +components: component.json + @component install --dev + +clean: + rm -fr build components template.js + +.PHONY: clean diff --git a/src/node_modules/foreach/Readme.md b/src/node_modules/foreach/Readme.md new file mode 100644 index 0000000..2752b57 --- /dev/null +++ b/src/node_modules/foreach/Readme.md @@ -0,0 +1,30 @@ + +# foreach + +Iterate over the key value pairs of either an array-like object or a dictionary like object. + +[![browser support][1]][2] + +## API + +### foreach(object, function, [context]) + +```js +var each = require('foreach'); + +each([1,2,3], function (value, key, array) { + // value === 1, 2, 3 + // key === 0, 1, 2 + // array === [1, 2, 3] +}); + +each({0:1,1:2,2:3}, function (value, key, object) { + // value === 1, 2, 3 + // key === 0, 1, 2 + // object === {0:1,1:2,2:3} +}); +``` + +[1]: https://ci.testling.com/manuelstofer/foreach.png +[2]: https://ci.testling.com/manuelstofer/foreach + diff --git a/src/node_modules/foreach/component.json b/src/node_modules/foreach/component.json new file mode 100644 index 0000000..0eeecb5 --- /dev/null +++ b/src/node_modules/foreach/component.json @@ -0,0 +1,11 @@ +{ + "name": "foreach", + "description": "foreach component + npm package", + "version": "2.0.5", + "keywords": [], + "dependencies": {}, + "scripts": [ + "index.js" + ], + "repo": "manuelstofer/foreach" +} diff --git a/src/node_modules/foreach/index.js b/src/node_modules/foreach/index.js new file mode 100644 index 0000000..a961e4e --- /dev/null +++ b/src/node_modules/foreach/index.js @@ -0,0 +1,22 @@ + +var hasOwn = Object.prototype.hasOwnProperty; +var toString = Object.prototype.toString; + +module.exports = function forEach (obj, fn, ctx) { + if (toString.call(fn) !== '[object Function]') { + throw new TypeError('iterator must be a function'); + } + var l = obj.length; + if (l === +l) { + for (var i = 0; i < l; i++) { + fn.call(ctx, obj[i], i, obj); + } + } else { + for (var k in obj) { + if (hasOwn.call(obj, k)) { + fn.call(ctx, obj[k], k, obj); + } + } + } +}; + diff --git a/src/node_modules/foreach/package.json b/src/node_modules/foreach/package.json new file mode 100644 index 0000000..b3e74f4 --- /dev/null +++ b/src/node_modules/foreach/package.json @@ -0,0 +1,57 @@ +{ + "name": "foreach", + "description": "foreach component + npm package", + "version": "2.0.5", + "author": "Manuel Stofer <manuel@takimata.ch>", + "contributors": [ + { + "name": "Manuel Stofer" + }, + { + "name": "Jordan Harband", + "url": "https://github.com/ljharb" + } + ], + "license": "MIT", + "main": "index.js", + "scripts": { + "test": "node test.js", + "coverage": "covert test.js", + "coverage-quiet": "covert --quiet test.js" + }, + "repository": { + "type": "git", + "url": "git://github.com/manuelstofer/foreach" + }, + "keywords": [ + "shim", + "Array.prototype.forEach", + "forEach", + "Array#forEach", + "each" + ], + "dependencies": {}, + "devDependencies": { + "tape": "*", + "covert": "*" + }, + "testling": { + "files": "test.js", + "browsers": [ + "iexplore/6.0..latest", + "firefox/3.0", + "firefox/15.0..latest", + "firefox/nightly", + "chrome/4.0", + "chrome/22.0..latest", + "chrome/canary", + "opera/10.0..latest", + "opera/next", + "safari/5.0.5..latest", + "ipad/6.0..latest", + "iphone/6.0..latest", + "android-browser/4.2" + ] + } +} + diff --git a/src/node_modules/foreach/test.js b/src/node_modules/foreach/test.js new file mode 100644 index 0000000..c6283c3 --- /dev/null +++ b/src/node_modules/foreach/test.js @@ -0,0 +1,153 @@ +var test = require('tape'); +var forEach = require('./index.js'); + + +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.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 = {}; + st.plan(1); + forEach([1], 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 () { + 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 = {}; + st.plan(1); + forEach({ a: 1 }, 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'); + }); + t.end(); +}); + |