Added logging, changed some directory structure

This commit is contained in:
2018-01-13 21:33:40 -05:00
parent f079a5f067
commit 8e72ffb917
73656 changed files with 35284 additions and 53718 deletions

View File

@@ -0,0 +1,3 @@
node_modules
components
build

View File

@@ -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.

View File

@@ -0,0 +1,11 @@
build: components
@component build
components: component.json
@component install --dev
clean:
rm -fr build components template.js
.PHONY: clean

View File

@@ -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

View File

@@ -0,0 +1,11 @@
{
"name": "foreach",
"description": "foreach component + npm package",
"version": "2.0.5",
"keywords": [],
"dependencies": {},
"scripts": [
"index.js"
],
"repo": "manuelstofer/foreach"
}

View File

@@ -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);
}
}
}
};

View File

@@ -0,0 +1,91 @@
{
"_args": [
[
"foreach@2.0.5",
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project"
]
],
"_from": "foreach@2.0.5",
"_id": "foreach@2.0.5",
"_inBundle": false,
"_integrity": "sha1-C+4AUBiusmDQo6865ljdATbsG5k=",
"_location": "/react-scripts/foreach",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "foreach@2.0.5",
"name": "foreach",
"escapedName": "foreach",
"rawSpec": "2.0.5",
"saveSpec": null,
"fetchSpec": "2.0.5"
},
"_requiredBy": [
"/react-scripts/define-properties"
],
"_resolved": "https://registry.npmjs.org/foreach/-/foreach-2.0.5.tgz",
"_spec": "2.0.5",
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project",
"author": {
"name": "Manuel Stofer",
"email": "manuel@takimata.ch"
},
"bugs": {
"url": "https://github.com/manuelstofer/foreach/issues"
},
"contributors": [
{
"name": "Manuel Stofer"
},
{
"name": "Jordan Harband",
"url": "https://github.com/ljharb"
}
],
"dependencies": {},
"description": "foreach component + npm package",
"devDependencies": {
"covert": "*",
"tape": "*"
},
"homepage": "https://github.com/manuelstofer/foreach#readme",
"keywords": [
"shim",
"Array.prototype.forEach",
"forEach",
"Array#forEach",
"each"
],
"license": "MIT",
"main": "index.js",
"name": "foreach",
"repository": {
"type": "git",
"url": "git://github.com/manuelstofer/foreach.git"
},
"scripts": {
"coverage": "covert test.js",
"coverage-quiet": "covert --quiet test.js",
"test": "node test.js"
},
"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"
]
},
"version": "2.0.5"
}

View File

@@ -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();
});