aboutsummaryrefslogtreecommitdiff
path: root/node_modules/reduce
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/reduce')
-rw-r--r--node_modules/reduce/.jscs.json53
-rw-r--r--node_modules/reduce/.npmignore3
-rw-r--r--node_modules/reduce/.travis.yml18
-rw-r--r--node_modules/reduce/LICENCE19
-rw-r--r--node_modules/reduce/README.md42
-rw-r--r--node_modules/reduce/index.js29
-rw-r--r--node_modules/reduce/package.json56
-rw-r--r--node_modules/reduce/test/simple.js94
8 files changed, 314 insertions, 0 deletions
diff --git a/node_modules/reduce/.jscs.json b/node_modules/reduce/.jscs.json
new file mode 100644
index 00000000..258f6e88
--- /dev/null
+++ b/node_modules/reduce/.jscs.json
@@ -0,0 +1,53 @@
+{
+ "requireCurlyBraces": ["if", "else", "for", "while", "do", "try", "catch"],
+
+ "requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch", "function"],
+
+ "disallowSpaceAfterKeywords": [],
+
+ "requireSpacesInAnonymousFunctionExpression": { "beforeOpeningRoundBrace": true, "beforeOpeningCurlyBrace": true },
+ "requireSpacesInNamedFunctionExpression": { "beforeOpeningCurlyBrace": true },
+ "disallowSpacesInNamedFunctionExpression": { "beforeOpeningRoundBrace": true },
+ "requireSpacesInFunctionDeclaration": { "beforeOpeningCurlyBrace": true },
+ "disallowSpacesInFunctionDeclaration": { "beforeOpeningRoundBrace": true },
+
+ "disallowSpacesInsideParentheses": true,
+
+ "disallowSpacesInsideArrayBrackets": true,
+
+ "disallowQuotedKeysInObjects": "allButReserved",
+
+ "disallowSpaceAfterObjectKeys": true,
+
+ "disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"],
+ "requireSpaceAfterPrefixUnaryOperators": [],
+
+ "disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
+ "requireSpaceBeforePostfixUnaryOperators": [],
+
+ "disallowSpaceBeforeBinaryOperators": [],
+ "requireSpaceBeforeBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="],
+
+ "requireSpaceAfterBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="],
+ "disallowSpaceAfterBinaryOperators": [],
+
+ "disallowImplicitTypeConversion": ["binary", "string"],
+
+ "disallowKeywords": ["with", "eval"],
+
+ "validateLineBreaks": "LF",
+
+ "requireKeywordsOnNewLine": [],
+ "disallowKeywordsOnNewLine": ["else"],
+
+ "requireLineFeedAtFileEnd": true,
+
+ "disallowTrailingWhitespace": true,
+
+ "excludeFiles": ["node_modules/**", "vendor/**"],
+
+ "disallowMultipleLineStrings": true,
+
+ "additionalRules": []
+}
+
diff --git a/node_modules/reduce/.npmignore b/node_modules/reduce/.npmignore
new file mode 100644
index 00000000..062c11e8
--- /dev/null
+++ b/node_modules/reduce/.npmignore
@@ -0,0 +1,3 @@
+node_modules
+*.log
+*.err \ No newline at end of file
diff --git a/node_modules/reduce/.travis.yml b/node_modules/reduce/.travis.yml
new file mode 100644
index 00000000..912080aa
--- /dev/null
+++ b/node_modules/reduce/.travis.yml
@@ -0,0 +1,18 @@
+language: node_js
+node_js:
+ - "0.11"
+ - "0.10"
+ - "0.9"
+ - "0.8"
+ - "0.6"
+ - "0.4"
+before_install:
+ - '[ "${TRAVIS_NODE_VERSION}" == "0.6" ] || npm install -g npm@~1.4.6'
+matrix:
+ fast_finish: true
+ allow_failures:
+ - node_js: "0.11"
+ - node_js: "0.9"
+ - node_js: "0.6"
+ - node_js: "0.4"
+
diff --git a/node_modules/reduce/LICENCE b/node_modules/reduce/LICENCE
new file mode 100644
index 00000000..a23e08a8
--- /dev/null
+++ b/node_modules/reduce/LICENCE
@@ -0,0 +1,19 @@
+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. \ No newline at end of file
diff --git a/node_modules/reduce/README.md b/node_modules/reduce/README.md
new file mode 100644
index 00000000..89440075
--- /dev/null
+++ b/node_modules/reduce/README.md
@@ -0,0 +1,42 @@
+# reduce [![build status][1]][2]
+
+[![browser support][3]][4]
+
+## Example
+
+Like `Array.prototype.reduce` but works on Object and accepts optional
+`this` value
+
+``` js
+var reduce = require("reduce")
+
+reduce({
+ key: "value"
+ , key2: "value2"
+ , ...
+}, function (acc, value, key) {
+ /* real code */
+ acc[key] = value
+ return acc
+}, {
+ this: "context"
+}, {
+ initial: "value"
+})
+```
+
+## Installation
+
+`npm install reduce`
+
+## Contributors
+
+ - Raynos
+
+## MIT Licenced
+
+ [1]: https://secure.travis-ci.org/Raynos/reduce.svg
+ [2]: http://travis-ci.org/Raynos/reduce
+ [3]: https://ci.testling.com/Raynos/reduce.png
+ [4]: https://ci.testling.com/Raynos/reduce
+
diff --git a/node_modules/reduce/index.js b/node_modules/reduce/index.js
new file mode 100644
index 00000000..b090f1c1
--- /dev/null
+++ b/node_modules/reduce/index.js
@@ -0,0 +1,29 @@
+module.exports = reduce
+
+var objectKeys = require('object-keys');
+
+function reduce(list, iterator) {
+ var keys = objectKeys(list)
+ , i = 0
+ , accumulator = list[0]
+ , context = this
+
+ if (arguments.length === 2) {
+ i = 1
+ } else if (arguments.length === 3) {
+ accumulator = arguments[2]
+ } else if (arguments.length >= 4) {
+ context = arguments[2]
+ accumulator = arguments[3]
+ }
+
+ for (var len = keys.length; i < len; i++) {
+ var key = keys[i]
+ , value = list[key]
+
+ accumulator = iterator.call(context, accumulator, value, key, list)
+ }
+
+ return accumulator
+}
+
diff --git a/node_modules/reduce/package.json b/node_modules/reduce/package.json
new file mode 100644
index 00000000..0d7062c7
--- /dev/null
+++ b/node_modules/reduce/package.json
@@ -0,0 +1,56 @@
+{
+ "name": "reduce",
+ "version": "1.0.1",
+ "description": "A better [].reduce",
+ "keywords": [],
+ "author": "Raynos <raynos2@gmail.com>",
+ "repository": "git://github.com/Raynos/reduce.git",
+ "main": "index",
+ "homepage": "https://github.com/Raynos/reduce",
+ "contributors": [
+ {
+ "name": "Jake Verbaten"
+ }
+ ],
+ "bugs": {
+ "url": "https://github.com/Raynos/reduce/issues",
+ "email": "raynos2@gmail.com"
+ },
+ "dependencies": {
+ "object-keys": "~1.0.0"
+ },
+ "devDependencies": {
+ "tape": "~2.14.0",
+ "covert": "~1.0.0",
+ "jscs": "~1.5.9"
+ },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "http://github.com/Raynos/reduce/raw/master/LICENSE"
+ }
+ ],
+ "testling": {
+ "files": "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"
+ ]
+ },
+ "scripts": {
+ "test": "npm run lint && node test/simple.js && npm run coverage-quiet",
+ "coverage": "covert test/simple.js",
+ "coverage-quiet": "covert --quiet test/simple.js",
+ "lint": "jscs *.js test/*.js"
+ }
+}
diff --git a/node_modules/reduce/test/simple.js b/node_modules/reduce/test/simple.js
new file mode 100644
index 00000000..2c056ab7
--- /dev/null
+++ b/node_modules/reduce/test/simple.js
@@ -0,0 +1,94 @@
+var test = require("tape")
+ , reduce = require("..")
+
+test("reduce calls each iterator", function (t) {
+ var item = createItem()
+ , timesCalled = 0
+ , accumulator = { key: '' }
+ , expectedKeys = ['a', 'b', 'c']
+ , expectedValues = ['a1', 'b1', 'c1']
+ , expectedAccumulatorKeys = ['', 'a1', 'a1b1', 'a1b1c1']
+ , calledArguments = []
+ , slice = Array.prototype.slice
+ , iterator = function (acc, value, key, list) {
+ var expectedKey = expectedKeys[timesCalled]
+ , expectedValue = expectedValues[timesCalled]
+ , expectedAccumulatorKey = expectedAccumulatorKeys[timesCalled]
+
+ calledArguments.push(slice.apply(arguments))
+
+ t.equal(value, expectedValue, 'value ' + value + ' does not match ' + expectedValue)
+ t.equal(key, expectedKey, 'key ' + key + ' does not match ' + expectedKey)
+ t.equal(list, item, 'list arg is not correct')
+ t.equal(acc.key, expectedAccumulatorKey, 'accumulator key ' + acc.key + ' does not match ' + expectedAccumulatorKey)
+
+ timesCalled += 1
+ acc.key += value
+ return acc
+ }
+
+ var result = reduce(item, iterator, accumulator)
+
+ t.equal(timesCalled, 3, "iterator was not called thrice")
+ t.deepEqual(result, { key: 'a1b1c1' }, 'result is incorrect');
+
+ t.deepEqual(calledArguments[0], [{
+ key: "a1b1c1"
+ }, "a1", "a", item], "iterator called with wrong arguments")
+ t.deepEqual(calledArguments[1], [{
+ key: "a1b1c1"
+ }, "b1", "b", item], "iterator called with wrong arguments")
+ t.deepEqual(calledArguments[2], [{
+ key: "a1b1c1"
+ }, "c1", "c", item], "iterator called with wrong arguments")
+ t.deepEqual(result, {
+ key: "a1b1c1"
+ })
+
+ t.end()
+})
+
+test("reduce calls iterator with correct this value", function (t) {
+ var item = createItem()
+ , thisValue = {}
+ , iterator = function () {
+ t.equal(this, thisValue, 'this value is incorrect');
+ }
+
+ reduce(item, iterator, thisValue, {})
+
+ t.end()
+})
+
+test("reduce reduces with first value if no initialValue", function (t) {
+ var list = [1, 2]
+ , iterator = function (sum, v) {
+ return sum + v
+ }
+
+ var result = reduce(list, iterator)
+
+ t.equal(result, 3, "result is incorrect")
+
+ t.end()
+})
+
+test("reduce throws a TypeError when an invalid iterator is provided", function (t) {
+ t.throws(function () { reduce([1, 2]); }, TypeError, 'requires a function')
+
+ t.end()
+})
+
+test("reduce has a length of 2, mimicking spec", function (t) {
+ t.equal(reduce.length, 2, 'reduce has a length of 2')
+
+ t.end()
+})
+
+function createItem() {
+ return {
+ a: "a1"
+ , b: "b1"
+ , c: "c1"
+ }
+}