diff --git a/.eslintrc b/.eslintrc index 2627332f2..db0ec7835 100644 --- a/.eslintrc +++ b/.eslintrc @@ -9,6 +9,7 @@ "ecmaVersion": 8, "sourceType": "module" }, + "extends": "eslint:recommended", "rules": { "eqeqeq": 0, "guard-for-in": 2, @@ -19,6 +20,7 @@ "SwitchCase": 1 } ], + "no-console": 0, "no-caller": 2, "no-undef": 2, "no-unused-vars": 2, @@ -28,10 +30,14 @@ "last" ], "semi": 0, + "prefer-arrow-callback": 2, + "arrow-spacing": 2, + "object-shorthand": 2, "no-eq-null": 0, "no-unused-expressions": 0, "no-loop-func": 2, "dot-notation": 0, + "no-trailing-spaces": 2, "valid-jsdoc": ["error", { "requireReturn": false, "requireReturnDescription": false, diff --git a/Makefile b/Makefile index e8ff7aab5..86af46c0e 100644 --- a/Makefile +++ b/Makefile @@ -61,7 +61,7 @@ clean: rm -rf perf/versions/ lint: - eslint $(LINT_FILES) + eslint --fix $(LINT_FILES) # Compile the ES6 modules to singular bundles, and individual bundles build-bundle: build-modules $(UMD_BUNDLE) diff --git a/lib/apply.js b/lib/apply.js index 06f630a52..b822bc0c9 100644 --- a/lib/apply.js +++ b/lib/apply.js @@ -1,5 +1,3 @@ -import slice from './internal/slice'; - /** * Creates a continuation function with some arguments already applied. * @@ -45,10 +43,6 @@ import slice from './internal/slice'; * two * three */ -export default function(fn/*, ...args*/) { - var args = slice(arguments, 1); - return function(/*callArgs*/) { - var callArgs = slice(arguments); - return fn.apply(null, args.concat(callArgs)); - }; -}; +export default function(fn, ...args) { + return (...callArgs) => fn(...args,...callArgs); +} diff --git a/lib/asyncify.js b/lib/asyncify.js index e6d63c0ee..168f88a20 100644 --- a/lib/asyncify.js +++ b/lib/asyncify.js @@ -1,5 +1,6 @@ import initialParams from './internal/initialParams'; import setImmediate from './internal/setImmediate'; +import { isAsync } from './internal/wrapAsync' /** * Take a sync function and make it async, passing its return value to a @@ -58,6 +59,14 @@ import setImmediate from './internal/setImmediate'; * q.push(files); */ export default function asyncify(func) { + if (isAsync(func)) { + return function (...args/*, callback*/) { + const callback = args.pop() + const promise = func.apply(this, args) + return handlePromise(promise, callback) + } + } + return initialParams(function (args, callback) { var result; try { @@ -67,25 +76,25 @@ export default function asyncify(func) { } // if result is Promise object if (result && typeof result.then === 'function') { - result.then(function(value) { - invokeCallback(callback, null, value); - }, function(err) { - invokeCallback(callback, err.message ? err : new Error(err)); - }); + return handlePromise(result, callback) } else { callback(null, result); } }); } +function handlePromise(promise, callback) { + return promise.then(value => { + invokeCallback(callback, null, value); + }, err => { + invokeCallback(callback, err.message ? err : new Error(err)); + }); +} + function invokeCallback(callback, error, value) { try { callback(error, value); - } catch (e) { - setImmediate(rethrow, e); + } catch (err) { + setImmediate(e => { throw e }, err); } } - -function rethrow(error) { - throw error; -} diff --git a/lib/auto.js b/lib/auto.js index 500620a69..adfdfa103 100644 --- a/lib/auto.js +++ b/lib/auto.js @@ -1,7 +1,5 @@ import noop from './internal/noop'; -import forOwn from './internal/forOwn'; -import slice from './internal/slice'; import once from './internal/once'; import onlyOnce from './internal/onlyOnce'; import wrapAsync from './internal/wrapAsync'; @@ -114,7 +112,8 @@ export default function (tasks, concurrency, callback) { // without the possibility of returning to an ancestor task var uncheckedDependencies = {}; - forOwn(tasks, function (task, key) { + Object.keys(tasks).forEach(key => { + var task = tasks[key] if (!Array.isArray(task)) { // no dependencies enqueueTask(key, [task]); @@ -131,14 +130,14 @@ export default function (tasks, concurrency, callback) { } uncheckedDependencies[key] = remainingDependencies; - dependencies.forEach(function (dependencyName) { + dependencies.forEach(dependencyName => { if (!tasks[dependencyName]) { throw new Error('async.auto task `' + key + '` has a non-existent dependency `' + dependencyName + '` in ' + dependencies.join(', ')); } - addListener(dependencyName, function () { + addListener(dependencyName, () => { remainingDependencies--; if (remainingDependencies === 0) { enqueueTask(key, task); @@ -151,9 +150,7 @@ export default function (tasks, concurrency, callback) { processQueue(); function enqueueTask(key, task) { - readyTasks.push(function () { - runTask(key, task); - }); + readyTasks.push(() => runTask(key, task)); } function processQueue() { @@ -179,9 +176,7 @@ export default function (tasks, concurrency, callback) { function taskComplete(taskName) { var taskListeners = listeners[taskName] || []; - taskListeners.forEach(function (fn) { - fn(); - }); + taskListeners.forEach(fn => fn()); processQueue(); } @@ -189,19 +184,19 @@ export default function (tasks, concurrency, callback) { function runTask(key, task) { if (hasError) return; - var taskCallback = onlyOnce(function(err, result) { + var taskCallback = onlyOnce((err, ...result) => { runningTasks--; if (err === false) { canceled = true return } - if (arguments.length > 2) { - result = slice(arguments, 1); + if (result.length < 2) { + result = result[0]; } if (err) { var safeResults = {}; - forOwn(results, function(val, rkey) { - safeResults[rkey] = val; + Object.keys(results).forEach(rkey => { + safeResults[rkey] = results[rkey]; }); safeResults[key] = result; hasError = true; @@ -232,7 +227,7 @@ export default function (tasks, concurrency, callback) { while (readyToCheck.length) { currentTask = readyToCheck.pop(); counter++; - getDependents(currentTask).forEach(function (dependent) { + getDependents(currentTask).forEach(dependent => { if (--uncheckedDependencies[dependent] === 0) { readyToCheck.push(dependent); } @@ -248,7 +243,8 @@ export default function (tasks, concurrency, callback) { function getDependents(taskName) { var result = []; - forOwn(tasks, function (task, key) { + Object.keys(tasks).forEach(key => { + const task = tasks[key] if (Array.isArray(task) && task.indexOf(taskName) >= 0) { result.push(key); } diff --git a/lib/autoInject.js b/lib/autoInject.js index 65b2cfbdb..935c83536 100644 --- a/lib/autoInject.js +++ b/lib/autoInject.js @@ -1,9 +1,8 @@ import auto from './auto'; -import forOwn from './internal/forOwn'; import wrapAsync from './internal/wrapAsync'; import { isAsync } from './internal/wrapAsync'; -var FN_ARGS = /^(?:async\s+)?(function)?\s*[^\(]*\(\s*([^\)]*)\)/m; +var FN_ARGS = /^(?:async\s+)?(function)?\s*[^(]*\(\s*([^)]*)\)/m; var FN_ARG_SPLIT = /,/; var FN_ARG = /(=.+)?(\s*)$/; var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg; @@ -12,7 +11,7 @@ function parseParams(func) { func = func.toString().replace(STRIP_COMMENTS, ''); func = func.match(FN_ARGS)[2].replace(' ', ''); func = func ? func.split(FN_ARG_SPLIT) : []; - func = func.map(function (arg){ + func = func.map((arg) => { return arg.replace(FN_ARG, '').trim(); }); return func; @@ -103,7 +102,8 @@ function parseParams(func) { export default function autoInject(tasks, callback) { var newTasks = {}; - forOwn(tasks, function (taskFn, key) { + Object.keys(tasks).forEach(key => { + var taskFn = tasks[key] var params; var fnIsAsync = isAsync(taskFn); var hasNoDeps = @@ -111,8 +111,8 @@ export default function autoInject(tasks, callback) { (fnIsAsync && taskFn.length === 0); if (Array.isArray(taskFn)) { - params = taskFn.slice(0, -1); - taskFn = taskFn[taskFn.length - 1]; + params = [...taskFn]; + taskFn = params.pop(); newTasks[key] = params.concat(params.length > 0 ? newTask : taskFn); } else if (hasNoDeps) { @@ -131,11 +131,9 @@ export default function autoInject(tasks, callback) { } function newTask(results, taskCb) { - var newArgs = params.map(function (name) { - return results[name]; - }); + var newArgs = params.map(name => results[name]) newArgs.push(taskCb); - wrapAsync(taskFn).apply(null, newArgs); + wrapAsync(taskFn)(...newArgs); } }); diff --git a/lib/compose.js b/lib/compose.js index d9fa760d1..1706013b1 100644 --- a/lib/compose.js +++ b/lib/compose.js @@ -1,5 +1,4 @@ import seq from './seq'; -import slice from './internal/slice'; /** * Creates a function which is a composition of the passed asynchronous @@ -36,6 +35,6 @@ import slice from './internal/slice'; * // result now equals 15 * }); */ -export default function(/*...args*/) { - return seq.apply(null, slice(arguments).reverse()); -}; +export default function(...args) { + return seq(...args.reverse()); +} diff --git a/lib/concatLimit.js b/lib/concatLimit.js index cec4e2b11..e5c179aac 100644 --- a/lib/concatLimit.js +++ b/lib/concatLimit.js @@ -1,10 +1,7 @@ import noop from './internal/noop'; import wrapAsync from './internal/wrapAsync'; -import slice from './internal/slice'; import mapLimit from './mapLimit'; -var _concat = Array.prototype.concat; - /** * The same as [`concat`]{@link module:Collections.concat} but runs a maximum of `limit` async operations at a time. * @@ -26,16 +23,16 @@ var _concat = Array.prototype.concat; export default function(coll, limit, iteratee, callback) { callback = callback || noop; var _iteratee = wrapAsync(iteratee); - mapLimit(coll, limit, function(val, callback) { - _iteratee(val, function(err /*, ...args*/) { + mapLimit(coll, limit, (val, callback) => { + _iteratee(val, (err, ...args) => { if (err) return callback(err); - return callback(null, slice(arguments, 1)); + return callback(null, args); }); - }, function(err, mapResults) { + }, (err, mapResults) => { var result = []; for (var i = 0; i < mapResults.length; i++) { if (mapResults[i]) { - result = _concat.apply(result, mapResults[i]); + result = result.concat(...mapResults[i]); } } diff --git a/lib/constant.js b/lib/constant.js index 238ef6144..ed839e21a 100644 --- a/lib/constant.js +++ b/lib/constant.js @@ -1,5 +1,3 @@ -import slice from './internal/slice'; - /** * Returns a function that when called, calls-back with the values provided. * Useful as the first function in a [`waterfall`]{@link module:ControlFlow.waterfall}, or for plugging values in to @@ -42,11 +40,9 @@ import slice from './internal/slice'; * //... * }, callback); */ -export default function(/*...values*/) { - var values = slice(arguments); - var args = [null].concat(values); - return function (/*...ignoredArgs, callback*/) { - var callback = arguments[arguments.length - 1]; - return callback.apply(this, args); +export default function(...args) { + return function (...ignoredArgs/*, callback*/) { + var callback = ignoredArgs.pop(); + return callback(null, ...args); }; -}; +} diff --git a/lib/detect.js b/lib/detect.js index c37ff9179..1ea4eb498 100644 --- a/lib/detect.js +++ b/lib/detect.js @@ -1,7 +1,5 @@ -import identity from './internal/identity'; import createTester from './internal/createTester'; import doParallel from './internal/doParallel'; -import findGetResult from './internal/findGetResult'; /** * Returns the first value in `coll` that passes an async truth test. The @@ -38,4 +36,4 @@ import findGetResult from './internal/findGetResult'; * // result now equals the first file in the list that exists * }); */ -export default doParallel(createTester(identity, findGetResult)); +export default doParallel(createTester(bool => bool, (res, item) => item)); diff --git a/lib/detectLimit.js b/lib/detectLimit.js index 4efdd3a26..e9ff15880 100644 --- a/lib/detectLimit.js +++ b/lib/detectLimit.js @@ -1,7 +1,5 @@ -import identity from './internal/identity'; import createTester from './internal/createTester'; import doParallelLimit from './internal/doParallelLimit'; -import findGetResult from './internal/findGetResult'; /** * The same as [`detect`]{@link module:Collections.detect} but runs a maximum of `limit` async operations at a @@ -25,4 +23,4 @@ import findGetResult from './internal/findGetResult'; * (iteratee) or the value `undefined` if none passed. Invoked with * (err, result). */ -export default doParallelLimit(createTester(identity, findGetResult)); +export default doParallelLimit(createTester(bool => bool, (res, item) => item)); diff --git a/lib/doDuring.js b/lib/doDuring.js index 5eb2b9279..be078d579 100644 --- a/lib/doDuring.js +++ b/lib/doDuring.js @@ -1,5 +1,4 @@ import noop from './internal/noop'; -import slice from './internal/slice'; import onlyOnce from './internal/onlyOnce'; import wrapAsync from './internal/wrapAsync'; @@ -28,13 +27,11 @@ export default function doDuring(fn, test, callback) { var _fn = wrapAsync(fn); var _test = wrapAsync(test); - function next(err/*, ...args*/) { + function next(err, ...args) { if (err) return callback(err); if (err === false) return; - var args = slice(arguments, 1); - args.push(check); - _test.apply(this, args); - }; + _test(...args, check); + } function check(err, truth) { if (err) return callback(err); diff --git a/lib/doUntil.js b/lib/doUntil.js index 06d3af77f..aa7d323b2 100644 --- a/lib/doUntil.js +++ b/lib/doUntil.js @@ -21,7 +21,5 @@ import doWhilst from './doWhilst'; * callback. Invoked with (err, [results]); */ export default function doUntil(iteratee, test, callback) { - doWhilst(iteratee, function() { - return !test.apply(this, arguments); - }, callback); + doWhilst(iteratee, (...args) => !test(...args), callback); } diff --git a/lib/doWhilst.js b/lib/doWhilst.js index 524582081..324d2e087 100644 --- a/lib/doWhilst.js +++ b/lib/doWhilst.js @@ -1,5 +1,4 @@ import noop from './internal/noop'; -import slice from './internal/slice'; import onlyOnce from './internal/onlyOnce'; import wrapAsync from './internal/wrapAsync'; @@ -29,12 +28,11 @@ import wrapAsync from './internal/wrapAsync'; export default function doWhilst(iteratee, test, callback) { callback = onlyOnce(callback || noop); var _iteratee = wrapAsync(iteratee); - var next = function(err/*, ...args*/) { + function next (err, ...args) { if (err) return callback(err); if (err === false) return; - var args = slice(arguments, 1); - if (test.apply(this, args)) return _iteratee(next); - callback.apply(null, [null].concat(args)); - }; + if (test(...args)) return _iteratee(next); + callback(null, ...args); + } _iteratee(next); } diff --git a/lib/ensureAsync.js b/lib/ensureAsync.js index a579efca6..b2b35b94f 100644 --- a/lib/ensureAsync.js +++ b/lib/ensureAsync.js @@ -1,5 +1,4 @@ import setImmediate from './internal/setImmediate'; -import initialParams from './internal/initialParams'; import { isAsync } from './internal/wrapAsync'; /** @@ -39,19 +38,17 @@ import { isAsync } from './internal/wrapAsync'; */ export default function ensureAsync(fn) { if (isAsync(fn)) return fn; - return initialParams(function (args, callback) { + return function (...args/*, callback*/) { + var callback = args.pop() var sync = true; - args.push(function () { - var innerArgs = arguments; + args.push((...innerArgs) => { if (sync) { - setImmediate(function () { - callback.apply(null, innerArgs); - }); + setImmediate(() => callback(...innerArgs)); } else { - callback.apply(null, innerArgs); + callback(...innerArgs); } }); fn.apply(this, args); sync = false; - }); + }; } diff --git a/lib/every.js b/lib/every.js index eb1074807..ed00f7219 100644 --- a/lib/every.js +++ b/lib/every.js @@ -1,6 +1,5 @@ import createTester from './internal/createTester'; import doParallel from './internal/doParallel'; -import notId from './internal/notId'; /** * Returns `true` if every element in `coll` satisfies an async test. If any @@ -30,4 +29,4 @@ import notId from './internal/notId'; * // if result is true then every file exists * }); */ -export default doParallel(createTester(notId, notId)); +export default doParallel(createTester(bool => !bool, res => !res)); diff --git a/lib/everyLimit.js b/lib/everyLimit.js index 89a69fc01..536229a9a 100644 --- a/lib/everyLimit.js +++ b/lib/everyLimit.js @@ -1,6 +1,5 @@ import createTester from './internal/createTester'; import doParallelLimit from './internal/doParallelLimit'; -import notId from './internal/notId'; /** * The same as [`every`]{@link module:Collections.every} but runs a maximum of `limit` async operations at a time. @@ -22,4 +21,4 @@ import notId from './internal/notId'; * `iteratee` functions have finished. Result will be either `true` or `false` * depending on the values of the async tests. Invoked with (err, result). */ -export default doParallelLimit(createTester(notId, notId)); +export default doParallelLimit(createTester(bool => !bool, res => !res)); diff --git a/lib/groupByLimit.js b/lib/groupByLimit.js index e6bbf8ee1..fe484ec73 100644 --- a/lib/groupByLimit.js +++ b/lib/groupByLimit.js @@ -23,12 +23,12 @@ import wrapAsync from './internal/wrapAsync'; export default function(coll, limit, iteratee, callback) { callback = callback || noop; var _iteratee = wrapAsync(iteratee); - mapLimit(coll, limit, function(val, callback) { - _iteratee(val, function(err, key) { + mapLimit(coll, limit, (val, callback) => { + _iteratee(val, (err, key) => { if (err) return callback(err); - return callback(null, {key: key, val: val}); + return callback(null, {key, val}); }); - }, function(err, mapResults) { + }, (err, mapResults) => { var result = {}; // from MDN, handle object having an `hasOwnProperty` prop var hasOwnProperty = Object.prototype.hasOwnProperty; @@ -48,4 +48,4 @@ export default function(coll, limit, iteratee, callback) { return callback(err, result); }); -}; +} diff --git a/lib/index.js b/lib/index.js index 06691523f..0eee7bda8 100644 --- a/lib/index.js +++ b/lib/index.js @@ -142,83 +142,83 @@ import waterfall from './waterfall' import whilst from './whilst' export default { - apply: apply, - applyEach: applyEach, - applyEachSeries: applyEachSeries, - asyncify: asyncify, - auto: auto, - autoInject: autoInject, - cargo: cargo, - compose: compose, - concat: concat, - concatLimit: concatLimit, - concatSeries: concatSeries, - constant: constant, - detect: detect, - detectLimit: detectLimit, - detectSeries: detectSeries, - dir: dir, - doDuring: doDuring, - doUntil: doUntil, - doWhilst: doWhilst, - during: during, - each: each, - eachLimit: eachLimit, - eachOf: eachOf, - eachOfLimit: eachOfLimit, - eachOfSeries: eachOfSeries, - eachSeries: eachSeries, - ensureAsync: ensureAsync, - every: every, - everyLimit: everyLimit, - everySeries: everySeries, - filter: filter, - filterLimit: filterLimit, - filterSeries: filterSeries, - forever: forever, - groupBy: groupBy, - groupByLimit: groupByLimit, - groupBySeries: groupBySeries, - log: log, - map: map, - mapLimit: mapLimit, - mapSeries: mapSeries, - mapValues: mapValues, - mapValuesLimit: mapValuesLimit, - mapValuesSeries: mapValuesSeries, - memoize: memoize, - nextTick: nextTick, - parallel: parallel, - parallelLimit: parallelLimit, - priorityQueue: priorityQueue, - queue: queue, - race: race, - reduce: reduce, - reduceRight: reduceRight, - reflect: reflect, - reflectAll: reflectAll, - reject: reject, - rejectLimit: rejectLimit, - rejectSeries: rejectSeries, - retry: retry, - retryable: retryable, - seq: seq, - series: series, - setImmediate: setImmediate, - some: some, - someLimit: someLimit, - someSeries: someSeries, - sortBy: sortBy, - timeout: timeout, - times: times, - timesLimit: timesLimit, - timesSeries: timesSeries, - transform: transform, - tryEach: tryEach, - unmemoize: unmemoize, - until: until, - waterfall: waterfall, - whilst: whilst, + apply, + applyEach, + applyEachSeries, + asyncify, + auto, + autoInject, + cargo, + compose, + concat, + concatLimit, + concatSeries, + constant, + detect, + detectLimit, + detectSeries, + dir, + doDuring, + doUntil, + doWhilst, + during, + each, + eachLimit, + eachOf, + eachOfLimit, + eachOfSeries, + eachSeries, + ensureAsync, + every, + everyLimit, + everySeries, + filter, + filterLimit, + filterSeries, + forever, + groupBy, + groupByLimit, + groupBySeries, + log, + map, + mapLimit, + mapSeries, + mapValues, + mapValuesLimit, + mapValuesSeries, + memoize, + nextTick, + parallel, + parallelLimit, + priorityQueue, + queue, + race, + reduce, + reduceRight, + reflect, + reflectAll, + reject, + rejectLimit, + rejectSeries, + retry, + retryable, + seq, + series, + setImmediate, + some, + someLimit, + someSeries, + sortBy, + timeout, + times, + timesLimit, + timesSeries, + transform, + tryEach, + unmemoize, + until, + waterfall, + whilst, // aliases all: every, diff --git a/lib/internal/DoublyLinkedList.js b/lib/internal/DoublyLinkedList.js index 86c5cfd31..259ac0d0a 100644 --- a/lib/internal/DoublyLinkedList.js +++ b/lib/internal/DoublyLinkedList.js @@ -2,86 +2,89 @@ // used for queues. This implementation assumes that the node provided by the user can be modified // to adjust the next and last properties. We implement only the minimal functionality // for queue support. -export default function DLL() { - this.head = this.tail = null; - this.length = 0; -} - -function setInitial(dll, node) { - dll.length = 1; - dll.head = dll.tail = node; -} +export default class DLL { + constructor() { + this.head = this.tail = null; + this.length = 0; + } -DLL.prototype.removeLink = function(node) { - if (node.prev) node.prev.next = node.next; - else this.head = node.next - if (node.next) node.next.prev = node.prev; - else this.tail = node.prev; + removeLink(node) { + if (node.prev) node.prev.next = node.next; + else this.head = node.next + if (node.next) node.next.prev = node.prev; + else this.tail = node.prev; - node.prev = node.next = null; - this.length -= 1; - return node; -} + node.prev = node.next = null; + this.length -= 1; + return node; + } -DLL.prototype.empty = function () { - while(this.head) this.shift(); - return this; -}; + empty () { + while(this.head) this.shift(); + return this; + } -DLL.prototype.insertAfter = function(node, newNode) { - newNode.prev = node; - newNode.next = node.next; - if (node.next) node.next.prev = newNode; - else this.tail = newNode; - node.next = newNode; - this.length += 1; -} + insertAfter(node, newNode) { + newNode.prev = node; + newNode.next = node.next; + if (node.next) node.next.prev = newNode; + else this.tail = newNode; + node.next = newNode; + this.length += 1; + } -DLL.prototype.insertBefore = function(node, newNode) { - newNode.prev = node.prev; - newNode.next = node; - if (node.prev) node.prev.next = newNode; - else this.head = newNode; - node.prev = newNode; - this.length += 1; -} + insertBefore(node, newNode) { + newNode.prev = node.prev; + newNode.next = node; + if (node.prev) node.prev.next = newNode; + else this.head = newNode; + node.prev = newNode; + this.length += 1; + } -DLL.prototype.unshift = function(node) { - if (this.head) this.insertBefore(this.head, node); - else setInitial(this, node); -}; + unshift(node) { + if (this.head) this.insertBefore(this.head, node); + else setInitial(this, node); + } -DLL.prototype.push = function(node) { - if (this.tail) this.insertAfter(this.tail, node); - else setInitial(this, node); -}; + push(node) { + if (this.tail) this.insertAfter(this.tail, node); + else setInitial(this, node); + } -DLL.prototype.shift = function() { - return this.head && this.removeLink(this.head); -}; + shift() { + return this.head && this.removeLink(this.head); + } -DLL.prototype.pop = function() { - return this.tail && this.removeLink(this.tail); -}; + pop() { + return this.tail && this.removeLink(this.tail); + } -DLL.prototype.toArray = function () { - var arr = Array(this.length); - var curr = this.head; - for(var idx = 0; idx < this.length; idx++) { - arr[idx] = curr.data; - curr = curr.next; + toArray () { + var arr = Array(this.length); + var curr = this.head; + for(var idx = 0; idx < this.length; idx++) { + arr[idx] = curr.data; + curr = curr.next; + } + return arr; } - return arr; -} -DLL.prototype.remove = function (testFn) { - var curr = this.head; - while(!!curr) { - var next = curr.next; - if (testFn(curr)) { - this.removeLink(curr); + remove (testFn) { + var curr = this.head; + while(curr) { + var next = curr.next; + if (testFn(curr)) { + this.removeLink(curr); + } + curr = next; } - curr = next; + return this; } - return this; } + +function setInitial(dll, node) { + dll.length = 1; + dll.head = dll.tail = node; +} + diff --git a/lib/internal/applyEach.js b/lib/internal/applyEach.js index c0ed402f9..b02918459 100644 --- a/lib/internal/applyEach.js +++ b/lib/internal/applyEach.js @@ -1,13 +1,11 @@ -import slice from './slice'; import initialParams from './initialParams'; import wrapAsync from './wrapAsync'; export default function applyEach(eachfn) { - return function(fns/*, ...args*/) { - var args = slice(arguments, 1); + return function(fns, ...args) { var go = initialParams(function(args, callback) { var that = this; - return eachfn(fns, function (fn, cb) { + return eachfn(fns, (fn, cb) => { wrapAsync(fn).apply(that, args.concat(cb)); }, callback); }); diff --git a/lib/internal/consoleFunc.js b/lib/internal/consoleFunc.js index c9776477a..d2c1cb1fe 100644 --- a/lib/internal/consoleFunc.js +++ b/lib/internal/consoleFunc.js @@ -1,23 +1,15 @@ -import slice from './slice'; import wrapAsync from './wrapAsync'; export default function consoleFunc(name) { - return function (fn/*, ...args*/) { - var args = slice(arguments, 1); - args.push(function (err/*, ...args*/) { - var args = slice(arguments, 1); - if (typeof console === 'object') { - if (err) { - if (console.error) { - console.error(err); - } - } else if (console[name]) { - args.forEach(function (x) { - console[name](x); - }); + return (fn, ...args) => wrapAsync(fn)(...args, (err, ...resultArgs) => { + if (typeof console === 'object') { + if (err) { + if (console.error) { + console.error(err); } + } else if (console[name]) { + resultArgs.forEach(x => console[name](x)); } - }) - wrapAsync(fn).apply(null, args); - }; + } + }) } diff --git a/lib/internal/createTester.js b/lib/internal/createTester.js index 87868332c..4a5d39fcc 100644 --- a/lib/internal/createTester.js +++ b/lib/internal/createTester.js @@ -2,28 +2,24 @@ import noop from './noop'; import breakLoop from './breakLoop'; export default function _createTester(check, getResult) { - return function(eachfn, arr, iteratee, cb) { + return (eachfn, arr, iteratee, cb) => { cb = cb || noop; var testPassed = false; var testResult; - eachfn(arr, function(value, _, callback) { - iteratee(value, function(err, result) { - if (err) { - callback(err); - } else if (check(result) && !testResult) { + eachfn(arr, (value, _, callback) => { + iteratee(value, (err, result) => { + if (err) return callback(err) + + if (check(result) && !testResult) { testPassed = true; testResult = getResult(true, value); - callback(null, breakLoop); - } else { - callback(); + return callback(null, breakLoop); } + callback(); }); - }, function(err) { - if (err) { - cb(err); - } else { - cb(null, testPassed ? testResult : getResult(false)); - } + }, err => { + if (err) return cb(err); + cb(null, testPassed ? testResult : getResult(false)); }); }; } diff --git a/lib/internal/doLimit.js b/lib/internal/doLimit.js index 7d2f1117a..70fb495d5 100644 --- a/lib/internal/doLimit.js +++ b/lib/internal/doLimit.js @@ -1,5 +1,3 @@ export default function doLimit(fn, limit) { - return function (iterable, iteratee, callback) { - return fn(iterable, limit, iteratee, callback); - }; + return (iterable, iteratee, cb) => fn(iterable, limit, iteratee, cb) } diff --git a/lib/internal/doParallel.js b/lib/internal/doParallel.js index deed91208..2b76b6837 100644 --- a/lib/internal/doParallel.js +++ b/lib/internal/doParallel.js @@ -2,7 +2,5 @@ import eachOf from '../eachOf'; import wrapAsync from './wrapAsync'; export default function doParallel(fn) { - return function (obj, iteratee, callback) { - return fn(eachOf, obj, wrapAsync(iteratee), callback); - }; + return (obj, iteratee, cb) => fn(eachOf, obj, wrapAsync(iteratee), cb); } diff --git a/lib/internal/doParallelLimit.js b/lib/internal/doParallelLimit.js index 6d0f60741..5e2703ae6 100644 --- a/lib/internal/doParallelLimit.js +++ b/lib/internal/doParallelLimit.js @@ -2,7 +2,5 @@ import eachOfLimit from './eachOfLimit'; import wrapAsync from './wrapAsync'; export default function doParallelLimit(fn) { - return function (obj, limit, iteratee, callback) { - return fn(eachOfLimit(limit), obj, wrapAsync(iteratee), callback); - }; + return (obj, limit, iteratee, cb) => fn(eachOfLimit(limit), obj, wrapAsync(iteratee), cb); } diff --git a/lib/internal/eachOfLimit.js b/lib/internal/eachOfLimit.js index 2928366dc..1d710dc34 100644 --- a/lib/internal/eachOfLimit.js +++ b/lib/internal/eachOfLimit.js @@ -6,8 +6,8 @@ import onlyOnce from './onlyOnce'; import breakLoop from './breakLoop'; -export default function _eachOfLimit(limit) { - return function (obj, iteratee, callback) { +export default (limit) => { + return (obj, iteratee, callback) => { callback = once(callback || noop); if (limit <= 0) { throw new RangeError('concurrency limit cannot be less than 1') diff --git a/lib/internal/filter.js b/lib/internal/filter.js index 192326475..4c9422bb1 100644 --- a/lib/internal/filter.js +++ b/lib/internal/filter.js @@ -1,17 +1,16 @@ import isArrayLike from './isArrayLike'; -import property from './property'; import noop from './noop'; import wrapAsync from './wrapAsync'; function filterArray(eachfn, arr, iteratee, callback) { var truthValues = new Array(arr.length); - eachfn(arr, function (x, index, callback) { - iteratee(x, function (err, v) { + eachfn(arr, (x, index, callback) => { + iteratee(x, (err, v) => { truthValues[index] = !!v; callback(err); }); - }, function (err) { + }, err => { if (err) return callback(err); var results = []; for (var i = 0; i < arr.length; i++) { @@ -23,29 +22,26 @@ function filterArray(eachfn, arr, iteratee, callback) { function filterGeneric(eachfn, coll, iteratee, callback) { var results = []; - eachfn(coll, function (x, index, callback) { - iteratee(x, function (err, v) { + eachfn(coll, (x, index, callback) => { + iteratee(x, (err, v) => { if (err) { callback(err); } else { if (v) { - results.push({index: index, value: x}); + results.push({index, value: x}); } callback(); } }); - }, function (err) { - if (err) { - callback(err); - } else { - callback(null, results.sort(function (a, b) { - return a.index - b.index; - }).map(property('value'))); - } + }, err => { + if (err) return callback(err); + callback(null, results + .sort((a, b) => a.index - b.index) + .map(v => v.value)); }); } export default function _filter(eachfn, coll, iteratee, callback) { var filter = isArrayLike(coll) ? filterArray : filterGeneric; - filter(eachfn, coll, wrapAsync(iteratee), callback || noop); + return filter(eachfn, coll, wrapAsync(iteratee), callback || noop); } diff --git a/lib/internal/findGetResult.js b/lib/internal/findGetResult.js deleted file mode 100644 index 7345df620..000000000 --- a/lib/internal/findGetResult.js +++ /dev/null @@ -1,3 +0,0 @@ -export default function _findGetResult(v, x) { - return x; -} diff --git a/lib/internal/forOwn.js b/lib/internal/forOwn.js deleted file mode 100644 index ea165197b..000000000 --- a/lib/internal/forOwn.js +++ /dev/null @@ -1,8 +0,0 @@ -export default function forOwn(object, callback) { - if (!object) { - return; - } - Object.keys(object).forEach(function (key) { - callback(object[key], key); - }); -} diff --git a/lib/internal/getIterator.js b/lib/internal/getIterator.js index 87860f48d..99a571886 100644 --- a/lib/internal/getIterator.js +++ b/lib/internal/getIterator.js @@ -1,5 +1,3 @@ -var iteratorSymbol = typeof Symbol === 'function' && Symbol.iterator; - export default function (coll) { - return iteratorSymbol && coll[iteratorSymbol] && coll[iteratorSymbol](); + return coll[Symbol.iterator] && coll[Symbol.iterator](); } diff --git a/lib/internal/identity.js b/lib/internal/identity.js deleted file mode 100644 index 7e6669d0b..000000000 --- a/lib/internal/identity.js +++ /dev/null @@ -1,3 +0,0 @@ -export default function identity(value) { - return value; -} diff --git a/lib/internal/initialParams.js b/lib/internal/initialParams.js index 207970302..4014785d3 100644 --- a/lib/internal/initialParams.js +++ b/lib/internal/initialParams.js @@ -1,8 +1,5 @@ -import slice from './slice'; - export default function (fn) { - return function (/*...args, callback*/) { - var args = slice(arguments); + return function (...args/*, callback*/) { var callback = args.pop(); fn.call(this, args, callback); }; diff --git a/lib/internal/iterator.js b/lib/internal/iterator.js index 65551878f..b0c464487 100644 --- a/lib/internal/iterator.js +++ b/lib/internal/iterator.js @@ -26,7 +26,7 @@ function createObjectIterator(obj) { var len = okeys.length; return function next() { var key = okeys[++i]; - return i < len ? {value: obj[key], key: key} : null; + return i < len ? {value: obj[key], key} : null; }; } diff --git a/lib/internal/map.js b/lib/internal/map.js index c7f64dd7e..b99d8ee16 100644 --- a/lib/internal/map.js +++ b/lib/internal/map.js @@ -8,13 +8,13 @@ export default function _asyncMap(eachfn, arr, iteratee, callback) { var counter = 0; var _iteratee = wrapAsync(iteratee); - eachfn(arr, function (value, _, callback) { + return eachfn(arr, (value, _, callback) => { var index = counter++; - _iteratee(value, function (err, v) { + _iteratee(value, (err, v) => { results[index] = v; callback(err); }); - }, function (err) { + }, err => { callback(err, results); }); } diff --git a/lib/internal/notId.js b/lib/internal/notId.js deleted file mode 100644 index 65a676e13..000000000 --- a/lib/internal/notId.js +++ /dev/null @@ -1,3 +0,0 @@ -export default function notId(v) { - return !v; -} diff --git a/lib/internal/once.js b/lib/internal/once.js index f601185b9..1293d5e6b 100644 --- a/lib/internal/once.js +++ b/lib/internal/once.js @@ -1,8 +1,8 @@ export default function once(fn) { - return function () { + return function (...args) { if (fn === null) return; var callFn = fn; fn = null; - callFn.apply(this, arguments); + callFn.apply(this, args); }; } diff --git a/lib/internal/onlyOnce.js b/lib/internal/onlyOnce.js index bb1979ab2..07664a451 100644 --- a/lib/internal/onlyOnce.js +++ b/lib/internal/onlyOnce.js @@ -1,8 +1,8 @@ export default function onlyOnce(fn) { - return function() { + return function (...args) { if (fn === null) throw new Error("Callback was already called."); var callFn = fn; fn = null; - callFn.apply(this, arguments); + callFn.apply(this, args); }; } diff --git a/lib/internal/parallel.js b/lib/internal/parallel.js index bbfdb423c..89e181ec6 100644 --- a/lib/internal/parallel.js +++ b/lib/internal/parallel.js @@ -1,21 +1,18 @@ import isArrayLike from './isArrayLike'; import noop from './noop'; -import slice from './slice'; import wrapAsync from './wrapAsync'; export default function _parallel(eachfn, tasks, callback) { callback = callback || noop; var results = isArrayLike(tasks) ? [] : {}; - eachfn(tasks, function (task, key, callback) { - wrapAsync(task)(function (err, result) { - if (arguments.length > 2) { - result = slice(arguments, 1); + eachfn(tasks, (task, key, callback) => { + wrapAsync(task)((err, ...result) => { + if (result.length < 2) { + result = result[0]; } results[key] = result; callback(err); }); - }, function (err) { - callback(err, results); - }); + }, err => callback(err, results)); } diff --git a/lib/internal/property.js b/lib/internal/property.js deleted file mode 100644 index 567b3c3d2..000000000 --- a/lib/internal/property.js +++ /dev/null @@ -1,5 +0,0 @@ -export default function property(property) { - return function (object) { - return object[property]; - } -} diff --git a/lib/internal/queue.js b/lib/internal/queue.js index a421d2e29..a811080eb 100644 --- a/lib/internal/queue.js +++ b/lib/internal/queue.js @@ -27,9 +27,7 @@ export default function queue(worker, concurrency, payload) { } if (data.length === 0 && q.idle()) { // call drain immediately if there are no tasks - return setImmediate(function() { - q.drain(); - }); + return setImmediate(() => q.drain()); } for (var i = 0, l = data.length; i < l; i++) { @@ -47,7 +45,7 @@ export default function queue(worker, concurrency, payload) { if (!processingScheduled) { processingScheduled = true; - setImmediate(function() { + setImmediate(() => { processingScheduled = false; q.process(); }); @@ -55,7 +53,7 @@ export default function queue(worker, concurrency, payload) { } function _next(tasks) { - return function(err){ + return function (err, ...args) { numRunning -= 1; for (var i = 0, l = tasks.length; i < l; i++) { @@ -68,7 +66,7 @@ export default function queue(worker, concurrency, payload) { workersList.splice(index, 1); } - task.callback.apply(task, arguments); + task.callback(err, ...args); if (err != null) { q.error(err, task.data); @@ -89,8 +87,8 @@ export default function queue(worker, concurrency, payload) { var isProcessing = false; var q = { _tasks: new DLL(), - concurrency: concurrency, - payload: payload, + concurrency, + payload, saturated: noop, unsaturated:noop, buffer: concurrency / 4, @@ -99,20 +97,20 @@ export default function queue(worker, concurrency, payload) { error: noop, started: false, paused: false, - push: function (data, callback) { + push (data, callback) { _insert(data, false, callback); }, - kill: function () { + kill () { q.drain = noop; q._tasks.empty(); }, - unshift: function (data, callback) { + unshift (data, callback) { _insert(data, true, callback); }, - remove: function (testFn) { + remove (testFn) { q._tasks.remove(testFn); }, - process: function () { + process () { // Avoid trying to start too many processing operations. This can occur // when callbacks resolve synchronously (#1267). if (isProcessing) { @@ -145,22 +143,22 @@ export default function queue(worker, concurrency, payload) { } isProcessing = false; }, - length: function () { + length () { return q._tasks.length; }, - running: function () { + running () { return numRunning; }, - workersList: function () { + workersList () { return workersList; }, - idle: function() { + idle() { return q._tasks.length + numRunning === 0; }, - pause: function () { + pause () { q.paused = true; }, - resume: function () { + resume () { if (q.paused === false) { return; } q.paused = false; setImmediate(q.process); diff --git a/lib/internal/reject.js b/lib/internal/reject.js index e082328b1..15226329f 100644 --- a/lib/internal/reject.js +++ b/lib/internal/reject.js @@ -1,8 +1,8 @@ import filter from './filter'; export default function reject(eachfn, arr, iteratee, callback) { - filter(eachfn, arr, function(value, cb) { - iteratee(value, function(err, v) { + return filter(eachfn, arr, (value, cb) => { + iteratee(value, (err, v) => { cb(err, !v); }); }, callback); diff --git a/lib/internal/setImmediate.js b/lib/internal/setImmediate.js index 95191f904..e14e52e3a 100644 --- a/lib/internal/setImmediate.js +++ b/lib/internal/setImmediate.js @@ -1,7 +1,5 @@ 'use strict'; -import slice from './slice'; - export var hasSetImmediate = typeof setImmediate === 'function' && setImmediate; export var hasNextTick = typeof process === 'object' && typeof process.nextTick === 'function'; @@ -10,12 +8,7 @@ export function fallback(fn) { } export function wrap(defer) { - return function (fn/*, ...args*/) { - var args = slice(arguments, 1); - defer(function () { - fn.apply(null, args); - }); - }; + return (fn, ...args) => defer(() => fn(...args)); } var _defer; diff --git a/lib/internal/slice.js b/lib/internal/slice.js deleted file mode 100644 index cd2e5b38f..000000000 --- a/lib/internal/slice.js +++ /dev/null @@ -1,9 +0,0 @@ -export default function slice(arrayLike, start) { - start = start|0; - var newLen = Math.max(arrayLike.length - start, 0); - var newArr = Array(newLen); - for(var idx = 0; idx < newLen; idx++) { - newArr[idx] = arrayLike[start + idx]; - } - return newArr; -} diff --git a/lib/internal/withoutIndex.js b/lib/internal/withoutIndex.js index 2d70dd4a8..4de0f31db 100644 --- a/lib/internal/withoutIndex.js +++ b/lib/internal/withoutIndex.js @@ -1,5 +1,3 @@ export default function _withoutIndex(iteratee) { - return function (value, index, callback) { - return iteratee(value, callback); - }; + return (value, index, callback) => iteratee(value, callback); } diff --git a/lib/internal/wrapAsync.js b/lib/internal/wrapAsync.js index c4d1ea830..2b1490c57 100644 --- a/lib/internal/wrapAsync.js +++ b/lib/internal/wrapAsync.js @@ -1,9 +1,7 @@ import asyncify from '../asyncify'; -var supportsSymbol = typeof Symbol === 'function'; - function isAsync(fn) { - return supportsSymbol && fn[Symbol.toStringTag] === 'AsyncFunction'; + return fn[Symbol.toStringTag] === 'AsyncFunction'; } function wrapAsync(asyncFn) { diff --git a/lib/mapValuesLimit.js b/lib/mapValuesLimit.js index 47e6072b0..2267aafd7 100644 --- a/lib/mapValuesLimit.js +++ b/lib/mapValuesLimit.js @@ -29,13 +29,11 @@ export default function mapValuesLimit(obj, limit, iteratee, callback) { callback = once(callback || noop); var newObj = {}; var _iteratee = wrapAsync(iteratee) - eachOfLimit(obj, limit, function(val, key, next) { - _iteratee(val, key, function (err, result) { + eachOfLimit(obj, limit, (val, key, next) => { + _iteratee(val, key, (err, result) => { if (err) return next(err); newObj[key] = result; next(); }); - }, function (err) { - callback(err, newObj); - }); + }, err => callback(err, newObj)); } diff --git a/lib/memoize.js b/lib/memoize.js index ea0da437b..d8001069e 100644 --- a/lib/memoize.js +++ b/lib/memoize.js @@ -1,13 +1,7 @@ -import identity from './internal/identity'; -import slice from './internal/slice'; import setImmediate from './internal/setImmediate'; import initialParams from './internal/initialParams'; import wrapAsync from './internal/wrapAsync'; -function has(obj, key) { - return key in obj; -} - /** * Caches the results of an async function. When creating a hash to store * function results against, the callback is omitted from the hash and an @@ -48,34 +42,29 @@ function has(obj, key) { * // callback * }); */ -export default function memoize(fn, hasher) { +export default function memoize(fn, hasher = v => v) { var memo = Object.create(null); var queues = Object.create(null); - hasher = hasher || identity; var _fn = wrapAsync(fn); - var memoized = initialParams(function memoized(args, callback) { - var key = hasher.apply(null, args); - if (has(memo, key)) { - setImmediate(function() { - callback.apply(null, memo[key]); - }); - } else if (has(queues, key)) { + var memoized = initialParams((args, callback) => { + var key = hasher(...args); + if (key in memo) { + setImmediate(() => callback(null, ...memo[key])); + } else if (key in queues) { queues[key].push(callback); } else { queues[key] = [callback]; - _fn.apply(null, args.concat(function(/*args*/) { - var args = slice(arguments); - var err = args[0]; + _fn(...args, (err, ...resultArgs) => { // #1465 don't memoize if an error occurred if (!err) { - memo[key] = args; + memo[key] = resultArgs; } var q = queues[key]; delete queues[key]; for (var i = 0, l = q.length; i < l; i++) { - q[i].apply(null, args); + q[i](err, ...resultArgs); } - })); + }); } }); memoized.memo = memo; diff --git a/lib/priorityQueue.js b/lib/priorityQueue.js index b7f7507bc..aa9b578c9 100644 --- a/lib/priorityQueue.js +++ b/lib/priorityQueue.js @@ -43,9 +43,7 @@ export default function(worker, concurrency) { } if (data.length === 0) { // call drain immediately if there are no tasks - return setImmediate(function() { - q.drain(); - }); + return setImmediate(() => q.drain()); } priority = priority || 0; @@ -57,8 +55,8 @@ export default function(worker, concurrency) { for (var i = 0, l = data.length; i < l; i++) { var item = { data: data[i], - priority: priority, - callback: callback + priority, + callback }; if (nextNode) { diff --git a/lib/queue.js b/lib/queue.js index 7a201c44e..00b90cee9 100644 --- a/lib/queue.js +++ b/lib/queue.js @@ -113,7 +113,7 @@ import wrapAsync from './internal/wrapAsync'; */ export default function (worker, concurrency) { var _worker = wrapAsync(worker); - return queue(function (items, cb) { + return queue((items, cb) => { _worker(items[0], cb); }, concurrency, 1); } diff --git a/lib/reduce.js b/lib/reduce.js index de42c5eb3..963d6192c 100644 --- a/lib/reduce.js +++ b/lib/reduce.js @@ -46,12 +46,10 @@ import wrapAsync from './internal/wrapAsync'; export default function reduce(coll, memo, iteratee, callback) { callback = once(callback || noop); var _iteratee = wrapAsync(iteratee); - eachOfSeries(coll, function(x, i, callback) { - _iteratee(memo, x, function(err, v) { + eachOfSeries(coll, (x, i, callback) => { + _iteratee(memo, x, (err, v) => { memo = v; callback(err); }); - }, function(err) { - callback(err, memo); - }); + }, err => callback(err, memo)); } diff --git a/lib/reduceRight.js b/lib/reduceRight.js index 1d203c993..dd56a88e3 100644 --- a/lib/reduceRight.js +++ b/lib/reduceRight.js @@ -1,5 +1,4 @@ import reduce from './reduce'; -import slice from './internal/slice'; /** * Same as [`reduce`]{@link module:Collections.reduce}, only operates on `array` in reverse order. @@ -24,6 +23,6 @@ import slice from './internal/slice'; * (err, result). */ export default function reduceRight (array, memo, iteratee, callback) { - var reversed = slice(array).reverse(); + var reversed = [...array].reverse(); reduce(reversed, memo, iteratee, callback); } diff --git a/lib/reflect.js b/lib/reflect.js index f50d81769..b1cbdc601 100644 --- a/lib/reflect.js +++ b/lib/reflect.js @@ -1,5 +1,4 @@ import initialParams from './internal/initialParams'; -import slice from './internal/slice'; import wrapAsync from './internal/wrapAsync'; /** @@ -44,18 +43,15 @@ import wrapAsync from './internal/wrapAsync'; export default function reflect(fn) { var _fn = wrapAsync(fn); return initialParams(function reflectOn(args, reflectCallback) { - args.push(function callback(error, cbArg) { + args.push((error, ...cbArgs) => { if (error) { - reflectCallback(null, { error: error }); - } else { - var value; - if (arguments.length <= 2) { - value = cbArg - } else { - value = slice(arguments, 1); - } - reflectCallback(null, { value: value }); + return reflectCallback(null, { error }); } + var value = cbArgs; + if (cbArgs.length <= 1) { + value = cbArgs[0] + } + reflectCallback(null, { value }); }); return _fn.apply(this, args); diff --git a/lib/reflectAll.js b/lib/reflectAll.js index 3f078dc96..12db89cdf 100644 --- a/lib/reflectAll.js +++ b/lib/reflectAll.js @@ -1,5 +1,4 @@ import reflect from './reflect'; -import forOwn from './internal/forOwn'; /** * A helper function that wraps an array or an object of functions with `reflect`. @@ -74,8 +73,8 @@ export default function reflectAll(tasks) { results = tasks.map(reflect); } else { results = {}; - forOwn(tasks, function(task, key) { - results[key] = reflect.call(this, task); + Object.keys(tasks).forEach(key => { + results[key] = reflect.call(this, tasks[key]); }); } return results; diff --git a/lib/retry.js b/lib/retry.js index ef0440667..2a353dc32 100644 --- a/lib/retry.js +++ b/lib/retry.js @@ -91,31 +91,15 @@ function constant(value) { * }); * */ -export default function retry(opts, task, callback) { - var DEFAULT_TIMES = 5; - var DEFAULT_INTERVAL = 0; +const DEFAULT_TIMES = 5; +const DEFAULT_INTERVAL = 0; +export default function retry(opts, task, callback) { var options = { times: DEFAULT_TIMES, intervalFunc: constant(DEFAULT_INTERVAL) }; - function parseTimes(acc, t) { - if (typeof t === 'object') { - acc.times = +t.times || DEFAULT_TIMES; - - acc.intervalFunc = typeof t.interval === 'function' ? - t.interval : - constant(+t.interval || DEFAULT_INTERVAL); - - acc.errorFilter = t.errorFilter; - } else if (typeof t === 'number' || typeof t === 'string') { - acc.times = +t || DEFAULT_TIMES; - } else { - throw new Error("Invalid arguments for async.retry"); - } - } - if (arguments.length < 3 && typeof opts === 'function') { callback = task || noop; task = opts; @@ -132,17 +116,33 @@ export default function retry(opts, task, callback) { var attempt = 1; function retryAttempt() { - _task(function(err) { + _task((err, ...args) => { if (err === false) return if (err && attempt++ < options.times && (typeof options.errorFilter != 'function' || options.errorFilter(err))) { setTimeout(retryAttempt, options.intervalFunc(attempt)); } else { - callback.apply(null, arguments); + callback(err, ...args); } }); } retryAttempt(); } + +function parseTimes(acc, t) { + if (typeof t === 'object') { + acc.times = +t.times || DEFAULT_TIMES; + + acc.intervalFunc = typeof t.interval === 'function' ? + t.interval : + constant(+t.interval || DEFAULT_INTERVAL); + + acc.errorFilter = t.errorFilter; + } else if (typeof t === 'number' || typeof t === 'string') { + acc.times = +t || DEFAULT_TIMES; + } else { + throw new Error("Invalid arguments for async.retry"); + } +} diff --git a/lib/retryable.js b/lib/retryable.js index 57410317a..9422eed1c 100644 --- a/lib/retryable.js +++ b/lib/retryable.js @@ -36,9 +36,9 @@ export default function (opts, task) { opts = null; } var _task = wrapAsync(task); - return initialParams(function (args, callback) { + return initialParams((args, callback) => { function taskFn(cb) { - _task.apply(null, args.concat(cb)); + _task(...args, cb); } if (opts) retry(opts, taskFn, callback); diff --git a/lib/seq.js b/lib/seq.js index 567219545..6dc28d885 100644 --- a/lib/seq.js +++ b/lib/seq.js @@ -1,5 +1,4 @@ import noop from './internal/noop'; -import slice from './internal/slice'; import reduce from './reduce'; import wrapAsync from './internal/wrapAsync'; @@ -41,10 +40,9 @@ import wrapAsync from './internal/wrapAsync'; * }); * }); */ -export default function seq(/*...functions*/) { - var _functions = Array.prototype.map.call(arguments, wrapAsync); - return function(/*...args*/) { - var args = slice(arguments); +export default function seq(...functions) { + var _functions = functions.map(wrapAsync); + return function (...args) { var that = this; var cb = args[args.length - 1]; @@ -54,14 +52,11 @@ export default function seq(/*...functions*/) { cb = noop; } - reduce(_functions, args, function(newargs, fn, cb) { - fn.apply(that, newargs.concat(function(err/*, ...nextargs*/) { - var nextargs = slice(arguments, 1); + reduce(_functions, args, (newargs, fn, cb) => { + fn.apply(that, newargs.concat((err, ...nextargs) => { cb(err, nextargs); })); }, - function(err, results) { - cb.apply(that, [err].concat(results)); - }); + (err, results) => cb(err, ...results)); }; } diff --git a/lib/some.js b/lib/some.js index d574d0219..d0d9d9e93 100644 --- a/lib/some.js +++ b/lib/some.js @@ -1,6 +1,5 @@ import createTester from './internal/createTester'; import doParallel from './internal/doParallel'; -import identity from './internal/identity'; /** * Returns `true` if at least one element in the `coll` satisfies an async test. @@ -32,4 +31,4 @@ import identity from './internal/identity'; * // if result is true then at least one of the files exists * }); */ -export default doParallel(createTester(Boolean, identity)); +export default doParallel(createTester(Boolean, res => res)); diff --git a/lib/someLimit.js b/lib/someLimit.js index f234828a5..a5906aae2 100644 --- a/lib/someLimit.js +++ b/lib/someLimit.js @@ -1,6 +1,5 @@ import createTester from './internal/createTester'; import doParallelLimit from './internal/doParallelLimit'; -import identity from './internal/identity'; /** * The same as [`some`]{@link module:Collections.some} but runs a maximum of `limit` async operations at a time. @@ -23,4 +22,4 @@ import identity from './internal/identity'; * Result will be either `true` or `false` depending on the values of the async * tests. Invoked with (err, result). */ -export default doParallelLimit(createTester(Boolean, identity)); +export default doParallelLimit(createTester(Boolean, res => res)); diff --git a/lib/sortBy.js b/lib/sortBy.js index 85028b2fa..3b9ce61cc 100644 --- a/lib/sortBy.js +++ b/lib/sortBy.js @@ -1,6 +1,5 @@ import map from './map'; import wrapAsync from './internal/wrapAsync'; -import property from './internal/property'; /** * Sorts a list by the results of running each `coll` value through an async @@ -51,14 +50,14 @@ import property from './internal/property'; */ export default function sortBy (coll, iteratee, callback) { var _iteratee = wrapAsync(iteratee); - map(coll, function (x, callback) { - _iteratee(x, function (err, criteria) { + map(coll, (x, callback) => { + _iteratee(x, (err, criteria) => { if (err) return callback(err); - callback(null, {value: x, criteria: criteria}); + callback(null, {value: x, criteria}); }); - }, function (err, results) { + }, (err, results) => { if (err) return callback(err); - callback(null, results.sort(comparator).map(property('value'))); + callback(null, results.sort(comparator).map(v => v.value)); }); function comparator(left, right) { diff --git a/lib/timeout.js b/lib/timeout.js index ebd81b1a3..39fd3356b 100644 --- a/lib/timeout.js +++ b/lib/timeout.js @@ -45,7 +45,7 @@ import wrapAsync from './internal/wrapAsync'; export default function timeout(asyncFn, milliseconds, info) { var fn = wrapAsync(asyncFn); - return initialParams(function (args, callback) { + return initialParams((args, callback) => { var timedOut = false; var timer; @@ -60,15 +60,15 @@ export default function timeout(asyncFn, milliseconds, info) { callback(error); } - args.push(function () { + args.push((...args) => { if (!timedOut) { - callback.apply(null, arguments); + callback(...args); clearTimeout(timer); } }); // setup timer and call original function timer = setTimeout(timeoutCallback, milliseconds); - fn.apply(null, args); + fn(...args); }); } diff --git a/lib/transform.js b/lib/transform.js index 501636c76..2a688459c 100644 --- a/lib/transform.js +++ b/lib/transform.js @@ -54,9 +54,7 @@ export default function transform (coll, accumulator, iteratee, callback) { callback = once(callback || noop); var _iteratee = wrapAsync(iteratee); - eachOf(coll, function(v, k, cb) { + eachOf(coll, (v, k, cb) => { _iteratee(accumulator, v, k, cb); - }, function(err) { - callback(err, accumulator); - }); + }, err => callback(err, accumulator)); } diff --git a/lib/tryEach.js b/lib/tryEach.js index 82649b4bd..c987d2497 100644 --- a/lib/tryEach.js +++ b/lib/tryEach.js @@ -1,7 +1,6 @@ import eachSeries from './eachSeries'; import noop from './internal/noop'; import wrapAsync from './internal/wrapAsync'; -import slice from './internal/slice'; /** * It runs each task in series but stops whenever any of the functions were @@ -44,17 +43,17 @@ export default function tryEach(tasks, callback) { var error = null; var result; callback = callback || noop; - eachSeries(tasks, function(task, callback) { - wrapAsync(task)(function (err, res/*, ...args*/) { - if (arguments.length > 2) { - result = slice(arguments, 1); + eachSeries(tasks, (task, callback) => { + wrapAsync(task)((err, ...args) => { + if (args.length < 2) { + result = args[0]; } else { - result = res; + result = args; } error = err; callback(err ? null : {}); }); - }, function () { + }, () => { callback(error, result); }); } diff --git a/lib/unmemoize.js b/lib/unmemoize.js index d89075f5d..62966c0e8 100644 --- a/lib/unmemoize.js +++ b/lib/unmemoize.js @@ -12,7 +12,7 @@ * @returns {AsyncFunction} a function that calls the original unmemoized function */ export default function unmemoize(fn) { - return function () { - return (fn.unmemoized || fn).apply(null, arguments); + return (...args) => { + return (fn.unmemoized || fn)(...args); }; } diff --git a/lib/until.js b/lib/until.js index 942a38120..31b7e9f24 100644 --- a/lib/until.js +++ b/lib/until.js @@ -23,7 +23,5 @@ import whilst from './whilst'; * callback. Invoked with (err, [results]); */ export default function until(test, iteratee, callback) { - whilst(function() { - return !test.apply(this, arguments); - }, iteratee, callback); + whilst((...args) => !test(...args), iteratee, callback); } diff --git a/lib/waterfall.js b/lib/waterfall.js index ceaf59d87..f4c3ddce7 100644 --- a/lib/waterfall.js +++ b/lib/waterfall.js @@ -1,6 +1,5 @@ import noop from './internal/noop'; import once from './internal/once'; -import slice from './internal/slice'; import onlyOnce from './internal/onlyOnce'; import wrapAsync from './internal/wrapAsync'; @@ -70,16 +69,15 @@ export default function(tasks, callback) { function nextTask(args) { var task = wrapAsync(tasks[taskIndex++]); - args.push(onlyOnce(next)); - task.apply(null, args); + task(...args, onlyOnce(next)); } - function next(err/*, ...args*/) { + function next(err, ...args) { if (err === false) return if (err || taskIndex === tasks.length) { - return callback.apply(null, arguments); + return callback(err, ...args); } - nextTask(slice(arguments, 1)); + nextTask(args); } nextTask([]); diff --git a/lib/whilst.js b/lib/whilst.js index 32c3b52e5..23dc7c905 100644 --- a/lib/whilst.js +++ b/lib/whilst.js @@ -1,5 +1,4 @@ import noop from './internal/noop'; -import slice from './internal/slice'; import onlyOnce from './internal/onlyOnce'; import wrapAsync from './internal/wrapAsync'; @@ -42,12 +41,11 @@ export default function whilst(test, iteratee, callback) { callback = onlyOnce(callback || noop); var _iteratee = wrapAsync(iteratee); if (!test()) return callback(null); - var next = function(err/*, ...args*/) { + var next = (err, ...args) => { if (err) return callback(err); if (err === false) return; if (test()) return _iteratee(next); - var args = slice(arguments, 1); - callback.apply(null, [null].concat(args)); + callback(null, ...args); }; _iteratee(next); } diff --git a/package-lock.json b/package-lock.json index e6b9c2e3b..28904fafc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -47,6 +47,23 @@ "integrity": "sha1-EFSVrlNh1pe9GVyCUZLhrX8lN4c=", "dev": true }, + "acorn-jsx": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-3.0.1.tgz", + "integrity": "sha1-r9+UiPsezvyDSPb7IvRk4ypYs2s=", + "dev": true, + "requires": { + "acorn": "^3.0.4" + }, + "dependencies": { + "acorn": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-3.3.0.tgz", + "integrity": "sha1-ReN/s56No/JbruP/U2niu18iAXo=", + "dev": true + } + } + }, "acorn-node": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/acorn-node/-/acorn-node-1.3.0.tgz", @@ -99,6 +116,12 @@ "json-schema-traverse": "^0.3.0" } }, + "ajv-keywords": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-2.1.1.tgz", + "integrity": "sha1-YXmX/F9gV2iUxDX5QNgZ4TW4B2I=", + "dev": true + }, "align-text": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz", @@ -153,6 +176,12 @@ } } }, + "ansi-escapes": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.1.0.tgz", + "integrity": "sha512-UgAb8H9D41AQnu/PbWlCofQVcnV4Gs2bBJi9eZPxfU/hgglFh3SMDMENRIqdr7H6XFnXdoknctFByVsCOotTVw==", + "dev": true + }, "ansi-regex": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.0.0.tgz", @@ -233,6 +262,21 @@ "integrity": "sha1-3Tz7gO15c6dRF82sabC5nshhhvU=", "dev": true }, + "array-union": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-1.0.2.tgz", + "integrity": "sha1-mjRBDk9OPaI96jdb5b5w8kd47Dk=", + "dev": true, + "requires": { + "array-uniq": "^1.0.1" + } + }, + "array-uniq": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/array-uniq/-/array-uniq-1.0.3.tgz", + "integrity": "sha1-r2rId6Jcx/dOBYiUdThY39sk/bY=", + "dev": true + }, "array-unique": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/array-unique/-/array-unique-0.2.1.tgz", @@ -245,6 +289,12 @@ "integrity": "sha512-wGUIVQXuehL5TCqQun8OW81jGzAWycqzFF8lFp+GOM5BXLYj3bKNsYC4daB7n6XjCqxQA/qgTJ+8ANR3acjrog==", "dev": true }, + "arrify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", + "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", + "dev": true + }, "asn1": { "version": "0.2.3", "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.3.tgz", @@ -2055,12 +2105,27 @@ "integrity": "sha1-0JxLUoAKpMB44t2BqGmqyQ0uVOc=", "dev": true }, + "caller-path": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/caller-path/-/caller-path-0.1.0.tgz", + "integrity": "sha1-lAhe9jWB7NPaqSREqP6U6CV3dR8=", + "dev": true, + "requires": { + "callsites": "^0.2.0" + } + }, "callsite": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/callsite/-/callsite-1.0.0.tgz", "integrity": "sha1-KAOY5dZkvXQDi28JBRU+borxvCA=", "dev": true }, + "callsites": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-0.2.0.tgz", + "integrity": "sha1-r6uWJikQp/M8GaV3WCXGnzTjUMo=", + "dev": true + }, "camelcase": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-1.2.1.tgz", @@ -2119,6 +2184,12 @@ "supports-color": "^2.0.0" } }, + "chardet": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.4.2.tgz", + "integrity": "sha1-tUc7M9yXxCTl2Y3IfVXU2KKci/I=", + "dev": true + }, "check-error": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", @@ -2420,6 +2491,21 @@ "integrity": "sha512-vnJA8KS0BfOihugYEUkLRcnmq21FbuivbxgzDLXNs3zIk4KllV4Mx4UuTzBXht9F00C7QfD1YqMXg1zP6EXpig==", "dev": true }, + "cli-cursor": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-2.1.0.tgz", + "integrity": "sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU=", + "dev": true, + "requires": { + "restore-cursor": "^2.0.0" + } + }, + "cli-width": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-2.2.0.tgz", + "integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk=", + "dev": true + }, "cliui": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/cliui/-/cliui-2.1.0.tgz", @@ -2818,8 +2904,7 @@ "version": "0.1.3", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", - "dev": true, - "optional": true + "dev": true }, "defined": { "version": "1.0.0", @@ -2848,6 +2933,21 @@ } } }, + "del": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/del/-/del-2.2.2.tgz", + "integrity": "sha1-wSyYHQZ4RshLyvhiz/kw2Qf/0ag=", + "dev": true, + "requires": { + "globby": "^5.0.0", + "is-path-cwd": "^1.0.0", + "is-path-in-cwd": "^1.0.0", + "object-assign": "^4.0.1", + "pify": "^2.0.0", + "pinkie-promise": "^2.0.0", + "rimraf": "^2.2.8" + } + }, "delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", @@ -2936,6 +3036,15 @@ "randombytes": "^2.0.0" } }, + "doctrine": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", + "integrity": "sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==", + "dev": true, + "requires": { + "esutils": "^2.0.2" + } + }, "dom-serialize": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/dom-serialize/-/dom-serialize-2.2.1.tgz", @@ -3169,969 +3278,170 @@ } }, "eslint": { - "version": "2.13.1", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-2.13.1.tgz", - "integrity": "sha1-5MyPoPAJ+4KaquI4VaKTYL4fbBE=", + "version": "4.19.1", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-4.19.1.tgz", + "integrity": "sha512-bT3/1x1EbZB7phzYu7vCr1v3ONuzDtX8WjuM9c0iYxe+cq+pwcKEoQjl7zd3RpC6YOLgnSy3cTN58M2jcoPDIQ==", "dev": true, "requires": { - "chalk": "^1.1.3", - "concat-stream": "^1.4.6", - "debug": "^2.1.1", - "doctrine": "^1.2.2", - "es6-map": "^0.1.3", - "escope": "^3.6.0", - "espree": "^3.1.6", - "estraverse": "^4.2.0", + "ajv": "^5.3.0", + "babel-code-frame": "^6.22.0", + "chalk": "^2.1.0", + "concat-stream": "^1.6.0", + "cross-spawn": "^5.1.0", + "debug": "^3.1.0", + "doctrine": "^2.1.0", + "eslint-scope": "^3.7.1", + "eslint-visitor-keys": "^1.0.0", + "espree": "^3.5.4", + "esquery": "^1.0.0", "esutils": "^2.0.2", - "file-entry-cache": "^1.1.1", - "glob": "^7.0.3", - "globals": "^9.2.0", - "ignore": "^3.1.2", + "file-entry-cache": "^2.0.0", + "functional-red-black-tree": "^1.0.1", + "glob": "^7.1.2", + "globals": "^11.0.1", + "ignore": "^3.3.3", "imurmurhash": "^0.1.4", - "inquirer": "^0.12.0", - "is-my-json-valid": "^2.10.0", + "inquirer": "^3.0.6", "is-resolvable": "^1.0.0", - "js-yaml": "^3.5.1", - "json-stable-stringify": "^1.0.0", + "js-yaml": "^3.9.1", + "json-stable-stringify-without-jsonify": "^1.0.1", "levn": "^0.3.0", - "lodash": "^4.0.0", - "mkdirp": "^0.5.0", - "optionator": "^0.8.1", - "path-is-absolute": "^1.0.0", - "path-is-inside": "^1.0.1", - "pluralize": "^1.2.1", - "progress": "^1.1.8", - "require-uncached": "^1.0.2", - "shelljs": "^0.6.0", - "strip-json-comments": "~1.0.1", - "table": "^3.7.8", - "text-table": "~0.2.0", - "user-home": "^2.0.0" + "lodash": "^4.17.4", + "minimatch": "^3.0.2", + "mkdirp": "^0.5.1", + "natural-compare": "^1.4.0", + "optionator": "^0.8.2", + "path-is-inside": "^1.0.2", + "pluralize": "^7.0.0", + "progress": "^2.0.0", + "regexpp": "^1.0.1", + "require-uncached": "^1.0.3", + "semver": "^5.3.0", + "strip-ansi": "^4.0.0", + "strip-json-comments": "~2.0.1", + "table": "4.0.2", + "text-table": "~0.2.0" }, "dependencies": { - "acorn": { - "version": "5.5.3", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.5.3.tgz", - "integrity": "sha512-jd5MkIUlbbmb07nXH0DT3y7rDVtkzDi4XZOUVWAer8ajmF/DTSSbl5oNFyDOl/OXA33Bl79+ypHhl2pN20VeOQ==", - "dev": true - }, - "acorn-jsx": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-3.0.1.tgz", - "integrity": "sha1-r9+UiPsezvyDSPb7IvRk4ypYs2s=", - "dev": true, - "requires": { - "acorn": "^3.0.4" - }, - "dependencies": { - "acorn": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-3.3.0.tgz", - "integrity": "sha1-ReN/s56No/JbruP/U2niu18iAXo=", - "dev": true - } - } - }, - "ajv": { - "version": "4.11.8", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-4.11.8.tgz", - "integrity": "sha1-gv+wKynmYq5TvcIK8VlHcGc5xTY=", - "dev": true, - "requires": { - "co": "^4.6.0", - "json-stable-stringify": "^1.0.1" - } - }, - "ajv-keywords": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-1.5.1.tgz", - "integrity": "sha1-MU3QpLM2j609/NxU7eYXG4htrzw=", - "dev": true - }, - "ansi-escapes": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-1.4.0.tgz", - "integrity": "sha1-06ioOzGapneTZisT52HHkRQiMG4=", - "dev": true - }, "ansi-regex": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", - "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", + "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", "dev": true }, "ansi-styles": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", - "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", - "dev": true - }, - "array-union": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/array-union/-/array-union-1.0.2.tgz", - "integrity": "sha1-mjRBDk9OPaI96jdb5b5w8kd47Dk=", - "dev": true, - "requires": { - "array-uniq": "^1.0.1" - } - }, - "array-uniq": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/array-uniq/-/array-uniq-1.0.3.tgz", - "integrity": "sha1-r2rId6Jcx/dOBYiUdThY39sk/bY=", - "dev": true - }, - "arrify": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", - "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", - "dev": true - }, - "caller-path": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/caller-path/-/caller-path-0.1.0.tgz", - "integrity": "sha1-lAhe9jWB7NPaqSREqP6U6CV3dR8=", + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", "dev": true, "requires": { - "callsites": "^0.2.0" + "color-convert": "^1.9.0" } }, - "callsites": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/callsites/-/callsites-0.2.0.tgz", - "integrity": "sha1-r6uWJikQp/M8GaV3WCXGnzTjUMo=", - "dev": true - }, "chalk": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", - "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", - "dev": true, - "requires": { - "ansi-styles": "^2.2.1", - "escape-string-regexp": "^1.0.2", - "has-ansi": "^2.0.0", - "strip-ansi": "^3.0.0", - "supports-color": "^2.0.0" - } - }, - "circular-json": { - "version": "0.3.3", - "resolved": "https://registry.npmjs.org/circular-json/-/circular-json-0.3.3.tgz", - "integrity": "sha512-UZK3NBx2Mca+b5LsG7bY183pHWt5Y1xts4P3Pz7ENTwGVnJOUWbRb3ocjvX7hx9tq/yTAdclXm9sZ38gNuem4A==", - "dev": true - }, - "cli-cursor": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-1.0.2.tgz", - "integrity": "sha1-ZNo/fValRBLll5S9Ytw1KV6PKYc=", - "dev": true, - "requires": { - "restore-cursor": "^1.0.1" - } - }, - "cli-width": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-2.2.0.tgz", - "integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk=", - "dev": true - }, - "co": { - "version": "4.6.0", - "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", - "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=", - "dev": true - }, - "code-point-at": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", - "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", - "dev": true - }, - "concat-stream": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", - "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", - "dev": true, - "requires": { - "buffer-from": "^1.0.0", - "inherits": "^2.0.3", - "readable-stream": "^2.2.2", - "typedarray": "^0.0.6" - } - }, - "core-util-is": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", - "dev": true - }, - "d": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/d/-/d-1.0.0.tgz", - "integrity": "sha1-dUu1v+VUUdpppYuU1F9MWwRi1Y8=", + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.1.tgz", + "integrity": "sha512-ObN6h1v2fTJSmUXoS3nMQ92LbDK9be4TV+6G+omQlGJFdcUX5heKi1LZ1YnRMIgwTLEj3E24bT6tYni50rlCfQ==", "dev": true, "requires": { - "es5-ext": "^0.10.9" + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" } }, "debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", "dev": true, "requires": { "ms": "2.0.0" } }, - "deep-is": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", - "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", + "esprima": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.0.tgz", + "integrity": "sha512-oftTcaMu/EGrEIu904mWteKIv8vMuOgGYo7EhVJJN00R/EED9DCua/xxHRdYnKtcECzVg7xOWhflvJMnqcFZjw==", "dev": true }, - "del": { - "version": "2.2.2", - "resolved": "https://registry.npmjs.org/del/-/del-2.2.2.tgz", - "integrity": "sha1-wSyYHQZ4RshLyvhiz/kw2Qf/0ag=", - "dev": true, - "requires": { - "globby": "^5.0.0", - "is-path-cwd": "^1.0.0", - "is-path-in-cwd": "^1.0.0", - "object-assign": "^4.0.1", - "pify": "^2.0.0", - "pinkie-promise": "^2.0.0", - "rimraf": "^2.2.8" - } - }, - "doctrine": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-1.5.0.tgz", - "integrity": "sha1-N53Ocw9hZvds76TmcHoVmwLFpvo=", - "dev": true, - "requires": { - "esutils": "^2.0.2", - "isarray": "^1.0.0" - } - }, - "es5-ext": { - "version": "0.10.42", - "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.42.tgz", - "integrity": "sha512-AJxO1rmPe1bDEfSR6TJ/FgMFYuTBhR5R57KW58iCkYACMyFbrkqVyzXSurYoScDGvgyMpk7uRF/lPUPPTmsRSA==", - "dev": true, - "requires": { - "es6-iterator": "~2.0.3", - "es6-symbol": "~3.1.1", - "next-tick": "1" - } - }, - "es6-iterator": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz", - "integrity": "sha1-p96IkUGgWpSwhUQDstCg+/qY87c=", - "dev": true, - "requires": { - "d": "1", - "es5-ext": "^0.10.35", - "es6-symbol": "^3.1.1" - } - }, - "es6-map": { - "version": "0.1.5", - "resolved": "https://registry.npmjs.org/es6-map/-/es6-map-0.1.5.tgz", - "integrity": "sha1-kTbgUD3MBqMBaQ8LsU/042TpSfA=", - "dev": true, - "requires": { - "d": "1", - "es5-ext": "~0.10.14", - "es6-iterator": "~2.0.1", - "es6-set": "~0.1.5", - "es6-symbol": "~3.1.1", - "event-emitter": "~0.3.5" - } - }, - "es6-set": { - "version": "0.1.5", - "resolved": "https://registry.npmjs.org/es6-set/-/es6-set-0.1.5.tgz", - "integrity": "sha1-0rPsXU2ADO2BjbU40ol02wpzzLE=", - "dev": true, - "requires": { - "d": "1", - "es5-ext": "~0.10.14", - "es6-iterator": "~2.0.1", - "es6-symbol": "3.1.1", - "event-emitter": "~0.3.5" - } - }, - "es6-symbol": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.1.tgz", - "integrity": "sha1-vwDvT9q2uhtG7Le2KbTH7VcVzHc=", - "dev": true, - "requires": { - "d": "1", - "es5-ext": "~0.10.14" - } - }, - "es6-weak-map": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/es6-weak-map/-/es6-weak-map-2.0.2.tgz", - "integrity": "sha1-XjqzIlH/0VOKH45f+hNXdy+S2W8=", - "dev": true, - "requires": { - "d": "1", - "es5-ext": "^0.10.14", - "es6-iterator": "^2.0.1", - "es6-symbol": "^3.1.1" - } + "globals": { + "version": "11.7.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-11.7.0.tgz", + "integrity": "sha512-K8BNSPySfeShBQXsahYB/AbbWruVOTyVpgoIDnl8odPpeSfP2J5QO2oLFFdl2j7GfDCtZj2bMKar2T49itTPCg==", + "dev": true }, - "escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", "dev": true }, - "escope": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/escope/-/escope-3.6.0.tgz", - "integrity": "sha1-4Bl16BJ4GhY6ba392AOY3GTIicM=", + "js-yaml": { + "version": "3.12.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.12.0.tgz", + "integrity": "sha512-PIt2cnwmPfL4hKNwqeiuz4bKfnzHTBv6HyVgjahA6mPLwPDzjDWrplJBMjHUFxku/N3FlmrbyPclad+I+4mJ3A==", "dev": true, "requires": { - "es6-map": "^0.1.3", - "es6-weak-map": "^2.0.1", - "esrecurse": "^4.1.0", - "estraverse": "^4.1.1" + "argparse": "^1.0.7", + "esprima": "^4.0.0" } }, - "espree": { - "version": "3.5.4", - "resolved": "https://registry.npmjs.org/espree/-/espree-3.5.4.tgz", - "integrity": "sha512-yAcIQxtmMiB/jL32dzEp2enBeidsB7xWPLNiw3IIkpVds1P+h7qF9YwJq1yUNzp2OKXgAprs4F61ih66UsoD1A==", + "strip-ansi": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", + "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", "dev": true, "requires": { - "acorn": "^5.5.0", - "acorn-jsx": "^3.0.0" + "ansi-regex": "^3.0.0" } }, - "esrecurse": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.2.1.tgz", - "integrity": "sha512-64RBB++fIOAXPw3P9cy89qfMlvZEXZkqqJkjqqXIvzP5ezRZjW+lPWjw35UX/3EhUPFYbg5ER4JYgDw4007/DQ==", + "supports-color": { + "version": "5.4.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz", + "integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==", "dev": true, "requires": { - "estraverse": "^4.1.0" + "has-flag": "^3.0.0" } - }, - "estraverse": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.2.0.tgz", - "integrity": "sha1-De4/7TH81GlhjOc0IJn8GvoL2xM=", - "dev": true - }, - "esutils": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", - "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", - "dev": true - }, - "event-emitter": { - "version": "0.3.5", - "resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz", - "integrity": "sha1-34xp7vFkeSPHFXuc6DhAYQsCzDk=", - "dev": true, - "requires": { - "d": "1", - "es5-ext": "~0.10.14" - } - }, - "exit-hook": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/exit-hook/-/exit-hook-1.1.1.tgz", - "integrity": "sha1-8FyiM7SMBdVP/wd2XfhQfpXAL/g=", - "dev": true - }, - "fast-levenshtein": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", - "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", - "dev": true - }, - "figures": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/figures/-/figures-1.7.0.tgz", - "integrity": "sha1-y+Hjr/zxzUS4DK3+0o3Hk6lwHS4=", - "dev": true, - "requires": { - "escape-string-regexp": "^1.0.5", - "object-assign": "^4.1.0" - } - }, - "file-entry-cache": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-1.3.1.tgz", - "integrity": "sha1-RMYepgeuS+nBQC9B9EJwy/4zT/g=", - "dev": true, - "requires": { - "flat-cache": "^1.2.1", - "object-assign": "^4.0.1" - } - }, - "flat-cache": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-1.3.0.tgz", - "integrity": "sha1-0wMLMrOBVPTjt+nHCfSQ9++XxIE=", - "dev": true, - "requires": { - "circular-json": "^0.3.1", - "del": "^2.0.2", - "graceful-fs": "^4.1.2", - "write": "^0.2.1" - } - }, - "generate-function": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.0.0.tgz", - "integrity": "sha1-aFj+fAlpt9TpCTM3ZHrHn2DfvnQ=", - "dev": true - }, - "generate-object-property": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/generate-object-property/-/generate-object-property-1.2.0.tgz", - "integrity": "sha1-nA4cQDCM6AT0eDYYuTf6iPmdUNA=", - "dev": true, - "requires": { - "is-property": "^1.0.0" - } - }, - "globby": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/globby/-/globby-5.0.0.tgz", - "integrity": "sha1-69hGZ8oNuzMLmbz8aOrCvFQ3Dg0=", - "dev": true, - "requires": { - "array-union": "^1.0.1", - "arrify": "^1.0.0", - "glob": "^7.0.3", - "object-assign": "^4.0.1", - "pify": "^2.0.0", - "pinkie-promise": "^2.0.0" - } - }, - "graceful-fs": { - "version": "4.1.11", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", - "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=", - "dev": true - }, - "has-ansi": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", - "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", - "dev": true, - "requires": { - "ansi-regex": "^2.0.0" - } - }, - "ignore": { - "version": "3.3.8", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-3.3.8.tgz", - "integrity": "sha512-pUh+xUQQhQzevjRHHFqqcTy0/dP/kS9I8HSrUydhihjuD09W6ldVWFtIrwhXdUJHis3i2rZNqEHpZH/cbinFbg==", - "dev": true - }, - "imurmurhash": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", - "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", - "dev": true - }, - "inherits": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", - "dev": true - }, - "inquirer": { - "version": "0.12.0", - "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-0.12.0.tgz", - "integrity": "sha1-HvK/1jUE3wvHV4X/+MLEHfEvB34=", - "dev": true, - "requires": { - "ansi-escapes": "^1.1.0", - "ansi-regex": "^2.0.0", - "chalk": "^1.0.0", - "cli-cursor": "^1.0.1", - "cli-width": "^2.0.0", - "figures": "^1.3.5", - "lodash": "^4.3.0", - "readline2": "^1.0.1", - "run-async": "^0.1.0", - "rx-lite": "^3.1.2", - "string-width": "^1.0.1", - "strip-ansi": "^3.0.0", - "through": "^2.3.6" - } - }, - "is-fullwidth-code-point": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", - "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", - "dev": true, - "requires": { - "number-is-nan": "^1.0.0" - } - }, - "is-my-json-valid": { - "version": "2.17.2", - "resolved": "https://registry.npmjs.org/is-my-json-valid/-/is-my-json-valid-2.17.2.tgz", - "integrity": "sha512-IBhBslgngMQN8DDSppmgDv7RNrlFotuuDsKcrCP3+HbFaVivIBU7u9oiiErw8sH4ynx3+gOGQ3q2otkgiSi6kg==", - "dev": true, - "requires": { - "generate-function": "^2.0.0", - "generate-object-property": "^1.1.0", - "is-my-ip-valid": "^1.0.0", - "jsonpointer": "^4.0.0", - "xtend": "^4.0.0" - } - }, - "is-path-cwd": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-path-cwd/-/is-path-cwd-1.0.0.tgz", - "integrity": "sha1-0iXsIxMuie3Tj9p2dHLmLmXxEG0=", - "dev": true - }, - "is-path-in-cwd": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/is-path-in-cwd/-/is-path-in-cwd-1.0.1.tgz", - "integrity": "sha512-FjV1RTW48E7CWM7eE/J2NJvAEEVektecDBVBE5Hh3nM1Jd0kvhHtX68Pr3xsDf857xt3Y4AkwVULK1Vku62aaQ==", - "dev": true, - "requires": { - "is-path-inside": "^1.0.0" - } - }, - "is-path-inside": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-1.0.1.tgz", - "integrity": "sha1-jvW33lBDej/cprToZe96pVy0gDY=", - "dev": true, - "requires": { - "path-is-inside": "^1.0.1" - } - }, - "is-property": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/is-property/-/is-property-1.0.2.tgz", - "integrity": "sha1-V/4cTkhHTt1lsJkR8msc1Ald2oQ=", - "dev": true - }, - "is-resolvable": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-resolvable/-/is-resolvable-1.1.0.tgz", - "integrity": "sha512-qgDYXFSR5WvEfuS5dMj6oTMEbrrSaM0CrFk2Yiq/gXnBvD9pMa2jGXxyhGLfvhZpuMZe18CJpFxAt3CRs42NMg==", - "dev": true - }, - "isarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", - "dev": true - }, - "json-stable-stringify": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/json-stable-stringify/-/json-stable-stringify-1.0.1.tgz", - "integrity": "sha1-mnWdOcXy/1A/1TAGRu1EX4jE+a8=", - "dev": true, - "requires": { - "jsonify": "~0.0.0" - } - }, - "jsonify": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz", - "integrity": "sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM=", - "dev": true - }, - "jsonpointer": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/jsonpointer/-/jsonpointer-4.0.1.tgz", - "integrity": "sha1-T9kss04OnbPInIYi7PUfm5eMbLk=", - "dev": true - }, - "levn": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", - "integrity": "sha1-OwmSTt+fCDwEkP3UwLxEIeBHZO4=", - "dev": true, - "requires": { - "prelude-ls": "~1.1.2", - "type-check": "~0.3.2" - } - }, - "minimist": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", - "dev": true - }, - "mkdirp": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", - "dev": true, - "requires": { - "minimist": "0.0.8" - } - }, - "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", - "dev": true - }, - "mute-stream": { - "version": "0.0.5", - "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.5.tgz", - "integrity": "sha1-j7+rsKmKJT0xhDMfno3rc3L6xsA=", - "dev": true - }, - "number-is-nan": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", - "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", - "dev": true - }, - "object-assign": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", - "dev": true - }, - "once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dev": true, - "requires": { - "wrappy": "1" - } - }, - "onetime": { - "version": "1.1.0", - "resolved": "http://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz", - "integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k=", - "dev": true - }, - "optionator": { - "version": "0.8.2", - "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.2.tgz", - "integrity": "sha1-NkxeQJ0/TWMB1sC0wFu6UBgK62Q=", - "dev": true, - "requires": { - "deep-is": "~0.1.3", - "fast-levenshtein": "~2.0.4", - "levn": "~0.3.0", - "prelude-ls": "~1.1.2", - "type-check": "~0.3.2", - "wordwrap": "~1.0.0" - } - }, - "os-homedir": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", - "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", - "dev": true - }, - "path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "dev": true - }, - "path-is-inside": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/path-is-inside/-/path-is-inside-1.0.2.tgz", - "integrity": "sha1-NlQX3t5EQw0cEa9hAn+s8HS9/FM=", - "dev": true - }, - "pify": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", - "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", - "dev": true - }, - "pinkie": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz", - "integrity": "sha1-clVrgM+g1IqXToDnckjoDtT3+HA=", - "dev": true - }, - "pinkie-promise": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz", - "integrity": "sha1-ITXW36ejWMBprJsXh3YogihFD/o=", - "dev": true, - "requires": { - "pinkie": "^2.0.0" - } - }, - "pluralize": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/pluralize/-/pluralize-1.2.1.tgz", - "integrity": "sha1-0aIUg/0iu0HlihL6NCGCMUCJfEU=", - "dev": true - }, - "prelude-ls": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", - "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=", - "dev": true - }, - "process-nextick-args": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz", - "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==", - "dev": true - }, - "progress": { - "version": "1.1.8", - "resolved": "https://registry.npmjs.org/progress/-/progress-1.1.8.tgz", - "integrity": "sha1-4mDHj2Fhzdmw5WzD4Khd4Xx6V74=", - "dev": true - }, - "readable-stream": { - "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", - "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", - "dev": true, - "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" - } - }, - "readline2": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/readline2/-/readline2-1.0.1.tgz", - "integrity": "sha1-QQWWCP/BVHV7cV2ZidGZ/783LjU=", - "dev": true, - "requires": { - "code-point-at": "^1.0.0", - "is-fullwidth-code-point": "^1.0.0", - "mute-stream": "0.0.5" - } - }, - "require-uncached": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz", - "integrity": "sha1-Tg1W1slmL9MeQwEcS5WqSZVUIdM=", - "dev": true, - "requires": { - "caller-path": "^0.1.0", - "resolve-from": "^1.0.0" - } - }, - "resolve-from": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-1.0.1.tgz", - "integrity": "sha1-Jsv+k10a7uq7Kbw/5a6wHpPUQiY=", - "dev": true - }, - "restore-cursor": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-1.0.1.tgz", - "integrity": "sha1-NGYfRohjJ/7SmRR5FSJS35LapUE=", - "dev": true, - "requires": { - "exit-hook": "^1.0.0", - "onetime": "^1.0.0" - } - }, - "run-async": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/run-async/-/run-async-0.1.0.tgz", - "integrity": "sha1-yK1KXhEGYeQCp9IbUw4AnyX444k=", - "dev": true, - "requires": { - "once": "^1.3.0" - } - }, - "rx-lite": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/rx-lite/-/rx-lite-3.1.2.tgz", - "integrity": "sha1-Gc5QLKVyZl87ZHsQk5+X/RYV8QI=", - "dev": true - }, - "shelljs": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.6.1.tgz", - "integrity": "sha1-7GIRvtGSBEIIj+D3Cyg3Iy7SyKg=", - "dev": true - }, - "slice-ansi": { - "version": "0.0.4", - "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-0.0.4.tgz", - "integrity": "sha1-7b+JA/ZvfOL46v1s7tZeJkyDGzU=", - "dev": true - }, - "string-width": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", - "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", - "dev": true, - "requires": { - "code-point-at": "^1.0.0", - "is-fullwidth-code-point": "^1.0.0", - "strip-ansi": "^3.0.0" - } - }, - "string_decoder": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", - "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "dev": true, - "requires": { - "safe-buffer": "~5.1.0" - } - }, - "strip-ansi": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", - "dev": true, - "requires": { - "ansi-regex": "^2.0.0" - } - }, - "strip-json-comments": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-1.0.4.tgz", - "integrity": "sha1-HhX7ysl9Pumb8tc7TGVrCCu6+5E=", - "dev": true - }, - "supports-color": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", - "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", - "dev": true - }, - "table": { - "version": "3.8.3", - "resolved": "https://registry.npmjs.org/table/-/table-3.8.3.tgz", - "integrity": "sha1-K7xULw/amGGnVdOUf+/Ys/UThV8=", - "dev": true, - "requires": { - "ajv": "^4.7.0", - "ajv-keywords": "^1.0.0", - "chalk": "^1.1.1", - "lodash": "^4.0.0", - "slice-ansi": "0.0.4", - "string-width": "^2.0.0" - }, - "dependencies": { - "ansi-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", - "dev": true - }, - "is-fullwidth-code-point": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", - "dev": true - }, - "string-width": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", - "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", - "dev": true, - "requires": { - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^4.0.0" - } - }, - "strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", - "dev": true, - "requires": { - "ansi-regex": "^3.0.0" - } - } - } - }, - "text-table": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", - "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", - "dev": true - }, - "through": { - "version": "2.3.8", - "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", - "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", - "dev": true - }, - "type-check": { - "version": "0.3.2", - "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", - "integrity": "sha1-WITKtRLPHTVeP7eE8wgEsrUg23I=", - "dev": true, - "requires": { - "prelude-ls": "~1.1.2" - } - }, - "typedarray": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", - "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", - "dev": true - }, - "user-home": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/user-home/-/user-home-2.0.0.tgz", - "integrity": "sha1-nHC/2Babwdy/SGBODwS4tJzenp8=", - "dev": true, - "requires": { - "os-homedir": "^1.0.0" - } - }, - "util-deprecate": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", - "dev": true - }, - "wordwrap": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", - "integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=", - "dev": true - }, - "wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true - }, - "write": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/write/-/write-0.2.1.tgz", - "integrity": "sha1-X8A4KOJkzqP+kUVUdvejxWbLB1c=", - "dev": true, - "requires": { - "mkdirp": "^0.5.1" - } - }, - "xtend": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", - "integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68=", + } + } + }, + "eslint-plugin-prefer-arrow": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/eslint-plugin-prefer-arrow/-/eslint-plugin-prefer-arrow-1.1.2.tgz", + "integrity": "sha512-DZr/ZR3PsEqEBVINvIhhxKJ0UKODC2MmIKTRCzzLSZW20Yv/UszDyXDh/qjAq1KzhFPMyYeTe7EZoTWUCS/7qA==", + "dev": true + }, + "eslint-scope": { + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-3.7.1.tgz", + "integrity": "sha1-PWPD7f2gLgbgGkUq2IyqzHzctug=", + "dev": true, + "requires": { + "esrecurse": "^4.1.0", + "estraverse": "^4.1.1" + } + }, + "eslint-visitor-keys": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", + "integrity": "sha512-qzm/XxIbxm/FHyH341ZrbnMUpe+5Bocte9xkmFMzPMjRaZMcXww+MpBptFvtU+79L362nqiLhekCxCxDPaUMBQ==", + "dev": true + }, + "espree": { + "version": "3.5.4", + "resolved": "https://registry.npmjs.org/espree/-/espree-3.5.4.tgz", + "integrity": "sha512-yAcIQxtmMiB/jL32dzEp2enBeidsB7xWPLNiw3IIkpVds1P+h7qF9YwJq1yUNzp2OKXgAprs4F61ih66UsoD1A==", + "dev": true, + "requires": { + "acorn": "^5.5.0", + "acorn-jsx": "^3.0.0" + }, + "dependencies": { + "acorn": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.1.tgz", + "integrity": "sha512-d+nbxBUGKg7Arpsvbnlq61mc12ek3EY8EQldM3GPAhWJ1UVxC6TDGbIvUMNU6obBX3i1+ptCIzV4vq0gFPEGVQ==", "dev": true } } @@ -4142,12 +3452,29 @@ "integrity": "sha1-luO3DVd59q1JzQMmc9HDEnZ7pYE=", "dev": true }, + "esquery": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.0.1.tgz", + "integrity": "sha512-SmiyZ5zIWH9VM+SRUReLS5Q8a7GxtRdxEBVZpm98rJM7Sb+A9DVCndXfkeFUd3byderg+EbDkfnevfCwynWaNA==", + "dev": true, + "requires": { + "estraverse": "^4.0.0" + } + }, + "esrecurse": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.2.1.tgz", + "integrity": "sha512-64RBB++fIOAXPw3P9cy89qfMlvZEXZkqqJkjqqXIvzP5ezRZjW+lPWjw35UX/3EhUPFYbg5ER4JYgDw4007/DQ==", + "dev": true, + "requires": { + "estraverse": "^4.1.0" + } + }, "estraverse": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.2.0.tgz", "integrity": "sha1-De4/7TH81GlhjOc0IJn8GvoL2xM=", - "dev": true, - "optional": true + "dev": true }, "esutils": { "version": "2.0.2", @@ -4269,6 +3596,17 @@ "integrity": "sha1-p1Xqe8Gt/MWjHOfnYtuq3F5jZEQ=", "dev": true }, + "external-editor": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-2.2.0.tgz", + "integrity": "sha512-bSn6gvGxKt+b7+6TKEv1ZycHleA7aHhRHyAqJyp5pbUFuYYNIzpZnQDk7AsYckyWdEnTeAnay0aCy2aV6iTk9A==", + "dev": true, + "requires": { + "chardet": "^0.4.0", + "iconv-lite": "^0.4.17", + "tmp": "^0.0.33" + } + }, "extglob": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/extglob/-/extglob-0.3.2.tgz", @@ -4306,8 +3644,26 @@ "version": "2.0.6", "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", + "dev": true + }, + "figures": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz", + "integrity": "sha1-OrGi0qYsi/tDGgyUy3l6L84nyWI=", "dev": true, - "optional": true + "requires": { + "escape-string-regexp": "^1.0.5" + } + }, + "file-entry-cache": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-2.0.0.tgz", + "integrity": "sha1-w5KZDD5oR4PYOLjISkXYoEhFg2E=", + "dev": true, + "requires": { + "flat-cache": "^1.2.1", + "object-assign": "^4.0.1" + } }, "file-uri-to-path": { "version": "1.0.0", @@ -4376,6 +3732,26 @@ "locate-path": "^2.0.0" } }, + "flat-cache": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-1.3.0.tgz", + "integrity": "sha1-0wMLMrOBVPTjt+nHCfSQ9++XxIE=", + "dev": true, + "requires": { + "circular-json": "^0.3.1", + "del": "^2.0.2", + "graceful-fs": "^4.1.2", + "write": "^0.2.1" + }, + "dependencies": { + "circular-json": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/circular-json/-/circular-json-0.3.3.tgz", + "integrity": "sha512-UZK3NBx2Mca+b5LsG7bY183pHWt5Y1xts4P3Pz7ENTwGVnJOUWbRb3ocjvX7hx9tq/yTAdclXm9sZ38gNuem4A==", + "dev": true + } + } + }, "follow-redirects": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.0.tgz", @@ -4520,12 +3896,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -4540,17 +3918,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -4667,7 +4048,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -4679,6 +4061,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -4693,6 +4076,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -4700,12 +4084,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.2.4", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -4724,6 +4110,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -4804,7 +4191,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -4816,6 +4204,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -4937,6 +4326,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -5054,6 +4444,12 @@ "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", "dev": true }, + "functional-red-black-tree": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", + "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", + "dev": true + }, "gasket": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/gasket/-/gasket-2.0.0.tgz", @@ -5271,6 +4667,20 @@ "integrity": "sha512-S0nG3CLEQiY/ILxqtztTWH/3iRRdyBLw6KMDxnKMchrtbj2OFmehVh0WUCfW3DUrIgx/qFrJPICrq4Z4sTR9UQ==", "dev": true }, + "globby": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-5.0.0.tgz", + "integrity": "sha1-69hGZ8oNuzMLmbz8aOrCvFQ3Dg0=", + "dev": true, + "requires": { + "array-union": "^1.0.1", + "arrify": "^1.0.0", + "glob": "^7.0.3", + "object-assign": "^4.0.1", + "pify": "^2.0.0", + "pinkie-promise": "^2.0.0" + } + }, "graceful-fs": { "version": "4.1.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", @@ -5561,6 +4971,18 @@ "integrity": "sha512-VhDzCKN7K8ufStx/CLj5/PDTMgph+qwN5Pkd5i0sGnVwk56zJ0lkT8Qzi1xqWLS0Wp29DgDtNeS7v8/wMoZeHg==", "dev": true }, + "ignore": { + "version": "3.3.10", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-3.3.10.tgz", + "integrity": "sha512-Pgs951kaMm5GXP7MOvxERINe3gsaVjUWFm+UZPSq9xYriQAksyhg0csnS0KXSNRD5NmNdapXEpjxG49+AKh/ug==", + "dev": true + }, + "imurmurhash": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", + "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", + "dev": true + }, "indexof": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/indexof/-/indexof-0.0.1.tgz", @@ -5589,6 +5011,80 @@ "source-map": "~0.5.3" } }, + "inquirer": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-3.3.0.tgz", + "integrity": "sha512-h+xtnyk4EwKvFWHrUYsWErEVR+igKtLdchu+o0Z1RL7VU/jVMFbYir2bp6bAj8efFNxWqHX0dIss6fJQ+/+qeQ==", + "dev": true, + "requires": { + "ansi-escapes": "^3.0.0", + "chalk": "^2.0.0", + "cli-cursor": "^2.1.0", + "cli-width": "^2.0.0", + "external-editor": "^2.0.4", + "figures": "^2.0.0", + "lodash": "^4.3.0", + "mute-stream": "0.0.7", + "run-async": "^2.2.0", + "rx-lite": "^4.0.8", + "rx-lite-aggregates": "^4.0.8", + "string-width": "^2.1.0", + "strip-ansi": "^4.0.0", + "through": "^2.3.6" + }, + "dependencies": { + "ansi-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", + "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", + "dev": true + }, + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + } + }, + "chalk": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.1.tgz", + "integrity": "sha512-ObN6h1v2fTJSmUXoS3nMQ92LbDK9be4TV+6G+omQlGJFdcUX5heKi1LZ1YnRMIgwTLEj3E24bT6tYni50rlCfQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + } + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", + "dev": true + }, + "strip-ansi": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", + "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "dev": true, + "requires": { + "ansi-regex": "^3.0.0" + } + }, + "supports-color": { + "version": "5.4.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz", + "integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==", + "dev": true, + "requires": { + "has-flag": "^3.0.0" + } + } + } + }, "insert-module-globals": { "version": "7.1.0", "resolved": "https://registry.npmjs.org/insert-module-globals/-/insert-module-globals-7.1.0.tgz", @@ -5688,7 +5184,8 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-my-ip-valid/-/is-my-ip-valid-1.0.0.tgz", "integrity": "sha512-gmh/eWXROncUzRnIa1Ubrt5b8ep/MGSnfAUI3aRp+sqTCs1tv1Isl8d8F6JmkN3dXKc3ehZMrtiPN9eL03NuaQ==", - "dev": true + "dev": true, + "optional": true }, "is-my-json-valid": { "version": "2.17.2", @@ -5713,6 +5210,30 @@ "kind-of": "^3.0.2" } }, + "is-path-cwd": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-path-cwd/-/is-path-cwd-1.0.0.tgz", + "integrity": "sha1-0iXsIxMuie3Tj9p2dHLmLmXxEG0=", + "dev": true + }, + "is-path-in-cwd": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-path-in-cwd/-/is-path-in-cwd-1.0.1.tgz", + "integrity": "sha512-FjV1RTW48E7CWM7eE/J2NJvAEEVektecDBVBE5Hh3nM1Jd0kvhHtX68Pr3xsDf857xt3Y4AkwVULK1Vku62aaQ==", + "dev": true, + "requires": { + "is-path-inside": "^1.0.0" + } + }, + "is-path-inside": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-1.0.1.tgz", + "integrity": "sha1-jvW33lBDej/cprToZe96pVy0gDY=", + "dev": true, + "requires": { + "path-is-inside": "^1.0.1" + } + }, "is-posix-bracket": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/is-posix-bracket/-/is-posix-bracket-0.1.1.tgz", @@ -5725,6 +5246,12 @@ "integrity": "sha1-IHurkWOEmcB7Kt8kCkGochADRXU=", "dev": true }, + "is-promise": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz", + "integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=", + "dev": true + }, "is-property": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/is-property/-/is-property-1.0.2.tgz", @@ -5732,6 +5259,12 @@ "dev": true, "optional": true }, + "is-resolvable": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-resolvable/-/is-resolvable-1.1.0.tgz", + "integrity": "sha512-qgDYXFSR5WvEfuS5dMj6oTMEbrrSaM0CrFk2Yiq/gXnBvD9pMa2jGXxyhGLfvhZpuMZe18CJpFxAt3CRs42NMg==", + "dev": true + }, "is-stream": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", @@ -5885,6 +5418,12 @@ "jsonify": "~0.0.0" } }, + "json-stable-stringify-without-jsonify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", + "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", + "dev": true + }, "json-stringify-safe": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", @@ -6145,7 +5684,6 @@ "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", "integrity": "sha1-OwmSTt+fCDwEkP3UwLxEIeBHZO4=", "dev": true, - "optional": true, "requires": { "prelude-ls": "~1.1.2", "type-check": "~0.3.2" @@ -6789,6 +6327,12 @@ "integrity": "sha1-IKMYwwy0X3H+et+/eyHJnBRy7xE=", "dev": true }, + "natural-compare": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", + "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", + "dev": true + }, "ncp": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/ncp/-/ncp-1.0.1.tgz", @@ -6820,12 +6364,6 @@ "dev": true, "optional": true }, - "next-tick": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz", - "integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw=", - "dev": true - }, "nodemailer": { "version": "2.7.2", "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-2.7.2.tgz", @@ -9597,6 +9135,12 @@ "integrity": "sha1-Rqarfwrq2N6unsBWV4C31O/rnUM=", "dev": true }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", + "dev": true + }, "object-component": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/object-component/-/object-component-0.0.3.tgz", @@ -9631,6 +9175,15 @@ "wrappy": "1" } }, + "onetime": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-2.0.1.tgz", + "integrity": "sha1-BnQoIw/WdEOyeUsiu6UotoZ5YtQ=", + "dev": true, + "requires": { + "mimic-fn": "^1.0.0" + } + }, "optimist": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz", @@ -9660,7 +9213,6 @@ "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.2.tgz", "integrity": "sha1-NkxeQJ0/TWMB1sC0wFu6UBgK62Q=", "dev": true, - "optional": true, "requires": { "deep-is": "~0.1.3", "fast-levenshtein": "~2.0.4", @@ -9880,6 +9432,12 @@ "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "dev": true }, + "path-is-inside": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/path-is-inside/-/path-is-inside-1.0.2.tgz", + "integrity": "sha1-NlQX3t5EQw0cEa9hAn+s8HS9/FM=", + "dev": true + }, "path-key": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", @@ -9942,19 +9500,23 @@ "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=", "dev": true }, + "pify": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", + "dev": true + }, "pinkie": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz", "integrity": "sha1-clVrgM+g1IqXToDnckjoDtT3+HA=", - "dev": true, - "optional": true + "dev": true }, "pinkie-promise": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz", "integrity": "sha1-ITXW36ejWMBprJsXh3YogihFD/o=", "dev": true, - "optional": true, "requires": { "pinkie": "^2.0.0" } @@ -9971,6 +9533,12 @@ "integrity": "sha1-bw+xftqqSPIUQrOpdcBjEw8cPr0=", "dev": true }, + "pluralize": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/pluralize/-/pluralize-7.0.0.tgz", + "integrity": "sha512-ARhBOdzS3e41FbkW/XWrTEtukqqLoK5+Z/4UeDaLuSW+39JPeFgs4gCGqsrJHVZX0fUrx//4OF0K1CUGwlIFow==", + "dev": true + }, "prelude-ls": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", @@ -10001,6 +9569,12 @@ "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==", "dev": true }, + "progress": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.0.tgz", + "integrity": "sha1-ihvjZr+Pwj2yvSPxDG/pILQ4nR8=", + "dev": true + }, "promisify-call": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/promisify-call/-/promisify-call-2.0.4.tgz", @@ -10371,6 +9945,12 @@ "is-primitive": "^2.0.0" } }, + "regexpp": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-1.1.0.tgz", + "integrity": "sha512-LOPw8FpgdQF9etWMaAfG/WRthIdXJGYp4mJ2Jgn/2lpkbod9jPn0t9UqN7AxBOKNfzRbYyVfgc7Vk4t/MpnXgw==", + "dev": true + }, "regexpu-core": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/regexpu-core/-/regexpu-core-2.0.0.tgz", @@ -10494,6 +10074,16 @@ } } }, + "require-uncached": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz", + "integrity": "sha1-Tg1W1slmL9MeQwEcS5WqSZVUIdM=", + "dev": true, + "requires": { + "caller-path": "^0.1.0", + "resolve-from": "^1.0.0" + } + }, "requires-port": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", @@ -10526,6 +10116,22 @@ "path-parse": "^1.0.5" } }, + "resolve-from": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-1.0.1.tgz", + "integrity": "sha1-Jsv+k10a7uq7Kbw/5a6wHpPUQiY=", + "dev": true + }, + "restore-cursor": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-2.0.0.tgz", + "integrity": "sha1-n37ih/gv0ybU/RYpI9YhKe7g368=", + "dev": true, + "requires": { + "onetime": "^2.0.0", + "signal-exit": "^3.0.2" + } + }, "revalidator": { "version": "0.1.8", "resolved": "https://registry.npmjs.org/revalidator/-/revalidator-0.1.8.tgz", @@ -10592,6 +10198,30 @@ "integrity": "sha512-OfWGQTb9vnwRjwtA2QwpG2ICclHC3pgXZO5xt8H2EfgDquO0qVdSb5T88L4qJVAEugbS56pAuV4XZM58UX8ulw==", "dev": true }, + "run-async": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.3.0.tgz", + "integrity": "sha1-A3GrSuC91yDUFm19/aZP96RFpsA=", + "dev": true, + "requires": { + "is-promise": "^2.1.0" + } + }, + "rx-lite": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/rx-lite/-/rx-lite-4.0.8.tgz", + "integrity": "sha1-Cx4Rr4vESDbwSmQH6S2kJGe3lEQ=", + "dev": true + }, + "rx-lite-aggregates": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/rx-lite-aggregates/-/rx-lite-aggregates-4.0.8.tgz", + "integrity": "sha1-dTuHqJoRyVRnxKwWJsTvxOBcZ74=", + "dev": true, + "requires": { + "rx-lite": "*" + } + }, "safe-buffer": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", @@ -10697,6 +10327,15 @@ "integrity": "sha1-xB8vbDn8FtHNF61LXYlhFK5HDVU=", "dev": true }, + "slice-ansi": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-1.0.0.tgz", + "integrity": "sha512-POqxBK6Lb3q6s047D/XsDVNPnF9Dl8JSaqe9h9lURl0OdNqy/ujDrOiIHtsqXMGbWWTIomRzAMaTyawAU//Reg==", + "dev": true, + "requires": { + "is-fullwidth-code-point": "^2.0.0" + } + }, "smart-buffer": { "version": "1.1.15", "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-1.1.15.tgz", @@ -11044,6 +10683,12 @@ "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=", "dev": true }, + "strip-json-comments": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", + "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", + "dev": true + }, "subarg": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/subarg/-/subarg-1.0.0.tgz", @@ -11085,12 +10730,69 @@ } } }, + "table": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/table/-/table-4.0.2.tgz", + "integrity": "sha512-UUkEAPdSGxtRpiV9ozJ5cMTtYiqz7Ni1OGqLXRCynrvzdtR1p+cfOWe2RJLwvUG8hNanaSRjecIqwOjqeatDsA==", + "dev": true, + "requires": { + "ajv": "^5.2.3", + "ajv-keywords": "^2.1.0", + "chalk": "^2.1.0", + "lodash": "^4.17.4", + "slice-ansi": "1.0.0", + "string-width": "^2.1.1" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + } + }, + "chalk": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.1.tgz", + "integrity": "sha512-ObN6h1v2fTJSmUXoS3nMQ92LbDK9be4TV+6G+omQlGJFdcUX5heKi1LZ1YnRMIgwTLEj3E24bT6tYni50rlCfQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + } + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", + "dev": true + }, + "supports-color": { + "version": "5.4.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz", + "integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==", + "dev": true, + "requires": { + "has-flag": "^3.0.0" + } + } + } + }, "taffydb": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/taffydb/-/taffydb-2.6.2.tgz", "integrity": "sha1-fLy2S1oUG2ou/CxdLGe04VCyomg=", "dev": true }, + "text-table": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", + "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", + "dev": true + }, "through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", @@ -11517,8 +11219,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", "integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=", - "dev": true, - "optional": true + "dev": true }, "wrap-ansi": { "version": "2.1.0", @@ -11558,6 +11259,15 @@ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", "dev": true }, + "write": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/write/-/write-0.2.1.tgz", + "integrity": "sha1-X8A4KOJkzqP+kUVUdvejxWbLB1c=", + "dev": true, + "requires": { + "mkdirp": "^0.5.1" + } + }, "ws": { "version": "3.3.3", "resolved": "https://registry.npmjs.org/ws/-/ws-3.3.3.tgz", diff --git a/package.json b/package.json index 9c7137d17..8f7569343 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,8 @@ "cheerio": "^0.22.0", "coveralls": "^3.0.1", "es6-promise": "^2.3.0", - "eslint": "^2.13.1", + "eslint": "^4.19.1", + "eslint-plugin-prefer-arrow": "^1.1.2", "fs-extra": "^0.26.7", "gh-pages-deploy": "^0.5.0", "jsdoc": "^3.4.0", @@ -60,7 +61,7 @@ "coverage": "nyc npm run mocha-node-test -- --grep @nycinvalid --invert", "coveralls": "npm run coverage && nyc report --reporter=text-lcov | coveralls", "jsdoc": "jsdoc -c ./support/jsdoc/jsdoc.json && node support/jsdoc/jsdoc-fix-html.js", - "lint": "eslint lib/ test/ perf/memory.js perf/suites.js perf/benchmark.js support/build/ support/*.js karma.conf.js", + "lint": "eslint --fix lib/ test/ perf/memory.js perf/suites.js perf/benchmark.js support/build/ support/*.js karma.conf.js", "mocha-browser-test": "karma start", "mocha-node-test": "mocha", "mocha-test": "npm run mocha-node-test && npm run mocha-browser-test", diff --git a/perf/benchmark.js b/perf/benchmark.js index 393464ff4..ba3c8e396 100755 --- a/perf/benchmark.js +++ b/perf/benchmark.js @@ -60,7 +60,7 @@ console.log("Comparing " + version0 + " with " + version1 + console.log("--------------------------------------"); -async.eachSeries(versionNames, cloneVersion, function (err) { +async.eachSeries(versionNames, cloneVersion, (err) => { if (err) { throw err; } versions = versionNames.map(requireVersion); @@ -72,7 +72,7 @@ async.eachSeries(versionNames, cloneVersion, function (err) { .filter(doesNotMatch) .map(createSuite); - async.eachSeries(suites, runSuite, function () { + async.eachSeries(suites, runSuite, () => { var totalTime0 = +totalTime[version0].toPrecision(3); var totalTime1 = +totalTime[version1].toPrecision(3); @@ -105,7 +105,7 @@ async.eachSeries(versionNames, cloneVersion, function (err) { }); function runSuite(suite, callback) { - suite.on("complete", function () { + suite.on("complete", () => { callback(); }).run({async: true}); } @@ -117,8 +117,8 @@ function setDefaultOptions(suiteConfig) { } function handleMultipleArgs(list, suiteConfig) { - return list.concat(suiteConfig.args.map(function (args) { - return _.defaults({args: args}, suiteConfig); + return list.concat(suiteConfig.args.map((args) => { + return _.defaults({args}, suiteConfig); })); } @@ -145,7 +145,7 @@ function createSuite(suiteConfig) { try { suiteConfig.setup(1); - suiteConfig.fn(version, function () {}); + suiteConfig.fn(version, () => {}); } catch (e) { console.error(name + " Errored"); errored = true; @@ -153,17 +153,17 @@ function createSuite(suiteConfig) { } var options = _.extend({ - versionName: versionName, - setup: function() { + versionName, + setup() { suiteConfig.setup.apply(null, args); }, - onError: function (err) { + onError (err) { console.log(err.stack); } }, benchOptions); - suite.add(name, function (deferred) { - suiteConfig.fn(version, function () { + suite.add(name, (deferred) => { + suiteConfig.fn(version, () => { deferred.resolve(); }); }, options); @@ -173,27 +173,27 @@ function createSuite(suiteConfig) { addBench(versions[1], versionNames[1]); - return suite.on('cycle', function(event) { + return suite.on('cycle', (event) => { var mean = event.target.stats.mean * 1000; console.log(event.target + ", " + mean.toPrecision(3) + "ms per run"); var version = event.target.options.versionName; if (errored) return; totalTime[version] += mean; }) - .on('error', function (err) { console.error(err); }) - .on('complete', function() { - if (!errored) { - var fastest = this.filter('fastest'); - if (fastest.length === 2) { - console.log("Tie"); - } else { - var winner = fastest[0].options.versionName; - console.log(winner + ' is faster'); - wins[winner]++; + .on('error', (err) => { console.error(err); }) + .on('complete', function() { + if (!errored) { + var fastest = this.filter('fastest'); + if (fastest.length === 2) { + console.log("Tie"); + } else { + var winner = fastest[0].options.versionName; + console.log(winner + ' is faster'); + wins[winner]++; + } } - } - console.log("--------------------------------------"); - }); + console.log("--------------------------------------"); + }); } @@ -210,7 +210,7 @@ function cloneVersion(tag, callback) { var versionDir = __dirname + "/versions/" + tag; mkdirp.sync(versionDir); - fs.open(versionDir + "/package.json", "r", function (err, handle) { + fs.open(versionDir + "/package.json", "r", (err, handle) => { if (!err) { // version has already been cloned return fs.close(handle, callback); @@ -220,7 +220,7 @@ function cloneVersion(tag, callback) { var cmd = "git clone --branch " + tag + " " + repoPath + " " + versionDir; - exec(cmd, function (err) { + exec(cmd, (err) => { if (err) { throw err; } diff --git a/perf/memory.js b/perf/memory.js index 1edab2077..d4a71e986 100644 --- a/perf/memory.js +++ b/perf/memory.js @@ -11,14 +11,12 @@ function waterfallTest(cb) { var functions = []; for(var i = 0; i < 10000; i++) { - functions.push(function leaky(next) { + functions.push((next) => { function func1(cb) {return cb(); } function func2(callback) { - if (true) { - callback(); - //return next(); // Should be callback here. - } + callback(); + //return next(); // Should be callback here. } function func3(cb) {return cb(); } @@ -41,6 +39,6 @@ function reportMemory() { (+(increase / 1024).toPrecision(3)) + "kB"); } -waterfallTest(function () { +waterfallTest(() => { setTimeout(reportMemory, 0); }); diff --git a/perf/suites.js b/perf/suites.js index 02f0e7ed9..e3b0c6f5f 100644 --- a/perf/suites.js +++ b/perf/suites.js @@ -13,8 +13,8 @@ module.exports = [{ setup: function setup(count) { tasks = _.range(count); }, - fn: function(async, done) { - async.each(tasks, function(num, cb) { + fn(async, done) { + async.each(tasks, (num, cb) => { async.setImmediate(cb); }, done); } @@ -28,8 +28,8 @@ module.exports = [{ setup: function setup(count) { tasks = _.range(count); }, - fn: function(async, done) { - async.eachSeries(tasks, function(num, cb) { + fn(async, done) { + async.eachSeries(tasks, (num, cb) => { async.setImmediate(cb); }, done); } @@ -43,8 +43,8 @@ module.exports = [{ setup: function setup(count) { tasks = _.range(count); }, - fn: function(async, done) { - async.eachLimit(tasks, 4, function(num, cb) { + fn(async, done) { + async.eachLimit(tasks, 4, (num, cb) => { async.setImmediate(cb); }, done); } @@ -59,8 +59,8 @@ module.exports = [{ setup: function setup(count) { tasks = _.range(count); }, - fn: function(async, done) { - async.map(tasks, function(num, cb) { + fn(async, done) { + async.map(tasks, (num, cb) => { async.setImmediate(cb); }, done); } @@ -74,8 +74,8 @@ module.exports = [{ setup: function setup(count) { tasks = _.range(count); }, - fn: function(async, done) { - async.mapSeries(tasks, function(num, cb) { + fn(async, done) { + async.mapSeries(tasks, (num, cb) => { async.setImmediate(cb); }, done); } @@ -89,8 +89,8 @@ module.exports = [{ setup: function setup(count) { tasks = _.range(count); }, - fn: function(async, done) { - async.mapLimit(tasks, 4, function(num, cb) { + fn(async, done) { + async.mapLimit(tasks, 4, (num, cb) => { async.setImmediate(cb); }, done); } @@ -105,9 +105,9 @@ module.exports = [{ count = c; tasks = _.range(count); }, - fn: function(async, done) { - async.filter(tasks, function(num, cb) { - async.setImmediate(function() { + fn(async, done) { + async.filter(tasks, (num, cb) => { + async.setImmediate(() => { cb(null, num > (count / 2)); }); }, done); @@ -123,9 +123,9 @@ module.exports = [{ count = c; tasks = _.range(count); }, - fn: function(async, done) { - async.filterLimit(tasks, 10, function(num, cb) { - async.setImmediate(function() { + fn(async, done) { + async.filterLimit(tasks, 10, (num, cb) => { + async.setImmediate(() => { cb(null, num > (count / 2)); }); }, done); @@ -141,9 +141,9 @@ module.exports = [{ setup: function setup(count) { tasks = _.range(count); }, - fn: function(async, done) { - async.concat(tasks, function(num, cb) { - async.setImmediate(function() { + fn(async, done) { + async.concat(tasks, (num, cb) => { + async.setImmediate(() => { cb(null, [num]); }); }, done); @@ -159,8 +159,8 @@ module.exports = [{ setup: function setup(count) { tasks = _.range(count); }, - fn: function(async, done) { - async.eachOf(tasks, function(num, i, cb) { + fn(async, done) { + async.eachOf(tasks, (num, i, cb) => { async.setImmediate(cb); }, done); } @@ -174,8 +174,8 @@ module.exports = [{ setup: function setup(count) { tasks = _.range(count); }, - fn: function(async, done) { - async.eachOfSeries(tasks, function(num, i, cb) { + fn(async, done) { + async.eachOfSeries(tasks, (num, i, cb) => { async.setImmediate(cb); }, done); } @@ -189,8 +189,8 @@ module.exports = [{ setup: function setup(count) { tasks = _.range(count); }, - fn: function(async, done) { - async.eachOfLimit(tasks, 4, function(num, i, cb) { + fn(async, done) { + async.eachOfLimit(tasks, 4, (num, i, cb) => { async.setImmediate(cb); }, done); } @@ -202,13 +202,13 @@ module.exports = [{ [1000] ], setup: function setup(count) { - tasks = _.range(count).map(function() { + tasks = _.range(count).map(() => { return function(cb) { setImmediate(cb); }; }); }, - fn: function(async, done) { + fn(async, done) { async.parallel(tasks, done); } }, { @@ -219,13 +219,13 @@ module.exports = [{ [1000] ], setup: function setup(count) { - tasks = _.range(count).map(function() { + tasks = _.range(count).map(() => { return function(cb) { setImmediate(cb); }; }); }, - fn: function(async, done) { + fn(async, done) { async.series(tasks, done); } }, { @@ -240,15 +240,15 @@ module.exports = [{ function(cb) { return cb(null, 1); } - ].concat(_.range(count).map(function(i) { + ].concat(_.range(count).map((i) => { return function(arg, cb) { - setImmediate(function() { + setImmediate(() => { cb(null, i); }); }; })); }, - fn: function(async, done) { + fn(async, done) { async.waterfall(tasks, done); } }, { @@ -260,9 +260,9 @@ module.exports = [{ ], setup: function setup(count) { tasks = { - dep1: function (cb) { cb(null, 1); } + dep1 (cb) { cb(null, 1); } }; - _.times(count, function(n) { + _.times(count, (n) => { var task = ['dep' + (n+1), function(results, cb) { setImmediate(cb, null, n); }]; @@ -270,7 +270,7 @@ module.exports = [{ tasks['dep' + (n+2)] = task; }); }, - fn: function(async, done) { + fn(async, done) { async.auto(tasks, done); } }, { @@ -286,7 +286,7 @@ module.exports = [{ setup: function setup(count) { tasks = count; }, - fn: function(async, done) { + fn(async, done) { var numEntries = tasks; var q = async.queue(worker, 1); for (var i = 1; i <= numEntries; i++) { @@ -311,9 +311,9 @@ module.exports = [{ setup: function setup(count) { tasks = _.range(count); }, - fn: function(async, done) { - async.some(tasks, function(i, cb) { - async.setImmediate(function() { + fn(async, done) { + async.some(tasks, (i, cb) => { + async.setImmediate(() => { cb(i >= 600); }); }, done); @@ -327,9 +327,9 @@ module.exports = [{ setup: function setup(count) { tasks = _.range(count); }, - fn: function(async, done) { - async.some(tasks, function(i, cb) { - async.setImmediate(function() { + fn(async, done) { + async.some(tasks, (i, cb) => { + async.setImmediate(() => { cb(i >= 60); }); }, done); @@ -343,9 +343,9 @@ module.exports = [{ setup: function setup(count) { tasks = _.range(count); }, - fn: function(async, done) { - async.every(tasks, function(i, cb) { - async.setImmediate(function() { + fn(async, done) { + async.every(tasks, (i, cb) => { + async.setImmediate(() => { cb(i <= 600); }); }, done); @@ -359,55 +359,55 @@ module.exports = [{ setup: function setup(count) { tasks = _.range(count); }, - fn: function(async, done) { - async.every(tasks, function(i, cb) { - async.setImmediate(function() { + fn(async, done) { + async.every(tasks, (i, cb) => { + async.setImmediate(() => { cb(i <= 60); }); }, done); } }, { name: "defer nextTick", - fn: function(async, done) { + fn(async, done) { process.nextTick(done); } }, { name: "defer setImmediate", - fn: function(async, done) { + fn(async, done) { setImmediate(done); } }, { name: "defer async.nextTick", - fn: function(async, done) { + fn(async, done) { async.nextTick(done); } }, { name: "defer async.setImmediate", - fn: function(async, done) { + fn(async, done) { async.setImmediate(done); } }, { name: "defer setTimeout", - fn: function(async, done) { + fn(async, done) { setTimeout(done, 0); } }, { name: "ensureAsync sync", - fn: function(async, done) { - async.ensureAsync(function(cb) { + fn(async, done) { + async.ensureAsync((cb) => { cb(); })(done); } }, { name: "ensureAsync async", - fn: function(async, done) { - async.ensureAsync(function(cb) { + fn(async, done) { + async.ensureAsync((cb) => { setImmediate(cb); })(done); } }, { name: "ensureAsync async noWrap", - fn: function(async, done) { + fn(async, done) { (function(cb) { setImmediate(cb); }(done)); diff --git a/support/build.test.js b/support/build.test.js index ebf18b7ec..178c62308 100644 --- a/support/build.test.js +++ b/support/build.test.js @@ -6,79 +6,79 @@ var rollupPluginNodeResolve = require('rollup-plugin-node-resolve'); var fs = require('fs'); var exec = require('child_process').exec; -describe("async main", function() { +describe("async main", () => { var async; - before(function() { + before(() => { async = require("../build/"); }); - it("should have methods", function() { - methods.forEach(function(methodName) { + it("should have methods", () => { + methods.forEach((methodName) => { expect(async[methodName]).to.be.a("function"); }); }); }); -describe("async umd", function() { +describe("async umd", () => { var async; - before(function() { + before(() => { async = require("../build/dist/async.js"); }); - it("should have methods", function() { - methods.forEach(function(methodName) { + it("should have methods", () => { + methods.forEach((methodName) => { expect(async[methodName]).to.be.a("function"); }); }); }); -describe("async umd minified", function() { +describe("async umd minified", () => { var async; - before(function() { + before(() => { async = require("../build/dist/async.min.js"); }); - it("should have methods", function() { - methods.forEach(function(methodName) { + it("should have methods", () => { + methods.forEach((methodName) => { expect(async[methodName]).to.be.a("function"); }); }); }); -methods.forEach(function (methodName) { - describe("async." + methodName, function () { +methods.forEach((methodName) => { + describe("async." + methodName, () => { var method; - before(function () { + before(() => { method = require("../build/" + methodName); }); - it("should require the individual method", function() { + it("should require the individual method", () => { expect(method).to.be.a("function"); }); }); }); -describe("ES Modules", function () { +describe("ES Modules", () => { var tmpDir = __dirname + "/../tmp"; var buildFile = __dirname + "/../tmp/es.test.js"; - before(function (done) { + before((done) => { if (fs.existsSync(tmpDir)) { return done(); } fs.mkdir(tmpDir, done); }); - before(function () { + before(() => { return rollup({ entry: __dirname + "/es.test.js", plugins: [ rollupPluginNodeResolve() ] - }).then(function (bundle) { + }).then((bundle) => { return bundle.write({ format: "umd", dest: buildFile @@ -86,8 +86,8 @@ describe("ES Modules", function () { }); }); - it("should build a successful bundle", function (done) { - exec("node " + buildFile, function (err, stdout) { + it("should build a successful bundle", (done) => { + exec("node " + buildFile, (err, stdout) => { if (err) { return done(err); } expect(stdout).to.match(/42/); done(); diff --git a/support/build/aggregate-bundle.js b/support/build/aggregate-bundle.js index c48b25f24..9430822d7 100644 --- a/support/build/aggregate-bundle.js +++ b/support/build/aggregate-bundle.js @@ -5,11 +5,11 @@ rollup({ entry: 'build-es/index.js', plugins: [ nodeResolve() ] }) -.then(function ( bundle ) { - return bundle.write({ - format: 'umd', - moduleName: 'async', - dest: 'build/dist/async.js' - }); -}) -.catch((err) => { throw err; }); + .then(( bundle ) => { + return bundle.write({ + format: 'umd', + moduleName: 'async', + dest: 'build/dist/async.js' + }); + }) + .catch((err) => { throw err; }); diff --git a/support/es.test.js b/support/es.test.js index 3dbb7d68c..45552be92 100644 --- a/support/es.test.js +++ b/support/es.test.js @@ -9,24 +9,24 @@ import forEachOf from "../build-es/forEachOf"; waterfall([ constant(42), function (val, next) { - async.setImmediate(function () { + async.setImmediate(() => { next(null, val); }); }, - wrapSync(function (a) { return a; }), + wrapSync((a) => { return a; }), function (val, next) { - async.forEachOf({a: 1}, function (val, key, cb) { + async.forEachOf({a: 1}, (val, key, cb) => { if (val !== 1 && key !== 'a') return cb(new Error('fail!')); cb(); - }, function (err) { next (err, val)}); + }, (err) => { next (err, val)}); }, function (val, next) { - forEachOf([1, 2, 3], function (v, key, cb) { + forEachOf([1, 2, 3], (v, key, cb) => { val += key cb() - }, function (err) { next(err, val - 3) }) + }, (err) => { next(err, val - 3) }) } -], function (err, result) { +], (err, result) => { if (err) { throw err; } console.log(result); if (result !== 42) { diff --git a/support/generate-index.js b/support/generate-index.js index 8e60f129b..ee760d2ec 100644 --- a/support/generate-index.js +++ b/support/generate-index.js @@ -56,7 +56,7 @@ function renderTemplate(entries, aliases, template) { .replace( `/*__default_object__*/`, entries - .map(entry => ` ${entry}: ${entry}`) + .map(entry => ` ${entry}`) .join(',\n') + ',') .replace( diff --git a/support/jsdoc/jsdoc-custom.js b/support/jsdoc/jsdoc-custom.js index b101444a8..e8a74548e 100644 --- a/support/jsdoc/jsdoc-custom.js +++ b/support/jsdoc/jsdoc-custom.js @@ -1,9 +1,9 @@ /* eslint no-undef: "off" */ if (typeof setImmediate !== 'function' && typeof async === 'object') { - setImmediate = async.setImmediate; + window.setImmediate = async.setImmediate; } -$(function initSearchBar() { +$(() => { function matchSubstrs(methodName) { var tokens = []; var len = methodName.length; @@ -40,8 +40,8 @@ $(function initSearchBar() { url: 'https://api.github.com/search/issues?q=%QUERY+repo:caolan/async', cache: true, wildcard: '%QUERY', - transform: function(response) { - return $.map(response.items, function(issue) { + transform(response) { + return $.map(response.items, (issue) => { // if (issue.state !== 'open') { // return null; // } @@ -50,7 +50,7 @@ $(function initSearchBar() { name: issue.number + ': ' + issue.title, number: issue.number }; - }).sort(function(a, b) { + }).sort((a, b) => { return b.number - a.number; }); } @@ -80,7 +80,7 @@ $(function initSearchBar() { templates: { header: '

Issues

' } - }).on('typeahead:select', function(ev, suggestion) { + }).on('typeahead:select', (ev, suggestion) => { var host; if (location.origin != "null") { host = location.origin; diff --git a/support/jsdoc/jsdoc-fix-html.js b/support/jsdoc/jsdoc-fix-html.js index 15234a0c0..3741a188e 100644 --- a/support/jsdoc/jsdoc-fix-html.js +++ b/support/jsdoc/jsdoc-fix-html.js @@ -37,7 +37,7 @@ function generateHTMLFile(filename, $page, callback) { } function extractModuleFiles(files) { - return _.filter(files, function(file) { + return _.filter(files, (file) => { return _.startsWith(file, 'module') && file !== mainModuleFile; }); } @@ -45,15 +45,15 @@ function extractModuleFiles(files) { function combineFakeModules(files, callback) { var moduleFiles = extractModuleFiles(files); - fs.readFile(path.join(docsDir, mainModuleFile), 'utf8', function(err, mainModuleData) { + fs.readFile(path.join(docsDir, mainModuleFile), 'utf8', (err, mainModuleData) => { if (err) return callback(err); var $mainPage = $(mainModuleData); // each 'module' (category) has a separate page, with all of the // important information in a 'main' div. Combine all of these divs into // one on the actual module page (async) - async.eachSeries(moduleFiles, function(file, fileCallback) { - fs.readFile(path.join(docsDir, file), 'utf8', function(err, moduleData) { + async.eachSeries(moduleFiles, (file, fileCallback) => { + fs.readFile(path.join(docsDir, file), 'utf8', (err, moduleData) => { if (err) return fileCallback(err); var $modulePage = $(moduleData); var moduleName = $modulePage.find(sectionTitleClass).text(); @@ -61,7 +61,7 @@ function combineFakeModules(files, callback) { $mainPage.find(mainScrollableSection).append($modulePage.find(mainScrollableSection).html()); return fileCallback(); }); - }, function(err) { + }, (err) => { if (err) return callback(err); generateHTMLFile(path.join(docsDir, docFilename), $mainPage, callback); }); @@ -83,7 +83,7 @@ function applyPreCheerioFixes(data) { .replace(rIncorrectCFText, fixedCFText) // for return types, JSDoc doesn't allow replacing the link text, so it // needs to be done here - .replace(rIncorrectModuleText, function(match, moduleName, methodName) { + .replace(rIncorrectModuleText, (match, moduleName, methodName) => { return '>'+methodName+'<'; }); } @@ -128,7 +128,7 @@ function fixToc(file, $page, moduleFiles) { var prependFilename = (file === docFilename) ? '' : docFilename; // make everything point to the same 'docs.html' page - _.each(moduleFiles, function(filename) { + _.each(moduleFiles, (filename) => { $page.find('[href^="'+filename+'"]').each(function() { var $ele = $(this); var href = $ele.attr('href'); @@ -156,9 +156,9 @@ function fixModuleLinks(files, callback) { var moduleFiles = extractModuleFiles(files); - async.each(files, function(file, fileCallback) { + async.each(files, (file, fileCallback) => { var filePath = path.join(docsDir, file); - fs.readFile(filePath, 'utf8', function(err, fileData) { + fs.readFile(filePath, 'utf8', (err, fileData) => { if (err) return fileCallback(err); var $file = $(applyPreCheerioFixes(fileData)); @@ -179,18 +179,18 @@ fs.copySync(path.join(__dirname, './jsdoc-custom.js'), path.join(docsDir, 'scrip fs.copySync(path.join(__dirname, '..', '..', 'logo', 'favicon.ico'), path.join(docsDir, 'favicon.ico'), { clobber: true }); fs.copySync(path.join(__dirname, '..', '..', 'logo', 'async-logo.svg'), path.join(docsDir, 'img', 'async-logo.svg'), { clobber: true }); -fs.readdir(docsDir, function(err, files) { +fs.readdir(docsDir, (err, files) => { if (err) { throw err; } - var HTMLFiles = _.filter(files, function(file) { + var HTMLFiles = _.filter(files, (file) => { return path.extname(file) === '.html'; }); async.waterfall([ function(callback) { - combineFakeModules(HTMLFiles, function(err) { + combineFakeModules(HTMLFiles, (err) => { if (err) return callback(err); HTMLFiles.push(docFilename); return callback(null); @@ -199,7 +199,7 @@ fs.readdir(docsDir, function(err, files) { function(callback) { fixModuleLinks(HTMLFiles, callback); } - ], function(err) { + ], (err) => { if (err) throw err; console.log('Docs generated successfully'); }); diff --git a/support/jsdoc/jsdoc-import-path-plugin.js b/support/jsdoc/jsdoc-import-path-plugin.js index 3f0937ff0..905e15776 100644 --- a/support/jsdoc/jsdoc-import-path-plugin.js +++ b/support/jsdoc/jsdoc-import-path-plugin.js @@ -1,7 +1,7 @@ const path = require('path'); exports.handlers = { - jsdocCommentFound: function(e) { + jsdocCommentFound(e) { var moduleName = path.parse(e.filename).name; diff --git a/test/apply.js b/test/apply.js index 18e5d1279..8c32177e3 100644 --- a/test/apply.js +++ b/test/apply.js @@ -1,10 +1,10 @@ var async = require('../lib'); var expect = require('chai').expect; -describe('concat', function() { - it('apply', function(done) { - var fn = function(){ - expect(Array.prototype.slice.call(arguments)).to.eql([1,2,3,4]); +describe('concat', () => { + it('apply', (done) => { + var fn = function (...args) { + expect(args).to.eql([1,2,3,4]); }; async.apply(fn, 1, 2, 3, 4)(); async.apply(fn, 1, 2, 3)(4); @@ -12,7 +12,7 @@ describe('concat', function() { async.apply(fn, 1)(2, 3, 4); async.apply(fn)(1, 2, 3, 4); expect( - async.apply(function(name){return 'hello ' + name;}, 'world')() + async.apply((name) => {return 'hello ' + name;}, 'world')() ).to.equal( 'hello world' ); diff --git a/test/applyEach.js b/test/applyEach.js index ca5ada3d7..e164ddac1 100644 --- a/test/applyEach.js +++ b/test/applyEach.js @@ -2,32 +2,32 @@ var async = require('../lib'); var expect = require('chai').expect; var assert = require('assert'); -describe('applyEach', function () { +describe('applyEach', () => { - it('applyEach', function (done) { + it('applyEach', (done) => { var call_order = []; var one = function (val, cb) { expect(val).to.equal(5); - setTimeout(function () { + setTimeout(() => { call_order.push('one'); cb(null, 1); }, 12); }; var two = function (val, cb) { expect(val).to.equal(5); - setTimeout(function () { + setTimeout(() => { call_order.push('two'); cb(null, 2); }, 2); }; var three = function (val, cb) { expect(val).to.equal(5); - setTimeout(function () { + setTimeout(() => { call_order.push('three'); cb(null, 3); }, 18); }; - async.applyEach([one, two, three], 5, function (err, results) { + async.applyEach([one, two, three], 5, (err, results) => { assert(err === null, err + " passed instead of 'null'"); expect(call_order).to.eql(['two', 'one', 'three']); expect(results).to.eql([1, 2, 3]); @@ -35,30 +35,30 @@ describe('applyEach', function () { }); }); - it('applyEachSeries', function (done) { + it('applyEachSeries', (done) => { var call_order = []; var one = function (val, cb) { expect(val).to.equal(5); - setTimeout(function () { + setTimeout(() => { call_order.push('one'); cb(null, 1); }, 10); }; var two = function (val, cb) { expect(val).to.equal(5); - setTimeout(function () { + setTimeout(() => { call_order.push('two'); cb(null, 2); }, 5); }; var three = function (val, cb) { expect(val).to.equal(5); - setTimeout(function () { + setTimeout(() => { call_order.push('three'); cb(null, 3); }, 15); }; - async.applyEachSeries([one, two, three], 5, function (err, results) { + async.applyEachSeries([one, two, three], 5, (err, results) => { assert(err === null, err + " passed instead of 'null'"); expect(call_order).to.eql(['one', 'two', 'three']); expect(results).to.eql([1, 2, 3]); @@ -66,30 +66,30 @@ describe('applyEach', function () { }); }); - it('applyEach partial application', function (done) { + it('applyEach partial application', (done) => { var call_order = []; var one = function (val, cb) { expect(val).to.equal(5); - setTimeout(function () { + setTimeout(() => { call_order.push('one'); cb(null, 1); }, 10); }; var two = function (val, cb) { expect(val).to.equal(5); - setTimeout(function () { + setTimeout(() => { call_order.push('two'); cb(null, 2); }, 5); }; var three = function (val, cb) { expect(val).to.equal(5); - setTimeout(function () { + setTimeout(() => { call_order.push('three'); cb(null, 3); }, 15); }; - async.applyEach([one, two, three])(5, function (err, results) { + async.applyEach([one, two, three])(5, (err, results) => { if (err) throw err; expect(call_order).to.eql(['two', 'one', 'three']); expect(results).to.eql([1, 2, 3]); diff --git a/test/asyncify.js b/test/asyncify.js index 112b8adcb..14f35eedc 100644 --- a/test/asyncify.js +++ b/test/asyncify.js @@ -2,32 +2,31 @@ var async = require('../lib'); var assert = require('assert'); var expect = require('chai').expect; -describe('asyncify', function(){ +describe('asyncify', () => { - it('asyncify', function(done) { + it('asyncify', (done) => { var parse = async.asyncify(JSON.parse); - parse("{\"a\":1}", function (err, result) { + parse("{\"a\":1}", (err, result) => { assert(!err); expect(result.a).to.equal(1); done(); }); }); - it('asyncify null', function(done) { - var parse = async.asyncify(function() { + it('asyncify null', (done) => { + var parse = async.asyncify(() => { return null; }); - parse("{\"a\":1}", function (err, result) { + parse("{\"a\":1}", (err, result) => { assert(!err); expect(result).to.equal(null); done(); }); }); - it('variable numbers of arguments', function(done) { - async.asyncify(function (/*x, y, z*/) { - return arguments; - })(1, 2, 3, function (err, result) { + it('variable numbers of arguments', (done) => { + const fn = (...args/*x, y, z*/) => args + async.asyncify(fn)(1, 2, 3, (err, result) => { expect(result.length).to.equal(3); expect(result[0]).to.equal(1); expect(result[1]).to.equal(2); @@ -36,19 +35,19 @@ describe('asyncify', function(){ }); }); - it('catch errors', function(done) { - async.asyncify(function () { + it('catch errors', (done) => { + async.asyncify(() => { throw new Error("foo"); - })(function (err) { + })((err) => { assert(err); expect(err.message).to.equal("foo"); done(); }); }); - it('dont catch errors in the callback', function(done) { + it('dont catch errors in the callback', (done) => { try { - async.asyncify(function () {})(function (err) { + async.asyncify(() => {})((err) => { if (err) { return done(new Error("should not get an error here")); } @@ -60,17 +59,17 @@ describe('asyncify', function(){ } }); - describe('promisified', function() { + describe('promisified', () => { function promisifiedTests(Promise) { - it('resolve', function(done) { + it('resolve', (done) => { var promisified = function(argument) { - return new Promise(function (resolve) { - setTimeout(function () { + return new Promise(((resolve) => { + setTimeout(() => { resolve(argument + " resolved"); }, 15); - }); + })); }; - async.asyncify(promisified)("argument", function (err, value) { + async.asyncify(promisified)("argument", (err, value) => { if (err) { return done(new Error("should not get an error here")); } @@ -79,42 +78,42 @@ describe('asyncify', function(){ }); }); - it('reject', function(done) { + it('reject', (done) => { var promisified = function(argument) { - return new Promise(function (resolve, reject) { + return new Promise(((resolve, reject) => { reject(argument + " rejected"); - }); + })); }; - async.asyncify(promisified)("argument", function (err) { + async.asyncify(promisified)("argument", (err) => { assert(err); expect(err.message).to.equal("argument rejected"); done(); }); }); - it('callback error @nodeonly', function(done) { + it('callback error @nodeonly', (done) => { expectUncaughtException(); var promisified = function(argument) { - return new Promise(function (resolve) { + return new Promise(((resolve) => { resolve(argument + " resolved"); - }); + })); }; var call_count = 0; - async.asyncify(promisified)("argument", function () { + async.asyncify(promisified)("argument", () => { call_count++; if (call_count === 1) { throw new Error("error in callback"); } }); - setTimeout(function () { + setTimeout(() => { expect(call_count).to.equal(1); done(); }, 15); }); - it('dont catch errors in the callback @nodeonly', function(done) { + it('dont catch errors in the callback @nodeonly', (done) => { expectUncaughtException(checkErr); var callbackError = new Error('thrown from callback'); @@ -127,7 +126,7 @@ describe('asyncify', function(){ throw callbackError; } - async.asyncify(function () { + async.asyncify(() => { return Promise.reject(new Error('rejection')); })(callback); }); @@ -142,7 +141,7 @@ describe('asyncify', function(){ var Promise = require('bluebird'); // Bluebird reports unhandled rejections to stderr. We handle it because we expect // unhandled rejections: - Promise.onPossiblyUnhandledRejection(function ignoreRejections() {}); + Promise.onPossiblyUnhandledRejection(() => {}); promisifiedTests.call(this, Promise); }); @@ -160,8 +159,8 @@ describe('asyncify', function(){ // do a weird dance to catch the async thrown error before mocha var listeners = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); - process.once('uncaughtException', function onErr(err) { - listeners.forEach(function(listener) { + process.once('uncaughtException', (err) => { + listeners.forEach((listener) => { process.on('uncaughtException', listener); }); // can't throw errors in a uncaughtException handler, defer diff --git a/test/auto.js b/test/auto.js index 3b561cbef..95aad09d4 100644 --- a/test/auto.js +++ b/test/auto.js @@ -2,19 +2,19 @@ var async = require('../lib'); var expect = require('chai').expect; var _ = require('lodash'); -describe('auto', function () { +describe('auto', () => { - it('basics', function(done){ + it('basics', (done) => { var callOrder = []; async.auto({ task1: ['task2', function(results, callback){ - setTimeout(function(){ + setTimeout(() => { callOrder.push('task1'); callback(); }, 25); }], - task2: function(callback){ - setTimeout(function(){ + task2(callback){ + setTimeout(() => { callOrder.push('task2'); callback(); }, 50); @@ -28,7 +28,7 @@ describe('auto', function () { callback(); }], task5: ['task2', function(results, callback){ - setTimeout(function(){ + setTimeout(() => { callOrder.push('task5'); callback(); }, 0); @@ -38,22 +38,22 @@ describe('auto', function () { callback(); }] }, - function(err){ + (err) => { expect(err).to.equal(null); expect(callOrder).to.eql(['task2','task3','task6','task5','task1','task4']); done(); }); }); - it('auto concurrency', function (done) { + it('auto concurrency', (done) => { var concurrency = 2; var runningTasks = []; function makeCallback(taskName) { - return function(/*..., callback*/) { - var callback = _.last(arguments); + return function(...args/*..., callback*/) { + var callback = _.last(args); runningTasks.push(taskName); - setTimeout(function(){ + setTimeout(() => { // Each task returns the array of running tasks as results. var result = runningTasks.slice(0); runningTasks.splice(runningTasks.indexOf(taskName), 1); @@ -69,25 +69,25 @@ describe('auto', function () { task4: ['task1', 'task2', makeCallback('task4')], task5: ['task2', makeCallback('task5')], task6: ['task2', makeCallback('task6')] - }, concurrency, function(err, results){ - _.each(results, function(result) { + }, concurrency, (err, results) => { + _.each(results, (result) => { expect(result.length).to.be.below(concurrency + 1); }); done(); }); }); - it('auto petrify', function (done) { + it('auto petrify', (done) => { var callOrder = []; async.auto({ task1: ['task2', function (results, callback) { - setTimeout(function () { + setTimeout(() => { callOrder.push('task1'); callback(); }, 100); }], - task2: function (callback) { - setTimeout(function () { + task2 (callback) { + setTimeout(() => { callOrder.push('task2'); callback(); }, 200); @@ -101,25 +101,25 @@ describe('auto', function () { callback(); }] }, - function (err) { + (err) => { if (err) throw err; expect(callOrder).to.eql(['task2', 'task3', 'task1', 'task4']); done(); }); }); - it('auto results', function(done){ + it('auto results', (done) => { var callOrder = []; async.auto({ task1: ['task2', function(results, callback){ expect(results.task2).to.eql('task2'); - setTimeout(function(){ + setTimeout(() => { callOrder.push('task1'); callback(null, 'task1a', 'task1b'); }, 25); }], - task2: function(callback){ - setTimeout(function(){ + task2(callback){ + setTimeout(() => { callOrder.push('task2'); callback(null, 'task2'); }, 50); @@ -136,42 +136,42 @@ describe('auto', function () { callback(null, 'task4'); }] }, - function(err, results){ + (err, results) => { expect(callOrder).to.eql(['task2','task3','task1','task4']); expect(results).to.eql({task1: ['task1a','task1b'], task2: 'task2', task3: undefined, task4: 'task4'}); done(); }); }); - it('auto empty object', function(done){ - async.auto({}, function(err){ + it('auto empty object', (done) => { + async.auto({}, (err) => { expect(err).to.equal(null); done(); }); }); - it('auto error', function(done){ + it('auto error', (done) => { async.auto({ - task1: function(callback){ + task1(callback){ callback('testerror'); }, task2: ['task1', function(/*results, callback*/){ throw new Error('task2 should not be called'); }], - task3: function(callback){ + task3(callback){ callback('testerror2'); } }, - function(err){ + (err) => { expect(err).to.equal('testerror'); }); setTimeout(done, 100); }); - it('auto canceled', function(done){ + it('auto canceled', (done) => { const call_order = [] async.auto({ - task1: function(callback){ + task1(callback){ call_order.push(1) callback(false); }, @@ -179,12 +179,12 @@ describe('auto', function () { call_order.push(2) throw new Error('task2 should not be called'); }], - task3: function(callback){ + task3(callback){ call_order.push(3) callback('testerror2'); } }, - function(){ + () => { throw new Error('should not get here') }); setTimeout(() => { @@ -193,11 +193,10 @@ describe('auto', function () { }, 10); }); - it('does not start other tasks when it has been canceled', function(done) { + it('does not start other tasks when it has been canceled', (done) => { const call_order = [] - debugger async.auto({ - task1: function(callback) { + task1(callback) { call_order.push(1); // defer calling task2, so task3 has time to stop execution async.setImmediate(callback); @@ -206,7 +205,7 @@ describe('auto', function () { call_order.push(2); throw new Error('task2 should not be called'); }], - task3: function(callback) { + task3(callback) { call_order.push(3); callback(false); }, @@ -215,7 +214,7 @@ describe('auto', function () { throw new Error('task4 should not be called'); }] }, - function() { + () => { throw new Error('should not get here') }); @@ -225,23 +224,23 @@ describe('auto', function () { }, 25) }); - it('auto no callback', function(done){ + it('auto no callback', (done) => { async.auto({ - task1: function(callback){callback();}, + task1(callback){callback();}, task2: ['task1', function(results, callback){callback(); done();}] }); }); - it('auto concurrency no callback', function(done){ + it('auto concurrency no callback', (done) => { async.auto({ - task1: function(callback){callback();}, + task1(callback){callback();}, task2: ['task1', function(results, callback){callback(); done();}] }, 1); }); - it('auto error should pass partial results', function(done) { + it('auto error should pass partial results', (done) => { async.auto({ - task1: function(callback){ + task1(callback){ callback(null, 'result1'); }, task2: ['task1', function(results, callback){ @@ -251,7 +250,7 @@ describe('auto', function () { throw new Error('task3 should not be called'); }] }, - function(err, results){ + (err, results) => { expect(err).to.equal('testerror'); expect(results.task1).to.equal('result1'); expect(results.task2).to.equal('result2'); @@ -261,25 +260,25 @@ describe('auto', function () { // Issue 24 on github: https://github.com/caolan/async/issues#issue/24 // Issue 76 on github: https://github.com/caolan/async/issues#issue/76 - it('auto removeListener has side effect on loop iteratee', function(done) { + it('auto removeListener has side effect on loop iteratee', (done) => { async.auto({ task1: ['task3', function(/*callback*/) { done(); }], task2: ['task3', function(/*callback*/) { /* by design: DON'T call callback */ }], - task3: function(callback) { callback(); } + task3(callback) { callback(); } }); }); // Issue 410 on github: https://github.com/caolan/async/issues/410 - it('auto calls callback multiple times', function(done) { + it('auto calls callback multiple times', (done) => { var finalCallCount = 0; try { async.auto({ - task1: function(callback) { callback(null); }, + task1(callback) { callback(null); }, task2: ['task1', function(results, callback) { callback(null); }] }, // Error throwing final callback. This should only run once - function() { + () => { finalCallCount++; var e = new Error('An error'); e._test_error = true; @@ -290,20 +289,20 @@ describe('auto', function () { throw e; } } - setTimeout(function () { + setTimeout(() => { expect(finalCallCount).to.equal(1); done(); }, 10); }); - it('auto calls callback multiple times with parallel functions', function(done) { + it('auto calls callback multiple times with parallel functions', (done) => { async.auto({ - task1: function(callback) { setTimeout(callback,0,'err'); }, - task2: function(callback) { setTimeout(callback,0,'err'); } + task1(callback) { setTimeout(callback,0,'err'); }, + task2(callback) { setTimeout(callback,0,'err'); } }, // Error throwing final callback. This should only run once - function(err) { + (err) => { expect(err).to.equal('err'); done(); }); @@ -311,24 +310,24 @@ describe('auto', function () { // Issue 462 on github: https://github.com/caolan/async/issues/462 - it('auto modifying results causes final callback to run early', function(done) { + it('auto modifying results causes final callback to run early', (done) => { async.auto({ - task1: function(callback){ + task1(callback){ callback(null, 'task1'); }, task2: ['task1', function(results, callback){ results.inserted = true; - setTimeout(function(){ + setTimeout(() => { callback(null, 'task2'); }, 50); }], - task3: function(callback){ - setTimeout(function(){ + task3(callback){ + setTimeout(() => { callback(null, 'task3'); }, 100); } }, - function(err, results){ + (err, results) => { expect(results.inserted).to.equal(true); expect(results.task3).to.equal('task3'); done(); @@ -336,8 +335,8 @@ describe('auto', function () { }); // Issue 263 on github: https://github.com/caolan/async/issues/263 - it('auto prevent dead-locks due to inexistant dependencies', function(done) { - expect(function () { + it('auto prevent dead-locks due to inexistant dependencies', (done) => { + expect(() => { async.auto({ task1: ['noexist', function(results, callback){ callback(null, 'task1'); @@ -348,8 +347,8 @@ describe('auto', function () { }); // Issue 263 on github: https://github.com/caolan/async/issues/263 - it('auto prevent dead-locks due to cyclic dependencies', function(done) { - expect(function () { + it('auto prevent dead-locks due to cyclic dependencies', (done) => { + expect(() => { async.auto({ task1: ['task2', function(results, callback){ callback(null, 'task1'); @@ -363,13 +362,13 @@ describe('auto', function () { }); // Issue 1092 on github: https://github.com/caolan/async/issues/1092 - it('extended cycle detection', function(done) { + it('extended cycle detection', (done) => { var task = function (name) { return function (results, callback) { callback(null, 'task ' + name); }; }; - expect(function () { + expect(() => { async.auto({ a: ['c', task('a')], b: ['a', task('b')], @@ -380,50 +379,50 @@ describe('auto', function () { }); // Issue 988 on github: https://github.com/caolan/async/issues/988 - it('auto stops running tasks on error', function(done) { + it('auto stops running tasks on error', (done) => { async.auto({ - task1: function (callback) { + task1 (callback) { callback('error'); }, - task2: function (/*callback*/) { + task2 (/*callback*/) { throw new Error('test2 should not be called'); } - }, 1, function (error) { + }, 1, (error) => { expect(error).to.equal('error'); done(); }); }); - it('ignores results after an error', function (done) { + it('ignores results after an error', (done) => { async.auto({ - task1: function (cb) { + task1 (cb) { setTimeout(cb, 25, 'error'); }, - task2: function (cb) { + task2 (cb) { setTimeout(cb, 30, null); }, task3: ['task2', function () { throw new Error("task should not have been called"); }] - }, function (err) { + }, (err) => { expect(err).to.equal('error'); setTimeout(done, 25, null); }); }); - it("does not allow calling callbacks twice", function () { - expect(function () { + it("does not allow calling callbacks twice", () => { + expect(() => { async.auto({ - bad: function (cb) { + bad (cb) { cb(); cb(); } - }, function () {}); + }, () => {}); }).to.throw(); }); - it('should handle array tasks with just a function', function (done) { + it('should handle array tasks with just a function', (done) => { async.auto({ a: [function (cb) { cb(null, 1); @@ -435,15 +434,15 @@ describe('auto', function () { }, done); }); - it("should avoid unncecessary deferrals", function (done) { + it("should avoid unncecessary deferrals", (done) => { var isSync = true; async.auto({ - step1: function (cb) { cb(null, 1); }, + step1 (cb) { cb(null, 1); }, step2: ["step1", function (results, cb) { cb(); }] - }, function () { + }, () => { expect(isSync).to.equal(true); done(); }); @@ -452,39 +451,39 @@ describe('auto', function () { }); // Issue 1358 on github: https://github.com/caolan/async/issues/1358 - it('should report errors when a task name is an array method', function (done) { + it('should report errors when a task name is an array method', (done) => { async.auto({ - 'one': function (next) { + 'one' (next) { next('Something bad happened here'); }, - 'filter': function (next) { - _.delay(function () { + 'filter' (next) { + _.delay(() => { next(null, 'All fine here though'); }, 25); }, 'finally': ['one', 'filter', function (a, next) { _.defer(next); }] - }, function (err) { + }, (err) => { expect(err).to.equal('Something bad happened here'); _.delay(done, 30); }); }); - it('should report errors when a task name is an obj prototype method', function (done) { + it('should report errors when a task name is an obj prototype method', (done) => { async.auto({ - 'one': function (next) { + 'one' (next) { next('Something bad happened here'); }, - 'hasOwnProperty': function (next) { - _.delay(function () { + 'hasOwnProperty' (next) { + _.delay(() => { next(null, 'All fine here though'); }, 25); }, 'finally': ['one', 'hasOwnProperty', function (a, next) { _.defer(next); }] - }, function (err) { + }, (err) => { expect(err).to.equal('Something bad happened here'); _.delay(done, 30); }); diff --git a/test/autoInject.js b/test/autoInject.js index 9c2d1fbe4..fe98e2708 100644 --- a/test/autoInject.js +++ b/test/autoInject.js @@ -1,60 +1,60 @@ var async = require('../lib'); var expect = require('chai').expect; -describe('autoInject', function () { +describe('autoInject', () => { - it("basics", function (done) { + it("basics", (done) => { var callOrder = []; async.autoInject({ - task1: function(task2, callback){ + task1(task2, callback){ expect(task2).to.equal(2); - setTimeout(function(){ + setTimeout(() => { callOrder.push('task1'); callback(null, 1); }, 25); }, - task2: function(callback){ - setTimeout(function(){ + task2(callback){ + setTimeout(() => { callOrder.push('task2'); callback(null, 2); }, 50); }, - task3: function(task2, callback){ + task3(task2, callback){ expect(task2).to.equal(2); callOrder.push('task3'); callback(null, 3); }, - task4: function(task1, task2, callback){ + task4(task1, task2, callback){ expect(task1).to.equal(1); expect(task2).to.equal(2); callOrder.push('task4'); callback(null, 4); }, - task5: function(task2, callback){ + task5(task2, callback){ expect(task2).to.equal(2); - setTimeout(function(){ + setTimeout(() => { callOrder.push('task5'); callback(null, 5); }, 0); }, - task6: function(task2, callback){ + task6(task2, callback){ expect(task2).to.equal(2); callOrder.push('task6'); callback(null, 6); } }, - function(err, results){ + (err, results) => { expect(results.task6).to.equal(6); expect(callOrder).to.eql(['task2','task3','task6','task5','task1','task4']); done(); }); }); - it('should work with array tasks', function (done) { + it('should work with array tasks', (done) => { var callOrder = []; async.autoInject({ - task1: function (cb) { + task1 (cb) { callOrder.push('task1'); cb(null, 1); }, @@ -63,17 +63,17 @@ describe('autoInject', function () { callOrder.push('task2'); cb(null, 2); }], - task3: function (cb) { + task3 (cb) { callOrder.push('task3'); cb(null, 3); } - }, function () { + }, () => { expect(callOrder).to.eql(['task1','task3','task2']); done(); }); }); - it('should handle array tasks with just a function', function (done) { + it('should handle array tasks with just a function', (done) => { async.autoInject({ a: [function (cb) { cb(null, 1); @@ -85,10 +85,10 @@ describe('autoInject', function () { }, done); }); - it('should throw error for function without explicit parameters', function (done) { + it('should throw error for function without explicit parameters', (done) => { try { async.autoInject({ - a: function (){} + a (){} }); } catch (e) { // It's ok. It detected a void function diff --git a/test/cargo.js b/test/cargo.js index 55e6e9686..ace4c93b0 100644 --- a/test/cargo.js +++ b/test/cargo.js @@ -2,29 +2,29 @@ var async = require('../lib'); var expect = require('chai').expect; var assert = require('assert'); -describe('cargo', function () { +describe('cargo', () => { - it('cargo', function (done) { + it('cargo', (done) => { var call_order = [], delays = [40, 40, 20]; // worker: --12--34--5- // order of completion: 1,2,3,4,5 - var c = async.cargo(function (tasks, callback) { - setTimeout(function () { + var c = async.cargo((tasks, callback) => { + setTimeout(() => { call_order.push('process ' + tasks.join(' ')); callback('error', 'arg'); }, delays.shift()); }, 2); - c.push(1, function (err, arg) { + c.push(1, (err, arg) => { expect(err).to.equal('error'); expect(arg).to.equal('arg'); expect(c.length()).to.equal(3); call_order.push('callback ' + 1); }); - c.push(2, function (err, arg) { + c.push(2, (err, arg) => { expect(err).to.equal('error'); expect(arg).to.equal('arg'); expect(c.length()).to.equal(3); @@ -34,23 +34,23 @@ describe('cargo', function () { expect(c.length()).to.equal(2); // async push - setTimeout(function () { - c.push(3, function (err, arg) { + setTimeout(() => { + c.push(3, (err, arg) => { expect(err).to.equal('error'); expect(arg).to.equal('arg'); expect(c.length()).to.equal(1); call_order.push('callback ' + 3); }); }, 15); - setTimeout(function () { - c.push(4, function (err, arg) { + setTimeout(() => { + c.push(4, (err, arg) => { expect(err).to.equal('error'); expect(arg).to.equal('arg'); expect(c.length()).to.equal(1); call_order.push('callback ' + 4); }); expect(c.length()).to.equal(2); - c.push(5, function (err, arg) { + c.push(5, (err, arg) => { expect(err).to.equal('error'); expect(arg).to.equal('arg'); expect(c.length()).to.equal(0); @@ -70,15 +70,15 @@ describe('cargo', function () { }; }); - it('without callback', function (done) { + it('without callback', (done) => { var call_order = [], delays = [40,20,60,20]; // worker: --1-2---34-5- // order of completion: 1,2,3,4,5 - var c = async.cargo(function (tasks, callback) { - setTimeout(function () { + var c = async.cargo((tasks, callback) => { + setTimeout(() => { call_order.push('process ' + tasks.join(' ')); callback('error', 'arg'); }, delays.shift()); @@ -86,16 +86,16 @@ describe('cargo', function () { c.push(1); - setTimeout(function () { + setTimeout(() => { c.push(2); }, 30); - setTimeout(function () { + setTimeout(() => { c.push(3); c.push(4); c.push(5); }, 50); - setTimeout(function () { + setTimeout(() => { expect(call_order).to.eql([ 'process 1', 'process 2', @@ -106,28 +106,28 @@ describe('cargo', function () { }, 200); }); - it('bulk task', function (done) { + it('bulk task', (done) => { var call_order = [], delays = [30,20]; // worker: -123-4- // order of completion: 1,2,3,4 - var c = async.cargo(function (tasks, callback) { - setTimeout(function () { + var c = async.cargo((tasks, callback) => { + setTimeout(() => { call_order.push('process ' + tasks.join(' ')); callback('error', tasks.join(' ')); }, delays.shift()); }, 3); - c.push( [1,2,3,4], function (err, arg) { + c.push( [1,2,3,4], (err, arg) => { expect(err).to.equal('error'); call_order.push('callback ' + arg); }); expect(c.length()).to.equal(4); - setTimeout(function () { + setTimeout(() => { expect(call_order).to.eql([ 'process 1 2 3', 'callback 1 2 3', 'callback 1 2 3', 'callback 1 2 3', @@ -138,9 +138,9 @@ describe('cargo', function () { }, 200); }); - it('drain once', function (done) { + it('drain once', (done) => { - var c = async.cargo(function (tasks, callback) { + var c = async.cargo((tasks, callback) => { callback(); }, 3); @@ -153,15 +153,15 @@ describe('cargo', function () { c.push(i); } - setTimeout(function(){ + setTimeout(() => { expect(drainCounter).to.equal(1); done(); }, 50); }); - it('drain twice', function (done) { + it('drain twice', (done) => { - var c = async.cargo(function (tasks, callback) { + var c = async.cargo((tasks, callback) => { callback(); }, 3); @@ -179,15 +179,15 @@ describe('cargo', function () { loadCargo(); setTimeout(loadCargo, 50); - setTimeout(function(){ + setTimeout(() => { expect(drainCounter).to.equal(2); done(); }, 100); }); - it('events', function (done) { + it('events', (done) => { var calls = []; - var q = async.cargo(function(task, cb) { + var q = async.cargo((task, cb) => { // nop calls.push('process ' + task); async.setImmediate(cb); @@ -227,16 +227,16 @@ describe('cargo', function () { ]); done(); }; - q.push('foo', function () {calls.push('foo cb');}); - q.push('bar', function () {calls.push('bar cb');}); - q.push('zoo', function () {calls.push('zoo cb');}); - q.push('poo', function () {calls.push('poo cb');}); - q.push('moo', function () {calls.push('moo cb');}); + q.push('foo', () => {calls.push('foo cb');}); + q.push('bar', () => {calls.push('bar cb');}); + q.push('zoo', () => {calls.push('zoo cb');}); + q.push('poo', () => {calls.push('poo cb');}); + q.push('moo', () => {calls.push('moo cb');}); }); - it('expose payload', function (done) { + it('expose payload', (done) => { var called_once = false; - var cargo = async.cargo(function(tasks, cb) { + var cargo = async.cargo((tasks, cb) => { if (!called_once) { expect(cargo.payload).to.equal(1); assert(tasks.length === 1, 'should start with payload = 1'); @@ -256,28 +256,28 @@ describe('cargo', function () { cargo.push([1, 2, 3]); - setTimeout(function () { + setTimeout(() => { cargo.payload = 2; }, 15); }); - it('workersList', function(done) { + it('workersList', (done) => { var called_once = false; function getWorkersListData(cargo) { - return cargo.workersList().map(function(v) { + return cargo.workersList().map((v) => { return v.data; }); } - var cargo = async.cargo(function(tasks, cb) { + var cargo = async.cargo((tasks, cb) => { if (!called_once) { expect(tasks).to.eql(['foo', 'bar']); } else { expect(tasks).to.eql(['baz']); } expect(getWorkersListData(cargo)).to.eql(tasks); - async.setImmediate(function() { + async.setImmediate(() => { // ensure nothing has changed expect(getWorkersListData(cargo)).to.eql(tasks); called_once = true; @@ -296,10 +296,10 @@ describe('cargo', function () { cargo.push('baz'); }); - it('running', function(done) { - var cargo = async.cargo(function(tasks, cb) { + it('running', (done) => { + var cargo = async.cargo((tasks, cb) => { expect(cargo.running()).to.equal(1); - async.setImmediate(function() { + async.setImmediate(() => { expect(cargo.running()).to.equal(1); cb(); }); diff --git a/test/compose.js b/test/compose.js index 5be919219..0517a203d 100644 --- a/test/compose.js +++ b/test/compose.js @@ -1,26 +1,26 @@ var async = require('../lib'); var expect = require('chai').expect; -describe('compose', function(){ - context('all functions succeed', function(){ - it('yields the result of the composition of the functions', function(done){ +describe('compose', () => { + context('all functions succeed', () => { + it('yields the result of the composition of the functions', (done) => { var add2 = function (n, cb) { - setTimeout(function () { + setTimeout(() => { cb(null, n + 2); }); }; var mul3 = function (n, cb) { - setTimeout(function () { + setTimeout(() => { cb(null, n * 3); }); }; var add1 = function (n, cb) { - setTimeout(function () { + setTimeout(() => { cb(null, n + 1); }); }; var add2mul3add1 = async.compose(add1, mul3, add2); - add2mul3add1(3, function (err, result) { + add2mul3add1(3, (err, result) => { expect(err).to.not.exist; expect(result).to.eql(16); done(); @@ -28,28 +28,28 @@ describe('compose', function(){ }); }); - context('a function errors', function(){ - it('yields the error and does not call later functions', function(done){ + context('a function errors', () => { + it('yields the error and does not call later functions', (done) => { var add1called = false; var mul3error = new Error('mul3 error'); var add2 = function (n, cb) { - setTimeout(function () { + setTimeout(() => { cb(null, n + 2); }); }; var mul3 = function (n, cb) { - setTimeout(function () { + setTimeout(() => { cb(mul3error); }); }; var add1 = function (n, cb) { add1called = true; - setTimeout(function () { + setTimeout(() => { cb(null, n + 1); }); }; var add2mul3add1 = async.compose(add1, mul3, add2); - add2mul3add1(3, function (err, result) { + add2mul3add1(3, (err, result) => { expect(err).to.eql(mul3error); expect(result).to.not.exist; expect(add1called).to.be.false; @@ -58,24 +58,24 @@ describe('compose', function(){ }); }); - it('calls each function with the binding of the composed function', function(done){ + it('calls each function with the binding of the composed function', (done) => { var context = {}; var add2Context = null; var mul3Context = null; var add2 = function (n, cb) { add2Context = this; - setTimeout(function () { + setTimeout(() => { cb(null, n + 2); }); }; var mul3 = function (n, cb) { mul3Context = this; - setTimeout(function () { + setTimeout(() => { cb(null, n * 3); }); }; var add2mul3 = async.compose(mul3, add2); - add2mul3.call(context, 3, function (err, result) { + add2mul3.call(context, 3, (err, result) => { expect(err).to.not.exist; expect(result).to.eql(15); expect(add2Context).to.equal(context); diff --git a/test/concat.js b/test/concat.js index 75f8db7e9..229a9da7b 100644 --- a/test/concat.js +++ b/test/concat.js @@ -6,16 +6,16 @@ describe('concat', function() { this.timeout(250); function concatIteratee(callOrder, val, next) { - setTimeout(function() { + setTimeout(() => { callOrder.push(val); next(null, [val, val+1]); }, val * 25); } - context('concat', function() { + context('concat', () => { it('basics', function(done) { var callOrder = []; - async.concat([1, 3, 2], concatIteratee.bind(this, callOrder), function(err, result) { + async.concat([1, 3, 2], concatIteratee.bind(this, callOrder), (err, result) => { expect(err).to.eql(null); expect(callOrder).to.eql([1, 2, 3]); expect(result).to.eql([1, 2, 3, 4, 2, 3]); @@ -23,114 +23,114 @@ describe('concat', function() { }); }); - it('error', function(done) { - async.concat([1, 3, 2], function(val, next) { + it('error', (done) => { + async.concat([1, 3, 2], (val, next) => { if (val === 3) { return next(new Error('fail')); } next(null, [val, val+1]); - }, function(err, result) { + }, (err, result) => { expect(err).to.not.eql(null); expect(result).to.eql([1, 2]); done(); }); }); - it('original untouched', function(done) { + it('original untouched', (done) => { var arr = ['foo', 'bar', 'baz']; - async.concat(arr, function(val, next) { + async.concat(arr, (val, next) => { next(null, [val, val]); - }, function(err, result) { + }, (err, result) => { expect(arr).to.eql(['foo', 'bar', 'baz']); expect(result).to.eql(['foo', 'foo', 'bar', 'bar', 'baz', 'baz']); done(); }); }); - it('empty results', function(done) { + it('empty results', (done) => { var arr = ['foo', 'bar', 'baz']; - async.concat(arr, function(val, next) { + async.concat(arr, (val, next) => { next(null); - }, function(err, result) { + }, (err, result) => { expect(err).to.eql(null); expect(result).to.be.an('array').that.is.empty; done(); }); }); - it('empty arrays', function(done) { + it('empty arrays', (done) => { var arr = ['foo', 'bar', 'baz']; - async.concat(arr, function(val, next) { + async.concat(arr, (val, next) => { next(null, []); - }, function(err, result) { + }, (err, result) => { expect(err).to.eql(null); expect(result).to.be.an('array').that.is.empty; done(); }); }); - it('handles empty object', function(done) { - async.concat({}, function(val, next) { + it('handles empty object', (done) => { + async.concat({}, (val, next) => { assert(false, 'iteratee should not be called'); next(); - }, function(err, result) { + }, (err, result) => { expect(err).to.eql(null); expect(result).to.be.an('array').that.is.empty; done(); }); }); - it('variadic', function(done) { + it('variadic', (done) => { var arr = ['foo', 'bar', 'baz']; - async.concat(arr, function(val, next) { + async.concat(arr, (val, next) => { next(null, val, val); - }, function(err, result) { + }, (err, result) => { expect(err).to.eql(null); expect(result).to.eql(['foo', 'foo', 'bar', 'bar', 'baz', 'baz']); done(); }); }); - it('flattens arrays', function(done) { + it('flattens arrays', (done) => { var arr = ['foo', 'bar']; - async.concat(arr, function(val, next) { + async.concat(arr, (val, next) => { next(null, [val, [val]]); - }, function(err, result) { + }, (err, result) => { expect(err).to.eql(null); expect(result).to.eql(['foo', ['foo'], 'bar', ['bar']]); done(); }); }); - it('handles fasly values', function(done) { + it('handles fasly values', (done) => { var falsy = [null, undefined, 0, '']; - async.concat(falsy, function(val, next) { + async.concat(falsy, (val, next) => { next(null, val); - }, function(err, result) { + }, (err, result) => { expect(err).to.eql(null); expect(result).to.eql(falsy); done(); }); }); - it('handles objects', function(done) { + it('handles objects', (done) => { var obj = {a: 'foo', b: 'bar', c: 'baz'}; - async.concat(obj, function(val, next) { + async.concat(obj, (val, next) => { next(null, val); - }, function(err, result) { + }, (err, result) => { expect(err).to.eql(null); expect(result).to.eql(['foo', 'bar', 'baz']); done(); }); }); - it('main callback optional', function(done) { + it('main callback optional', (done) => { var arr = [1, 2, 3]; var runs = []; - async.concat(arr, function(val, next) { + async.concat(arr, (val, next) => { runs.push(val); var _done = (runs.length === arr.length); - async.setImmediate(function() { + async.setImmediate(() => { next(null); if (_done) { expect(runs).to.eql(arr); @@ -140,35 +140,35 @@ describe('concat', function() { }); }); - it('iteratee callback is only called once', function(done) { - async.concat([1, 2], function(val, next) { + it('iteratee callback is only called once', (done) => { + async.concat([1, 2], (val, next) => { try { next(val); } catch (exception) { - expect(function() { + expect(() => { next(exception); }).to.throw(/already called/); done(); } - }, function() { + }, () => { throw new Error(); }); }); - it('preserves order', function(done) { + it('preserves order', (done) => { var arr = [30, 15]; - async.concat(arr, function(x, cb) { - setTimeout(function() { + async.concat(arr, (x, cb) => { + setTimeout(() => { cb(null, x); }, x); - }, function(err, result) { + }, (err, result) => { expect(err).to.eql(null); expect(result).to.eql(arr); done(); }); }); - it('handles Map', function(done) { + it('handles Map', (done) => { if (typeof Map !== 'function') { return done(); } @@ -179,28 +179,28 @@ describe('concat', function() { ['c', 'd'] ]); - async.concat(map, function(val, next) { + async.concat(map, (val, next) => { next(null, val); - }, function(err, result) { + }, (err, result) => { expect(err).to.eql(null); expect(result).to.eql(['a', 'b', 'b', 'c', 'c', 'd']); done(); }); }); - it('handles sparse results', function(done) { + it('handles sparse results', (done) => { var arr = [1, 2, 3, 4]; - async.concat(arr, function(val, next) { + async.concat(arr, (val, next) => { if (val === 1 || val === 3) { return next(null, val+1); } else if (val === 2) { - async.setImmediate(function() { + async.setImmediate(() => { return next(null, val+1); }); } else { return next('error'); } - }, function(err, result) { + }, (err, result) => { expect(err).to.not.eql(null); expect(result).to.eql([2, 4]); async.setImmediate(done); @@ -208,19 +208,19 @@ describe('concat', function() { }); }); - context('concatLimit', function() { + context('concatLimit', () => { var arr = ['foo', 'bar', 'baz']; - it('basics', function(done) { + it('basics', (done) => { var running = 0; var concurrency = {'foo': 2, 'bar': 2, 'baz': 1}; - async.concatLimit(arr, 2, function(val, next) { + async.concatLimit(arr, 2, (val, next) => { running++; - async.setImmediate(function() { + async.setImmediate(() => { expect(running).to.equal(concurrency[val]); running--; next(null, val, val); }) - }, function(err, result) { + }, (err, result) => { expect(running).to.equal(0); expect(err).to.eql(null); expect(result).to.eql(['foo', 'foo', 'bar', 'bar', 'baz', 'baz']); @@ -228,45 +228,45 @@ describe('concat', function() { }); }); - it('error', function(done) { - async.concatLimit(arr, 1, function(val, next) { + it('error', (done) => { + async.concatLimit(arr, 1, (val, next) => { if (val === 'bar') { return next(new Error('fail')); } next(null, val); - }, function(err, result) { + }, (err, result) => { expect(err).to.not.eql(null); expect(result).to.eql(['foo']); done(); }); }); - it('handles objects', function(done) { - async.concatLimit({'foo': 1, 'bar': 2, 'baz': 3}, 2, function(val, next) { + it('handles objects', (done) => { + async.concatLimit({'foo': 1, 'bar': 2, 'baz': 3}, 2, (val, next) => { next(null, val+1); - }, function(err, result) { + }, (err, result) => { expect(err).to.eql(null); expect(result).to.eql([2, 3, 4]); done(); }); }); - it('handles empty object', function(done) { - async.concatLimit({}, 2, function(val, next) { + it('handles empty object', (done) => { + async.concatLimit({}, 2, (val, next) => { assert(false, 'iteratee should not be called'); next(); - }, function(err, result) { + }, (err, result) => { expect(err).to.eql(null); expect(result).to.be.an('array').that.is.empty; done(); }); }); - it('handles undefined', function(done) { - async.concatLimit(undefined, 2, function(val, next) { + it('handles undefined', (done) => { + async.concatLimit(undefined, 2, (val, next) => { assert(false, 'iteratee should not be called'); next(); - }, function(err, result) { + }, (err, result) => { expect(err).to.eql(null); expect(result).to.be.an('array').that.is.empty; done(); @@ -275,7 +275,7 @@ describe('concat', function() { it('limit exceeds size', function(done) { var callOrder = []; - async.concatLimit([3, 2, 2, 1], 10, concatIteratee.bind(this, callOrder), function(err, result) { + async.concatLimit([3, 2, 2, 1], 10, concatIteratee.bind(this, callOrder), (err, result) => { expect(err).to.eql(null); expect(result).to.eql([3, 4, 2, 3, 2, 3, 1, 2]); expect(callOrder).to.eql([1, 2, 2, 3]); @@ -285,7 +285,7 @@ describe('concat', function() { it('limit equal size', function(done) { var callOrder = []; - async.concatLimit([3, 2, 2, 1], 4, concatIteratee.bind(this, callOrder), function(err, result) { + async.concatLimit([3, 2, 2, 1], 4, concatIteratee.bind(this, callOrder), (err, result) => { expect(err).to.eql(null); expect(result).to.eql([3, 4, 2, 3, 2, 3, 1, 2]); expect(callOrder).to.eql([1, 2, 2, 3]); @@ -293,34 +293,32 @@ describe('concat', function() { }); }); - it('zero limit', function() { + it('zero limit', () => { expect(() => { - async.concatLimit([3, 2, 2, 1], 0, function(val, next) { + async.concatLimit([3, 2, 2, 1], 0, (val, next) => { assert(false, 'iteratee should not be called'); next(); - }, function() { + }, () => { assert(false, 'callback should not be called'); }); }).to.throw(/limit/) }); - it('does not continue replenishing after error', function(done) { + it('does not continue replenishing after error', (done) => { var started = 0; var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; var limit = 3; - var step = 0; - var maxSteps = arr.length; - async.concatLimit(arr, limit, function(val, next) { + async.concatLimit(arr, limit, (val, next) => { started++; if (started === 3) { return next(new Error('fail')); } - async.setImmediate(function() { + async.setImmediate(() => { next(); }); - }, function(err, result) { + }, (err, result) => { expect(err).to.not.eql(null); expect(result).to.be.an('array').that.is.empty; }); @@ -328,27 +326,21 @@ describe('concat', function() { // wait `maxSteps` event loop cycles before calling done to ensure // the iteratee is not called on more items in arr. function waitCycle() { - step++; - if (step >= maxSteps) { - expect(started).to.equal(3); - done(); - return; - } else { - async.setImmediate(waitCycle); - } + expect(started).to.equal(3); + done(); } - async.setImmediate(waitCycle); + setTimeout(waitCycle, 25); }); }); - context('concatSeries', function() { - it('basics', function(done) { + context('concatSeries', () => { + it('basics', (done) => { var callOrder = []; var running = 0; var iteratee = function (x, cb) { running++; - setTimeout(function() { + setTimeout(() => { expect(running).to.equal(1); running--; callOrder.push(x); @@ -360,7 +352,7 @@ describe('concat', function() { cb(null, r); }, x*25); }; - async.concatSeries([1,3,2], iteratee, function(err, results) { + async.concatSeries([1,3,2], iteratee, (err, results) => { expect(results).to.eql([1,3,2,1,2,1]); expect(running).to.equal(0); expect(callOrder).to.eql([1,3,2]); @@ -369,45 +361,45 @@ describe('concat', function() { }); }); - it('error', function(done) { - async.concatSeries(['foo', 'bar', 'baz'], function(val, next) { + it('error', (done) => { + async.concatSeries(['foo', 'bar', 'baz'], (val, next) => { if (val === 'bar') { return next(new Error('fail')); } next(null, [val, val]); - }, function(err, result) { + }, (err, result) => { expect(err).to.not.eql(null); expect(result).to.eql(['foo', 'foo']); done(); }); }); - it('handles objects', function(done) { - async.concatSeries({'foo': 1, 'bar': 2, 'baz': 3}, function(val, next) { + it('handles objects', (done) => { + async.concatSeries({'foo': 1, 'bar': 2, 'baz': 3}, (val, next) => { return next(null, [val, val+1]); - }, function(err, result) { + }, (err, result) => { expect(err).to.eql(null); expect(result).to.eql([1, 2, 2, 3, 3, 4]); done(); }); }); - it('handles empty object', function(done) { - async.concatSeries({}, function(val, next) { + it('handles empty object', (done) => { + async.concatSeries({}, (val, next) => { assert(false, 'iteratee should not be called'); next(); - }, function(err, result) { + }, (err, result) => { expect(err).to.eql(null); expect(result).to.be.an('array').that.is.empty; done(); }); }); - it('handles undefined', function(done) { - async.concatSeries(undefined, function(val, next) { + it('handles undefined', (done) => { + async.concatSeries(undefined, (val, next) => { assert(false, 'iteratee should not be called'); next(); - }, function(err, result) { + }, (err, result) => { expect(err).to.eql(null); expect(result).to.be.an('array').that.is.empty; done(); diff --git a/test/consoleFunctions.js b/test/consoleFunctions.js index 3c295c8a5..6d13151e9 100644 --- a/test/consoleFunctions.js +++ b/test/consoleFunctions.js @@ -1,7 +1,7 @@ var async = require('../lib'); var expect = require('chai').expect; -describe('console functions', function() { +describe('console functions', () => { var names = [ 'log', @@ -12,22 +12,22 @@ describe('console functions', function() { ]; // generates tests for console functions such as async.log - names.forEach(function(name) { + names.forEach((name) => { if (typeof console !== 'undefined') { - it(name, function(done) { + it(name, (done) => { var fn = function(arg1, callback){ expect(arg1).to.equal('one'); - setTimeout(function(){callback(null, 'test');}, 0); + setTimeout(() => {callback(null, 'test');}, 0); }; var fn_err = function(arg1, callback){ expect(arg1).to.equal('one'); - setTimeout(function(){callback('error');}, 0); + setTimeout(() => {callback('error');}, 0); }; var _console_fn = console[name]; var _error = console.error; - console[name] = function(val){ + console[name] = function(val, ...extra){ expect(val).to.equal('test'); - expect(arguments.length).to.equal(1); + expect(extra.length).to.equal(0); console.error = function(val){ expect(val).to.equal('error'); console[name] = _console_fn; @@ -39,7 +39,7 @@ describe('console functions', function() { async[name](fn, 'one'); }); - it(name + ' with multiple result params', function(done) { + it(name + ' with multiple result params', (done) => { var fn = function(callback){callback(null,'one','two','three');}; var _console_fn = console[name]; var called_with = []; @@ -55,7 +55,7 @@ describe('console functions', function() { // browser-only test if (typeof window !== 'undefined') { - it(name + ' without console.' + name, function(done) { + it(name + ' without console.' + name, (done) => { var _console = window.console; window.console = undefined; var fn = function(callback){callback(null, 'val');}; diff --git a/test/constant.js b/test/constant.js index d76076c15..342e51593 100644 --- a/test/constant.js +++ b/test/constant.js @@ -1,11 +1,11 @@ var async = require('../lib'); var expect = require('chai').expect; -describe('constant', function () { +describe('constant', () => { - it('basic usage', function(done){ + it('basic usage', (done) => { var f = async.constant(42, 1, 2, 3); - f(function (err, value, a, b, c) { + f((err, value, a, b, c) => { expect(err).to.equal(null); expect(value).to.equal(42); expect(a).to.equal(1); @@ -15,9 +15,9 @@ describe('constant', function () { }); }); - it('called with multiple arguments', function(done){ + it('called with multiple arguments', (done) => { var f = async.constant(42, 1, 2, 3); - f('argument to ignore', 'another argument', function (err, value, a) { + f('argument to ignore', 'another argument', (err, value, a) => { expect(err).to.equal(null); expect(value).to.equal(42); expect(a).to.equal(1); diff --git a/test/detect.js b/test/detect.js index b1ebf249a..4bda08fe3 100644 --- a/test/detect.js +++ b/test/detect.js @@ -2,10 +2,10 @@ var async = require('../lib'); var expect = require('chai').expect; var _ = require('lodash'); -describe("detect", function () { +describe("detect", () => { function detectIteratee(call_order, x, callback) { - setTimeout(function(){ + setTimeout(() => { call_order.push(x); callback(null, x == 2); }, x*5); @@ -13,12 +13,12 @@ describe("detect", function () { it('detect', function(done){ var call_order = []; - async.detect([3,2,1], detectIteratee.bind(this, call_order), function(err, result){ + async.detect([3,2,1], detectIteratee.bind(this, call_order), (err, result) => { call_order.push('callback'); expect(err).to.equal(null); expect(result).to.equal(2); }); - setTimeout(function(){ + setTimeout(() => { expect(call_order).to.eql([1,2,'callback',3]); done(); }, 25); @@ -26,21 +26,21 @@ describe("detect", function () { it('detect - mulitple matches', function(done){ var call_order = []; - async.detect([3,2,2,1,2], detectIteratee.bind(this, call_order), function(err, result){ + async.detect([3,2,2,1,2], detectIteratee.bind(this, call_order), (err, result) => { call_order.push('callback'); expect(err).to.equal(null); expect(result).to.equal(2); }); - setTimeout(function(){ + setTimeout(() => { expect(call_order).to.eql([1,2,'callback',2,2,3]); done(); }, 25); }); - it('detect error', function(done){ - async.detect([3,2,1], function(x, callback) { - setTimeout(function(){callback('error');}, 0); - }, function(err, result){ + it('detect error', (done) => { + async.detect([3,2,1], (x, callback) => { + setTimeout(() => {callback('error');}, 0); + }, (err, result) => { expect(err).to.equal('error'); expect(result).to.not.exist; done(); @@ -49,12 +49,12 @@ describe("detect", function () { it('detectSeries', function(done){ var call_order = []; - async.detectSeries([3,2,1], detectIteratee.bind(this, call_order), function(err, result){ + async.detectSeries([3,2,1], detectIteratee.bind(this, call_order), (err, result) => { call_order.push('callback'); expect(err).to.equal(null); expect(result).to.equal(2); }); - setTimeout(function(){ + setTimeout(() => { expect(call_order).to.eql([3,2,'callback']); done(); }, 50); @@ -62,36 +62,36 @@ describe("detect", function () { it('detectSeries - multiple matches', function(done){ var call_order = []; - async.detectSeries([3,2,2,1,2], detectIteratee.bind(this, call_order), function(err, result){ + async.detectSeries([3,2,2,1,2], detectIteratee.bind(this, call_order), (err, result) => { call_order.push('callback'); expect(err).to.equal(null); expect(result).to.equal(2); }); - setTimeout(function(){ + setTimeout(() => { expect(call_order).to.eql([3,2,'callback']); done(); }, 50); }); - it('detect no callback', function(done) { + it('detect no callback', (done) => { var calls = []; - async.detect([1, 2, 3], function (val, cb) { + async.detect([1, 2, 3], (val, cb) => { calls.push(val); cb(); }); - setTimeout(function () { + setTimeout(() => { expect(calls).to.eql([1, 2, 3]); done(); }, 10); }); - it('detectSeries - ensure stop', function (done) { - async.detectSeries([1, 2, 3, 4, 5], function (num, cb) { + it('detectSeries - ensure stop', (done) => { + async.detectSeries([1, 2, 3, 4, 5], (num, cb) => { if (num > 3) throw new Error("detectSeries did not stop iterating"); cb(null, num === 3); - }, function (err, result) { + }, (err, result) => { expect(err).to.equal(null); expect(result).to.equal(3); done(); @@ -100,12 +100,12 @@ describe("detect", function () { it('detectLimit', function(done){ var call_order = []; - async.detectLimit([3, 2, 1], 2, detectIteratee.bind(this, call_order), function(err, result) { + async.detectLimit([3, 2, 1], 2, detectIteratee.bind(this, call_order), (err, result) => { call_order.push('callback'); expect(err).to.equal(null); expect(result).to.equal(2); }); - setTimeout(function() { + setTimeout(() => { expect(call_order).to.eql([2, 'callback', 3]); done(); }, 50); @@ -113,63 +113,63 @@ describe("detect", function () { it('detectLimit - multiple matches', function(done){ var call_order = []; - async.detectLimit([3,2,2,1,2], 2, detectIteratee.bind(this, call_order), function(err, result){ + async.detectLimit([3,2,2,1,2], 2, detectIteratee.bind(this, call_order), (err, result) => { call_order.push('callback'); expect(err).to.equal(null); expect(result).to.equal(2); }); - setTimeout(function(){ + setTimeout(() => { expect(call_order).to.eql([2, 'callback', 3]); done(); }, 50); }); - it('detectLimit - ensure stop', function (done) { - async.detectLimit([1, 2, 3, 4, 5], 2, function (num, cb) { + it('detectLimit - ensure stop', (done) => { + async.detectLimit([1, 2, 3, 4, 5], 2, (num, cb) => { if (num > 4) throw new Error("detectLimit did not stop iterating"); cb(null, num === 3); - }, function (err, result) { + }, (err, result) => { expect(err).to.equal(null); expect(result).to.equal(3); done(); }); }); - it('detectSeries doesn\'t cause stack overflow (#1293)', function(done) { + it('detectSeries doesn\'t cause stack overflow (#1293)', (done) => { var arr = _.range(10000); let calls = 0; - async.detectSeries(arr, function(data, cb) { + async.detectSeries(arr, (data, cb) => { calls += 1; async.setImmediate(_.partial(cb, null, true)); - }, function(err) { + }, (err) => { expect(err).to.equal(null); expect(calls).to.equal(1); done(); }); }); - it('detectLimit doesn\'t cause stack overflow (#1293)', function(done) { + it('detectLimit doesn\'t cause stack overflow (#1293)', (done) => { var arr = _.range(10000); let calls = 0; - async.detectLimit(arr, 100, function(data, cb) { + async.detectLimit(arr, 100, (data, cb) => { calls += 1; async.setImmediate(_.partial(cb, null, true)); - }, function(err) { + }, (err) => { expect(err).to.equal(null); expect(calls).to.equal(100); done(); }); }); - it('find alias', function(){ + it('find alias', () => { expect(async.find).to.equal(async.detect); }); - it('findLimit alias', function(){ + it('findLimit alias', () => { expect(async.findLimit).to.equal(async.detectLimit); }); - it('findSeries alias', function(){ + it('findSeries alias', () => { expect(async.findSeries).to.be.a('function'); expect(async.findSeries).to.equal(async.detectSeries); }); diff --git a/test/during.js b/test/during.js index e0636e501..fccb63615 100644 --- a/test/during.js +++ b/test/during.js @@ -2,23 +2,23 @@ var async = require('../lib'); var expect = require('chai').expect; var assert = require('assert'); -describe('during', function() { +describe('during', () => { - it('during', function(done) { + it('during', (done) => { var call_order = []; var count = 0; async.during( - function (cb) { + (cb) => { call_order.push(['test', count]); cb(null, count < 5); }, - function (cb) { + (cb) => { call_order.push(['iteratee', count]); count++; cb(null, count); }, - function (err) { + (err) => { assert(err === null, err + " passed instead of 'null'"); expect(call_order).to.eql([ ['test', 0], @@ -50,22 +50,22 @@ describe('during', function() { }, 10) }) - it('doDuring', function(done) { + it('doDuring', (done) => { var call_order = []; var count = 0; async.doDuring( - function (cb) { + (cb) => { call_order.push(['iteratee', count]); count++; cb(null, count); }, - function (c, cb) { + (c, cb) => { expect(c).to.equal(count); call_order.push(['test', count]); cb(null, count < 5); }, - function (err) { + (err) => { assert(err === null, err + " passed instead of 'null'"); expect(call_order).to.eql([ ['iteratee', 0], ['test', 1], @@ -80,32 +80,32 @@ describe('during', function() { ); }); - it('doDuring - error test', function(done) { + it('doDuring - error test', (done) => { var error = new Error('asdas'); async.doDuring( - function (cb) { + (cb) => { cb(error); }, - function () {}, - function (err) { + () => {}, + (err) => { expect(err).to.equal(error); done(); } ); }); - it('doDuring - error iteratee', function(done) { + it('doDuring - error iteratee', (done) => { var error = new Error('asdas'); async.doDuring( - function (cb) { + (cb) => { cb(null); }, - function (cb) { + (cb) => { cb(error); }, - function (err) { + (err) => { expect(err).to.equal(error); done(); } diff --git a/test/each.js b/test/each.js index ba5f3c4a1..404ad33bd 100644 --- a/test/each.js +++ b/test/each.js @@ -2,10 +2,10 @@ var async = require('../lib'); var expect = require('chai').expect; var assert = require('assert'); -describe("each", function() { +describe("each", () => { function eachIteratee(args, x, callback) { - setTimeout(function(){ + setTimeout(() => { args.push(x); callback(); }, x*25); @@ -19,16 +19,16 @@ describe("each", function() { it('each', function(done) { var args = []; - async.each([1,3,2], eachIteratee.bind(this, args), function(err){ + async.each([1,3,2], eachIteratee.bind(this, args), (err) => { assert(err === null, err + " passed instead of 'null'"); expect(args).to.eql([1,2,3]); done(); }); }); - it('each extra callback', function(done) { + it('each extra callback', (done) => { var count = 0; - async.each([1,3,2], function(val, callback) { + async.each([1,3,2], (val, callback) => { count++; var done_ = count == 3; callback(); @@ -39,11 +39,11 @@ describe("each", function() { }); }); - it('each empty array', function(done) { - async.each([], function(x, callback){ + it('each empty array', (done) => { + async.each([], (x, callback) => { assert(false, 'iteratee should not be called'); callback(); - }, function(err){ + }, (err) => { if (err) throw err; assert(true, 'should call callback'); }); @@ -51,13 +51,13 @@ describe("each", function() { }); - it('each empty array, with other property on the array', function(done) { + it('each empty array, with other property on the array', (done) => { var myArray = []; myArray.myProp = "anything"; - async.each(myArray, function(x, callback){ + async.each(myArray, (x, callback) => { assert(false, 'iteratee should not be called'); callback(); - }, function(err){ + }, (err) => { if (err) throw err; assert(true, 'should call callback'); }); @@ -65,10 +65,10 @@ describe("each", function() { }); - it('each error', function(done) { - async.each([1,2,3], function(x, callback){ + it('each error', (done) => { + async.each([1,2,3], (x, callback) => { callback('error'); - }, function(err){ + }, (err) => { expect(err).to.equal('error'); }); setTimeout(done, 50); @@ -80,29 +80,29 @@ describe("each", function() { it('eachSeries', function(done) { var args = []; - async.eachSeries([1,3,2], eachIteratee.bind(this, args), function(err){ + async.eachSeries([1,3,2], eachIteratee.bind(this, args), (err) => { assert(err === null, err + " passed instead of 'null'"); expect(args).to.eql([1,3,2]); done(); }); }); - it('eachSeries empty array', function(done) { - async.eachSeries([], function(x, callback){ + it('eachSeries empty array', (done) => { + async.eachSeries([], (x, callback) => { assert(false, 'iteratee should not be called'); callback(); - }, function(err){ + }, (err) => { if (err) throw err; assert(true, 'should call callback'); }); setTimeout(done, 25); }); - it('eachSeries array modification', function(done) { + it('eachSeries array modification', (done) => { var arr = [1, 2, 3, 4]; - async.eachSeries(arr, function (x, callback) { + async.eachSeries(arr, (x, callback) => { async.setImmediate(callback); - }, function () { + }, () => { assert(true, 'should call callback'); }); @@ -113,11 +113,11 @@ describe("each", function() { }); // bug #782. Remove in next major release - it('eachSeries single item', function(done) { + it('eachSeries single item', (done) => { var sync = true; - async.eachSeries([1], function (i, cb) { + async.eachSeries([1], (i, cb) => { cb(null); - }, function () { + }, () => { assert(sync, "callback not called on same tick"); }); sync = false; @@ -125,23 +125,23 @@ describe("each", function() { }); // bug #782. Remove in next major release - it('eachSeries single item', function(done) { + it('eachSeries single item', (done) => { var sync = true; - async.eachSeries([1], function (i, cb) { + async.eachSeries([1], (i, cb) => { cb(null); - }, function () { + }, () => { assert(sync, "callback not called on same tick"); }); sync = false; done(); }); - it('eachSeries error', function(done) { + it('eachSeries error', (done) => { var call_order = []; - async.eachSeries([1,2,3], function(x, callback){ + async.eachSeries([1,2,3], (x, callback) => { call_order.push(x); callback('error'); - }, function(err){ + }, (err) => { expect(call_order).to.eql([1]); expect(err).to.equal('error'); }); @@ -153,26 +153,26 @@ describe("each", function() { }); - it('eachLimit', function(done) { + it('eachLimit', (done) => { var args = []; var arr = [0,1,2,3,4,5,6,7,8,9]; - async.eachLimit(arr, 2, function(x,callback){ - setTimeout(function(){ + async.eachLimit(arr, 2, (x,callback) => { + setTimeout(() => { args.push(x); callback(); }, x*5); - }, function(err){ + }, (err) => { assert(err === null, err + " passed instead of 'null'"); expect(args).to.eql(arr); done(); }); }); - it('eachLimit empty array', function(done) { - async.eachLimit([], 2, function(x, callback){ + it('eachLimit empty array', (done) => { + async.eachLimit([], 2, (x, callback) => { assert(false, 'iteratee should not be called'); callback(); - }, function(err){ + }, (err) => { if (err) throw err; assert(true, 'should call callback'); }); @@ -182,7 +182,7 @@ describe("each", function() { it('eachLimit limit exceeds size', function(done) { var args = []; var arr = [0,1,2,3,4,5,6,7,8,9]; - async.eachLimit(arr, 20, eachIteratee.bind(this, args), function(err){ + async.eachLimit(arr, 20, eachIteratee.bind(this, args), (err) => { if (err) throw err; expect(args).to.eql(arr); done(); @@ -192,34 +192,34 @@ describe("each", function() { it('eachLimit limit equal size', function(done) { var args = []; var arr = [0,1,2,3,4,5,6,7,8,9]; - async.eachLimit(arr, 10, eachIteratee.bind(this, args), function(err){ + async.eachLimit(arr, 10, eachIteratee.bind(this, args), (err) => { if (err) throw err; expect(args).to.eql(arr); done(); }); }); - it('eachLimit zero limit', function() { + it('eachLimit zero limit', () => { expect(() => { - async.eachLimit([0,1,2,3,4,5], 0, function(x, callback){ + async.eachLimit([0,1,2,3,4,5], 0, (x, callback) => { assert(false, 'iteratee should not be called'); callback(); - }, function(){ + }, () => { assert(false, 'should not call callback'); }); }).to.throw(/limit/) }); - it('eachLimit error', function(done) { + it('eachLimit error', (done) => { var arr = [0,1,2,3,4,5,6,7,8,9]; var call_order = []; - async.eachLimit(arr, 3, function(x, callback){ + async.eachLimit(arr, 3, (x, callback) => { call_order.push(x); if (x === 2) { callback('error'); } - }, function(err){ + }, (err) => { expect(call_order).to.eql([0,1,2]); expect(err).to.equal('error'); }); @@ -230,53 +230,53 @@ describe("each", function() { async.eachLimit([1], 1, eachNoCallbackIteratee.bind(this, done)); }); - it('eachLimit synchronous', function(done) { + it('eachLimit synchronous', (done) => { var args = []; var arr = [0,1,2]; - async.eachLimit(arr, 5, function(x,callback){ + async.eachLimit(arr, 5, (x,callback) => { args.push(x); callback(); - }, function(err){ + }, (err) => { if (err) throw err; expect(args).to.eql(arr); done(); }); }); - it('eachLimit does not continue replenishing after error', function(done) { + it('eachLimit does not continue replenishing after error', (done) => { var started = 0; var arr = [0,1,2,3,4,5,6,7,8,9]; var delay = 10; var limit = 3; var maxTime = 10 * arr.length; - async.eachLimit(arr, limit, function(x, callback) { + async.eachLimit(arr, limit, (x, callback) => { started ++; if (started === 3) { return callback(new Error ("Test Error")); } - setTimeout(function(){ + setTimeout(() => { callback(); }, delay); - }, function(){}); + }, () => {}); - setTimeout(function(){ + setTimeout(() => { expect(started).to.equal(3); done(); }, maxTime); }); - it('forEach alias', function(done) { + it('forEach alias', (done) => { assert.strictEqual(async.each, async.forEach); done(); }); - it('forEachSeries alias', function(done) { + it('forEachSeries alias', (done) => { assert.strictEqual(async.eachSeries, async.forEachSeries); done(); }); - it('forEachLimit alias', function(done) { + it('forEachLimit alias', (done) => { assert.strictEqual(async.eachLimit, async.forEachLimit); done(); }); diff --git a/test/eachOf.js b/test/eachOf.js index 1701d3ed0..39c36cf06 100644 --- a/test/eachOf.js +++ b/test/eachOf.js @@ -3,7 +3,7 @@ var expect = require('chai').expect; var assert = require('assert'); var _ = require('lodash'); -describe("eachOf", function() { +describe("eachOf", () => { function forEachOfNoCallbackIteratee(done, x, key, callback) { expect(x).to.equal(1); @@ -13,37 +13,37 @@ describe("eachOf", function() { } function forEachOfIteratee(args, value, key, callback) { - setTimeout(function(){ + setTimeout(() => { args.push(key, value); callback(); }, value*25); } - it('eachOf alias', function(done) { + it('eachOf alias', (done) => { expect(async.eachOf).to.equal(async.forEachOf); done(); }); - it('eachOfLimit alias', function(done) { + it('eachOfLimit alias', (done) => { expect(async.eachOfLimit).to.equal(async.forEachOfLimit); done(); }); - it('eachOfSeries alias', function(done) { + it('eachOfSeries alias', (done) => { expect(async.eachOfSeries).to.equal(async.forEachOfSeries); done(); }); it('forEachOf', function(done) { var args = []; - async.forEachOf({ a: 1, b: 2 }, forEachOfIteratee.bind(this, args), function(err){ + async.forEachOf({ a: 1, b: 2 }, forEachOfIteratee.bind(this, args), (err) => { assert(err === null, err + " passed instead of 'null'"); expect(args).to.eql(["a", 1, "b", 2]); done(); }); }); - it('forEachOf no call stack size exceed error', function(done) { + it('forEachOf no call stack size exceed error', (done) => { var obj = {}; var len = 3000; var args = new Array(len * 2); @@ -55,56 +55,56 @@ describe("eachOf", function() { expected[2 * i + 1] = i; } - async.forEachOf(obj, function(value, key, callback) { + async.forEachOf(obj, (value, key, callback) => { var index = parseInt(key.slice(1), 10); args[2 * index] = key; args[2 * index + 1] = value; callback(); - }, function(err) { + }, (err) => { assert(err === null, err + " passed instead of 'null'"); expect(args).to.eql(expected); done(); }); }); - it('forEachOf - instant resolver', function(done) { + it('forEachOf - instant resolver', (done) => { var args = []; - async.forEachOf({ a: 1, b: 2 }, function(x, k, cb) { + async.forEachOf({ a: 1, b: 2 }, (x, k, cb) => { args.push(k, x); cb(); - }, function(){ + }, () => { // ensures done callback isn't called before all items iterated expect(args).to.eql(["a", 1, "b", 2]); done(); }); }); - it('forEachOf empty object', function(done) { - async.forEachOf({}, function(value, key, callback){ + it('forEachOf empty object', (done) => { + async.forEachOf({}, (value, key, callback) => { assert(false, 'iteratee should not be called'); callback(); - }, function(err) { + }, (err) => { if (err) throw err; assert(true, 'should call callback'); }); setTimeout(done, 25); }); - it('forEachOf empty array', function(done) { - async.forEachOf([], function(value, key, callback){ + it('forEachOf empty array', (done) => { + async.forEachOf([], (value, key, callback) => { assert(false, 'iteratee should not be called'); callback(); - }, function(err) { + }, (err) => { if (err) throw err; assert(true, 'should call callback'); }); setTimeout(done, 25); }); - it('forEachOf error', function(done) { - async.forEachOf({ a: 1, b: 2 }, function(value, key, callback) { + it('forEachOf error', (done) => { + async.forEachOf({ a: 1, b: 2 }, (value, key, callback) => { callback('error'); - }, function(err){ + }, (err) => { expect(err).to.equal('error'); }); setTimeout(done, 50); @@ -117,7 +117,7 @@ describe("eachOf", function() { it('forEachOf with array', function(done) { var args = []; - async.forEachOf([ "a", "b" ], forEachOfIteratee.bind(this, args), function(err){ + async.forEachOf([ "a", "b" ], forEachOfIteratee.bind(this, args), (err) => { if (err) throw err; expect(args).to.eql([0, "a", 1, "b"]); done(); @@ -132,7 +132,7 @@ describe("eachOf", function() { var set = new Set(); set.add("a"); set.add("b"); - async.forEachOf(set, forEachOfIteratee.bind(this, args), function(err){ + async.forEachOf(set, forEachOfIteratee.bind(this, args), (err) => { if (err) throw err; expect(args).to.eql([0, "a", 1, "b"]); done(); @@ -147,7 +147,7 @@ describe("eachOf", function() { var map = new Map(); map.set(1, "a"); map.set(2, "b"); - async.forEachOf(map, forEachOfIteratee.bind(this, args), function(err){ + async.forEachOf(map, forEachOfIteratee.bind(this, args), (err) => { if (err) throw err; expect(args).to.eql([0, [1, "a"], 1, [2, "b"]]); done(); @@ -156,14 +156,14 @@ describe("eachOf", function() { it('forEachOfSeries', function(done) { var args = []; - async.forEachOfSeries({ a: 1, b: 2 }, forEachOfIteratee.bind(this, args), function(err){ + async.forEachOfSeries({ a: 1, b: 2 }, forEachOfIteratee.bind(this, args), (err) => { assert(err === null, err + " passed instead of 'null'"); expect(args).to.eql([ "a", 1, "b", 2 ]); done(); }); }); - it('forEachOfSeries no call stack size exceed error', function(done) { + it('forEachOfSeries no call stack size exceed error', (done) => { var obj = {}; var len = 3000; var args = new Array(len * 2); @@ -175,35 +175,35 @@ describe("eachOf", function() { expected[2 * i + 1] = i; } - async.forEachOfSeries(obj, function(value, key, callback) { + async.forEachOfSeries(obj, (value, key, callback) => { var index = parseInt(key.slice(1), 10); args[2 * index] = key; args[2 * index + 1] = value; callback(); - }, function(err) { + }, (err) => { assert(err === null, err + " passed instead of 'null'"); expect(args).to.eql(expected); done(); }); }); - it('forEachOfSeries empty object', function(done) { - async.forEachOfSeries({}, function(x, callback){ + it('forEachOfSeries empty object', (done) => { + async.forEachOfSeries({}, (x, callback) => { assert(false, 'iteratee should not be called'); callback(); - }, function(err){ + }, (err) => { if (err) throw err; assert(true, 'should call callback'); }); setTimeout(done, 25); }); - it('forEachOfSeries error', function(done) { + it('forEachOfSeries error', (done) => { var call_order = []; - async.forEachOfSeries({ a: 1, b: 2 }, function(value, key, callback){ + async.forEachOfSeries({ a: 1, b: 2 }, (value, key, callback) => { call_order.push(value, key); callback('error'); - }, function(err){ + }, (err) => { expect(call_order).to.eql([ 1, "a" ]); expect(err).to.equal('error'); }); @@ -216,7 +216,7 @@ describe("eachOf", function() { it('forEachOfSeries with array', function(done) { var args = []; - async.forEachOfSeries([ "a", "b" ], forEachOfIteratee.bind(this, args), function(err){ + async.forEachOfSeries([ "a", "b" ], forEachOfIteratee.bind(this, args), (err) => { if (err) throw err; expect(args).to.eql([ 0, "a", 1, "b" ]); done(); @@ -231,7 +231,7 @@ describe("eachOf", function() { var set = new Set(); set.add("a"); set.add("b"); - async.forEachOfSeries(set, forEachOfIteratee.bind(this, args), function(err){ + async.forEachOfSeries(set, forEachOfIteratee.bind(this, args), (err) => { if (err) throw err; expect(args).to.eql([0, "a", 1, "b"]); done(); @@ -246,33 +246,33 @@ describe("eachOf", function() { var map = new Map(); map.set(1, "a"); map.set(2, "b"); - async.forEachOfSeries(map, forEachOfIteratee.bind(this, args), function(err){ + async.forEachOfSeries(map, forEachOfIteratee.bind(this, args), (err) => { if (err) throw err; expect(args).to.eql([0, [1, "a"], 1, [2, "b"]]); done(); }); }); - it('forEachOfLimit', function(done) { + it('forEachOfLimit', (done) => { var args = []; var obj = { a: 1, b: 2, c: 3, d: 4 }; - async.forEachOfLimit(obj, 2, function(value, key, callback){ - setTimeout(function(){ + async.forEachOfLimit(obj, 2, (value, key, callback) => { + setTimeout(() => { args.push(value, key); callback(); }, value * 5); - }, function(err){ + }, (err) => { assert(err === null, err + " passed instead of 'null'"); expect(args).to.eql([ 1, "a", 2, "b", 3, "c", 4, "d" ]); done(); }); }); - it('forEachOfLimit empty object', function(done) { - async.forEachOfLimit({}, 2, function(value, key, callback){ + it('forEachOfLimit empty object', (done) => { + async.forEachOfLimit({}, 2, (value, key, callback) => { assert(false, 'iteratee should not be called'); callback(); - }, function(err){ + }, (err) => { if (err) throw err; assert(true, 'should call callback'); }); @@ -282,7 +282,7 @@ describe("eachOf", function() { it('forEachOfLimit limit exceeds size', function(done) { var args = []; var obj = { a: 1, b: 2, c: 3, d: 4, e: 5 }; - async.forEachOfLimit(obj, 10, forEachOfIteratee.bind(this, args), function(err){ + async.forEachOfLimit(obj, 10, forEachOfIteratee.bind(this, args), (err) => { if (err) throw err; expect(args).to.eql([ "a", 1, "b", 2, "c", 3, "d", 4, "e", 5 ]); done(); @@ -292,58 +292,58 @@ describe("eachOf", function() { it('forEachOfLimit limit equal size', function(done) { var args = []; var obj = { a: 1, b: 2, c: 3, d: 4, e: 5 }; - async.forEachOfLimit(obj, 5, forEachOfIteratee.bind(this, args), function(err){ + async.forEachOfLimit(obj, 5, forEachOfIteratee.bind(this, args), (err) => { if (err) throw err; expect(args).to.eql([ "a", 1, "b", 2, "c", 3, "d", 4, "e", 5 ]); done(); }); }); - it('forEachOfLimit zero limit', function() { + it('forEachOfLimit zero limit', () => { expect(() => { - async.forEachOfLimit({ a: 1, b: 2 }, 0, function(x, callback){ + async.forEachOfLimit({ a: 1, b: 2 }, 0, (x, callback) => { assert(false, 'iteratee should not be called'); callback(); - }, function(){ + }, () => { assert(true, 'should call callback'); }); }).to.throw(/concurrency limit/) }); - it('forEachOfLimit no limit', function(done) { + it('forEachOfLimit no limit', (done) => { var count = 0; - async.forEachOfLimit(_.range(100), Infinity, function(x, i, callback){ + async.forEachOfLimit(_.range(100), Infinity, (x, i, callback) => { count++; callback(); - }, function(err){ + }, (err) => { if (err) throw err; expect(count).to.equal(100); }); setTimeout(done, 25); }); - it('forEachOfLimit no call stack size exceed error', function(done) { + it('forEachOfLimit no call stack size exceed error', (done) => { var count = 0; - async.forEachOfLimit(_.range(1024 * 1024), Infinity, function(x, i, callback){ + async.forEachOfLimit(_.range(1024 * 1024), Infinity, (x, i, callback) => { count++; callback(); - }, function(err){ + }, (err) => { if (err) throw err; expect(count).to.equal(1024 * 1024); done(); }); }); - it('forEachOfLimit error', function(done) { + it('forEachOfLimit error', (done) => { var obj = { a: 1, b: 2, c: 3, d: 4, e: 5 }; var call_order = []; - async.forEachOfLimit(obj, 3, function(value, key, callback){ + async.forEachOfLimit(obj, 3, (value, key, callback) => { call_order.push(value, key); if (value === 2) { callback('error'); } - }, function(err){ + }, (err) => { expect(call_order).to.eql([ 1, "a", 2, "b" ]); expect(err).to.equal('error'); }); @@ -357,7 +357,7 @@ describe("eachOf", function() { it('forEachOfLimit synchronous', function(done) { var args = []; var obj = { a: 1, b: 2 }; - async.forEachOfLimit(obj, 5, forEachOfIteratee.bind(this, args), function(err){ + async.forEachOfLimit(obj, 5, forEachOfIteratee.bind(this, args), (err) => { if (err) throw err; expect(args).to.eql([ "a", 1, "b", 2 ]); done(); @@ -367,7 +367,7 @@ describe("eachOf", function() { it('forEachOfLimit with array', function(done) { var args = []; var arr = [ "a", "b" ]; - async.forEachOfLimit(arr, 1, forEachOfIteratee.bind(this, args), function (err) { + async.forEachOfLimit(arr, 1, forEachOfIteratee.bind(this, args), (err) => { if (err) throw err; expect(args).to.eql([ 0, "a", 1, "b" ]); done(); @@ -382,7 +382,7 @@ describe("eachOf", function() { var set = new Set(); set.add("a"); set.add("b"); - async.forEachOfLimit(set, 1, forEachOfIteratee.bind(this, args), function(err){ + async.forEachOfLimit(set, 1, forEachOfIteratee.bind(this, args), (err) => { if (err) throw err; expect(args).to.eql([0, "a", 1, "b"]); done(); @@ -397,24 +397,24 @@ describe("eachOf", function() { var map = new Map(); map.set(1, "a"); map.set(2, "b"); - async.forEachOfLimit(map, 1, forEachOfIteratee.bind(this, args), function(err){ + async.forEachOfLimit(map, 1, forEachOfIteratee.bind(this, args), (err) => { if (err) throw err; expect(args).to.eql([0, [1, "a"], 1, [2, "b"]]); done(); }); }); - it('forEachOfLimit canceled', function(done) { + it('forEachOfLimit canceled', (done) => { var obj = { a: 1, b: 2, c: 3, d: 4, e: 5 }; var call_order = []; - async.forEachOfLimit(obj, 3, function(value, key, callback){ + async.forEachOfLimit(obj, 3, (value, key, callback) => { call_order.push(value, key); if (value === 2) { return callback(false); } callback() - }, function(){ + }, () => { throw new Error('should not get here') }); setTimeout(() => { @@ -423,11 +423,11 @@ describe("eachOf", function() { }, 10); }); - it('forEachOfLimit canceled (async)', function(done) { + it('forEachOfLimit canceled (async)', (done) => { var obj = { a: 1, b: 2, c: 3, d: 4, e: 5 }; var call_order = []; - async.forEachOfLimit(obj, 3, function(value, key, callback){ + async.forEachOfLimit(obj, 3, (value, key, callback) => { call_order.push(value, key); setTimeout(() => { if (value === 2) { @@ -435,7 +435,7 @@ describe("eachOf", function() { } callback() }) - }, function(){ + }, () => { throw new Error('should not get here') }); setTimeout(() => { @@ -444,11 +444,11 @@ describe("eachOf", function() { }, 20); }); - it('eachOfLimit canceled (async, array)', function(done) { + it('eachOfLimit canceled (async, array)', (done) => { var obj = ['a', 'b', 'c', 'd', 'e']; var call_order = []; - async.eachOfLimit(obj, 3, function(value, key, callback){ + async.eachOfLimit(obj, 3, (value, key, callback) => { call_order.push(key, value); setTimeout(() => { if (value === 'b') { @@ -456,7 +456,7 @@ describe("eachOf", function() { } callback() }) - }, function(){ + }, () => { throw new Error('should not get here') }); setTimeout(() => { @@ -465,11 +465,11 @@ describe("eachOf", function() { }, 20); }); - it('eachOf canceled (async, array)', function(done) { + it('eachOf canceled (async, array)', (done) => { var arr = ['a', 'b', 'c', 'd', 'e']; var call_order = []; - async.eachOf(arr, function(value, key, callback){ + async.eachOf(arr, (value, key, callback) => { call_order.push(key, value); setTimeout(() => { if (value === 'b') { @@ -477,7 +477,7 @@ describe("eachOf", function() { } callback() }) - }, function(){ + }, () => { throw new Error('should not get here') }); setTimeout(() => { @@ -486,11 +486,11 @@ describe("eachOf", function() { }, 20); }); - it('forEachOfLimit canceled (async, w/ error)', function(done) { + it('forEachOfLimit canceled (async, w/ error)', (done) => { var obj = { a: 1, b: 2, c: 3, d: 4, e: 5 }; var call_order = []; - async.forEachOfLimit(obj, 3, function(value, key, callback){ + async.forEachOfLimit(obj, 3, (value, key, callback) => { call_order.push(value, key); setTimeout(() => { if (value === 2) { @@ -501,7 +501,7 @@ describe("eachOf", function() { } callback() }) - }, function(){ + }, () => { throw new Error('should not get here') }); setTimeout(() => { diff --git a/test/ensureAsync.js b/test/ensureAsync.js index 89659e28b..bbfc05355 100644 --- a/test/ensureAsync.js +++ b/test/ensureAsync.js @@ -2,18 +2,18 @@ var async = require('../lib'); var expect = require('chai').expect; var assert = require('assert'); -describe('ensureAsync', function() { +describe('ensureAsync', () => { var passContext = function(cb) { cb(this); }; - it('defer sync functions', function(done) { + it('defer sync functions', (done) => { var sync = true; - async.ensureAsync(function (arg1, arg2, cb) { + async.ensureAsync((arg1, arg2, cb) => { expect(arg1).to.equal(1); expect(arg2).to.equal(2); cb(null, 4, 5); - })(1, 2, function (err, arg4, arg5) { + })(1, 2, (err, arg4, arg5) => { expect(err).to.equal(null); expect(arg4).to.equal(4); expect(arg5).to.equal(5); @@ -23,17 +23,17 @@ describe('ensureAsync', function() { sync = false; }); - it('do not defer async functions', function(done) { + it('do not defer async functions', (done) => { var sync = false; - async.ensureAsync(function (arg1, arg2, cb) { + async.ensureAsync((arg1, arg2, cb) => { expect(arg1).to.equal(1); expect(arg2).to.equal(2); - async.setImmediate(function () { + async.setImmediate(() => { sync = true; cb(null, 4, 5); sync = false; }); - })(1, 2, function (err, arg4, arg5) { + })(1, 2, (err, arg4, arg5) => { expect(err).to.equal(null); expect(arg4).to.equal(4); expect(arg5).to.equal(5); @@ -42,13 +42,13 @@ describe('ensureAsync', function() { }); }); - it('double wrapping', function(done) { + it('double wrapping', (done) => { var sync = true; - async.ensureAsync(async.ensureAsync(function (arg1, arg2, cb) { + async.ensureAsync(async.ensureAsync((arg1, arg2, cb) => { expect(arg1).to.equal(1); expect(arg2).to.equal(2); cb(null, 4, 5); - }))(1, 2, function (err, arg4, arg5) { + }))(1, 2, (err, arg4, arg5) => { expect(err).to.equal(null); expect(arg4).to.equal(4); expect(arg5).to.equal(5); @@ -59,25 +59,25 @@ describe('ensureAsync', function() { }); - it('should propely bind context to the wrapped function', function(done) { + it('should propely bind context to the wrapped function', (done) => { // call bind after wrapping with ensureAsync var context = {context: "post"}; var postBind = async.ensureAsync(passContext); postBind = postBind.bind(context); - postBind(function(ref) { + postBind((ref) => { expect(ref).to.equal(context); done(); }); }); - it('should not override the bound context of a function when wrapping', function(done) { + it('should not override the bound context of a function when wrapping', (done) => { // call bind before wrapping with ensureAsync var context = {context: "pre"}; var preBind = passContext.bind(context); preBind = async.ensureAsync(preBind); - preBind(function(ref) { + preBind((ref) => { expect(ref).to.equal(context); done(); }); diff --git a/test/es2017/asyncFunctions.js b/test/es2017/asyncFunctions.js index 1a93f4f75..23fa2e675 100644 --- a/test/es2017/asyncFunctions.js +++ b/test/es2017/asyncFunctions.js @@ -20,7 +20,7 @@ module.exports = function () { }); it('should handle errors in async functions', (done) => { - async.asyncify(async function () { + async.asyncify(async () => { throw new Error('thrown error') })((err) => { assert(err.message = 'thrown error'); @@ -228,7 +228,7 @@ module.exports = function () { }); it('should handle async functions in reduce', (done) => { - async.reduce(input, 0, async function (acc, val) { + async.reduce(input, 0, async (acc, val) => { var res = await Promise.resolve(acc + val); return res; }, @@ -239,7 +239,7 @@ module.exports = function () { }); it('should handle async functions in reduceRight', (done) => { - async.reduceRight(input, 0, async function (acc, val) { + async.reduceRight(input, 0, async (acc, val) => { var res = await Promise.resolve(acc + val); return res; }, @@ -257,7 +257,7 @@ module.exports = function () { }); it('should handle async functions in transform', (done) => { - async.transform(inputObj, async function (obj, val, key) { + async.transform(inputObj, async (obj, val, key) => { obj[key] = await Promise.resolve(val); }, (err, result) => { expect(result).to.eql(inputObj); @@ -285,10 +285,10 @@ module.exports = function () { it('should handle async functions in auto', (done) => { async.auto({ - a: async function () { + async a () { return await Promise.resolve(1); }, - b: async function () { + async b () { return await Promise.resolve(2); }, c: ['a', 'b', async function (results) { @@ -302,10 +302,10 @@ module.exports = function () { it('should handle async functions in autoInject', (done) => { async.autoInject({ - a: async function () { + async a () { return await Promise.resolve(1); }, - b: async function (a) { + async b (a) { return await Promise.resolve(a + 1); }, c: async (a, b) => { @@ -342,7 +342,7 @@ module.exports = function () { it('should handle async functions in cargo', (done) => { var result = []; - var q = async.cargo(async function(val) { + var q = async.cargo(async (val) => { result.push(await Promise.resolve(val)); }, 2) @@ -358,7 +358,7 @@ module.exports = function () { it('should handle async functions in queue', (done) => { var result = []; - var q = async.queue(async function(val) { + var q = async.queue(async (val) => { result.push(await Promise.resolve(val)); }, 2) @@ -374,7 +374,7 @@ module.exports = function () { it('should handle async functions in priorityQueue', (done) => { var result = []; - var q = async.priorityQueue(async function(val) { + var q = async.priorityQueue(async (val) => { result.push(await Promise.resolve(val)); }, 2) @@ -435,10 +435,10 @@ module.exports = function () { it('should handle async functions in whilst', (done) => { var val = 0; async.whilst(() => val < 3, - async () => { - val += 1; - return val; - }, done); + async () => { + val += 1; + return val; + }, done); }); it('should handle async functions in doWhilst', (done) => { @@ -452,10 +452,10 @@ module.exports = function () { it('should handle async functions in until', (done) => { var val = 0; async.until(() => val > 3, - async () => { - val += 1; - return val; - }, done); + async () => { + val += 1; + return val; + }, done); }); it('should handle async functions in doUntil', (done) => { diff --git a/test/every.js b/test/every.js index 39ae51c4d..559084d0c 100644 --- a/test/every.js +++ b/test/every.js @@ -2,34 +2,34 @@ var async = require('../lib'); var expect = require('chai').expect; var _ = require('lodash'); -describe("every", function () { +describe("every", () => { - it('everyLimit true', function(done){ - async.everyLimit([3,1,2], 1, function(x, callback){ - setTimeout(function(){callback(null, x >= 1);}, 0); - }, function(err, result){ + it('everyLimit true', (done) => { + async.everyLimit([3,1,2], 1, (x, callback) => { + setTimeout(() => {callback(null, x >= 1);}, 0); + }, (err, result) => { expect(err).to.equal(null); expect(result).to.equal(true); done(); }); }); - it('everyLimit false', function(done){ - async.everyLimit([3,1,2], 2, function(x, callback){ - setTimeout(function(){callback(null, x === 2);}, 0); - }, function(err, result){ + it('everyLimit false', (done) => { + async.everyLimit([3,1,2], 2, (x, callback) => { + setTimeout(() => {callback(null, x === 2);}, 0); + }, (err, result) => { expect(err).to.equal(null); expect(result).to.equal(false); done(); }); }); - it('everyLimit short-circuit', function(done){ + it('everyLimit short-circuit', (done) => { var calls = 0; - async.everyLimit([3,1,2], 1, function(x, callback){ + async.everyLimit([3,1,2], 1, (x, callback) => { calls++; callback(null, x === 1); - }, function(err, result){ + }, (err, result) => { expect(err).to.equal(null); expect(result).to.equal(false); expect(calls).to.equal(1); @@ -38,87 +38,87 @@ describe("every", function () { }); - it('true', function(done){ - async.every([1,2,3], function(x, callback){ - setTimeout(function(){callback(null, true);}, 0); - }, function(err, result){ + it('true', (done) => { + async.every([1,2,3], (x, callback) => { + setTimeout(() => {callback(null, true);}, 0); + }, (err, result) => { expect(err).to.equal(null); expect(result).to.equal(true); done(); }); }); - it('false', function(done){ - async.every([1,2,3], function(x, callback){ - setTimeout(function(){callback(null, x % 2);}, 0); - }, function(err, result){ + it('false', (done) => { + async.every([1,2,3], (x, callback) => { + setTimeout(() => {callback(null, x % 2);}, 0); + }, (err, result) => { expect(err).to.equal(null); expect(result).to.equal(false); done(); }); }); - it('early return', function(done){ + it('early return', (done) => { var call_order = []; - async.every([1,2,3], function(x, callback){ - setTimeout(function(){ + async.every([1,2,3], (x, callback) => { + setTimeout(() => { call_order.push(x); callback(null, x === 1); }, x*5); - }, function(){ + }, () => { call_order.push('callback'); }); - setTimeout(function(){ + setTimeout(() => { expect(call_order).to.eql([1,2,'callback',3]); done(); }, 25); }); - it('error', function(done){ - async.every([1,2,3], function(x, callback){ - setTimeout(function(){callback('error');}, 0); - }, function(err, result){ + it('error', (done) => { + async.every([1,2,3], (x, callback) => { + setTimeout(() => {callback('error');}, 0); + }, (err, result) => { expect(err).to.equal('error'); expect(result).to.not.exist; done(); }); }); - it('everySeries doesn\'t cause stack overflow (#1293)', function(done) { + it('everySeries doesn\'t cause stack overflow (#1293)', (done) => { var arr = _.range(10000); let calls = 0; - async.everySeries(arr, function(data, cb) { + async.everySeries(arr, (data, cb) => { calls += 1; async.setImmediate(_.partial(cb, null, false)); - }, function(err) { + }, (err) => { expect(err).to.equal(null); expect(calls).to.equal(1); done(); }); }); - it('everyLimit doesn\'t cause stack overflow (#1293)', function(done) { + it('everyLimit doesn\'t cause stack overflow (#1293)', (done) => { var arr = _.range(10000); let calls = 0; - async.everyLimit(arr, 100, function(data, cb) { + async.everyLimit(arr, 100, (data, cb) => { calls += 1; async.setImmediate(_.partial(cb, null, false)); - }, function(err) { + }, (err) => { expect(err).to.equal(null); expect(calls).to.equal(100); done(); }); }); - it('all alias', function(){ + it('all alias', () => { expect(async.all).to.equal(async.every); }); - it('allLimit alias', function(){ + it('allLimit alias', () => { expect(async.allLimit).to.equal(async.everyLimit); }); - it('allSeries alias', function(){ + it('allSeries alias', () => { expect(async.allSeries).to.be.a('function'); expect(async.allSeries).to.equal(async.everySeries); }); diff --git a/test/filter.js b/test/filter.js index a6cea2a38..ee835cfae 100644 --- a/test/filter.js +++ b/test/filter.js @@ -2,7 +2,7 @@ var async = require('../lib'); var expect = require('chai').expect; function filterIteratee(x, callback) { - setTimeout(function(){ + setTimeout(() => { callback(null, x % 2); }, x*5); } @@ -10,30 +10,30 @@ function filterIteratee(x, callback) { function testLimit(arr, limitFunc, limit, iter, done) { var args = []; - limitFunc(arr, limit, function(x) { + limitFunc(arr, limit, (x, next) => { args.push(x); - iter.apply(this, arguments); - }, function() { + iter(x, next); + }, (err, result) => { expect(args).to.eql(arr); - done.apply(this, arguments); + done(err, result); }); } -describe("filter", function () { +describe("filter", () => { - it('filter', function(done){ - async.filter([3,1,2], filterIteratee, function(err, results){ + it('filter', (done) => { + async.filter([3,1,2], filterIteratee, (err, results) => { expect(err).to.equal(null); expect(results).to.eql([3,1]); done(); }); }); - it('filter original untouched', function(done){ + it('filter original untouched', (done) => { var a = [3,1,2]; - async.filter(a, function(x, callback){ + async.filter(a, (x, callback) => { callback(null, x % 2); - }, function(err, results){ + }, (err, results) => { expect(err).to.equal(null); expect(results).to.eql([3,1]); expect(a).to.eql([3,1,2]); @@ -41,11 +41,11 @@ describe("filter", function () { }); }); - it('filter collection', function(done){ + it('filter collection', (done) => { var a = {a: 3, b: 1, c: 2}; - async.filter(a, function(x, callback){ + async.filter(a, (x, callback) => { callback(null, x % 2); - }, function(err, results){ + }, (err, results) => { expect(err).to.equal(null); expect(results).to.eql([3,1]); expect(a).to.eql({a: 3, b: 1, c: 2}); @@ -53,67 +53,65 @@ describe("filter", function () { }); }); - if (typeof Symbol === 'function' && Symbol.iterator) { - function makeIterator(array){ - var nextIndex; - let iterator = { - next: function(){ - return nextIndex < array.length ? - {value: array[nextIndex++], done: false} : - {done: true}; - } - }; - iterator[Symbol.iterator] = function() { - nextIndex = 0; // reset iterator - return iterator; - }; + function makeIterator(array){ + var nextIndex; + let iterator = { + next(){ + return nextIndex < array.length ? + {value: array[nextIndex++], done: false} : + {done: true}; + } + }; + iterator[Symbol.iterator] = function() { + nextIndex = 0; // reset iterator return iterator; - } - - it('filter iterator', function(done){ - var a = makeIterator([500, 20, 100]); - async.filter(a, function(x, callback) { - setTimeout(function() { - callback(null, x > 20); - }, x); - }, function(err, results){ - expect(err).to.equal(null); - expect(results).to.eql([500, 100]); - done(); - }); - }); + }; + return iterator; } - it('filter error', function(done){ - async.filter([3,1,2], function(x, callback){ + it('filter iterator', (done) => { + var a = makeIterator([500, 20, 100]); + async.filter(a, (x, callback) => { + setTimeout(() => { + callback(null, x > 20); + }, x); + }, (err, results) => { + expect(err).to.equal(null); + expect(results).to.eql([500, 100]); + done(); + }); + }); + + it('filter error', (done) => { + async.filter([3,1,2], (x, callback) => { callback('error'); - } , function(err, results){ + } , (err, results) => { expect(err).to.equal('error'); expect(results).to.not.exist; done(); }); }); - it('filterSeries', function(done){ - async.filterSeries([3,1,2], filterIteratee, function(err, results){ + it('filterSeries', (done) => { + async.filterSeries([3,1,2], filterIteratee, (err, results) => { expect(err).to.equal(null); expect(results).to.eql([3,1]); done(); }); }); - it('select alias', function(){ + it('select alias', () => { expect(async.select).to.equal(async.filter); }); - it('selectSeries alias', function(){ + it('selectSeries alias', () => { expect(async.selectSeries).to.equal(async.filterSeries); }); - it('filterLimit', function(done) { - testLimit([5, 4, 3, 2, 1], async.filterLimit, 2, function(v, next) { + it('filterLimit', (done) => { + testLimit([5, 4, 3, 2, 1], async.filterLimit, 2, (v, next) => { next(null, v % 2); - }, function(err, result){ + }, (err, result) => { expect(err).to.equal(null); expect(result).to.eql([5, 3, 1]); done(); @@ -122,21 +120,21 @@ describe("filter", function () { }); -describe("reject", function () { +describe("reject", () => { - it('reject', function(done){ - async.reject([3,1,2], filterIteratee, function(err, results){ + it('reject', (done) => { + async.reject([3,1,2], filterIteratee, (err, results) => { expect(err).to.equal(null); expect(results).to.eql([2]); done(); }); }); - it('reject original untouched', function(done){ + it('reject original untouched', (done) => { var a = [3,1,2]; - async.reject(a, function(x, callback){ + async.reject(a, (x, callback) => { callback(null, x % 2); - }, function(err, results){ + }, (err, results) => { expect(err).to.equal(null); expect(results).to.eql([2]); expect(a).to.eql([3,1,2]); @@ -144,42 +142,42 @@ describe("reject", function () { }); }); - it('reject error', function(done){ - async.reject([3,1,2], function(x, callback){ + it('reject error', (done) => { + async.reject([3,1,2], (x, callback) => { callback('error'); - } , function(err, results){ + } , (err, results) => { expect(err).to.equal('error'); expect(results).to.not.exist; done(); }); }); - it('rejectSeries', function(done){ - async.rejectSeries([3,1,2], filterIteratee, function(err, results){ + it('rejectSeries', (done) => { + async.rejectSeries([3,1,2], filterIteratee, (err, results) => { expect(err).to.equal(null); expect(results).to.eql([2]); done(); }); }); - it('rejectLimit', function(done) { - testLimit([5, 4, 3, 2, 1], async.rejectLimit, 2, function(v, next) { + it('rejectLimit', (done) => { + testLimit([5, 4, 3, 2, 1], async.rejectLimit, 2, (v, next) => { next(null, v % 2); - }, function(err, result){ + }, (err, result) => { expect(err).to.equal(null); expect(result).to.eql([4, 2]); done(); }); }); - it('filter fails', function(done) { - async.filter({a: 1, b: 2, c: 3}, function (item, callback) { + it('filter fails', (done) => { + async.filter({a: 1, b: 2, c: 3}, (item, callback) => { if (item === 3) { callback("error", false); } else { callback(null, true); } - }, function (err, res) { + }, (err, res) => { expect(err).to.equal("error"); expect(res).to.equal(undefined); done(); diff --git a/test/forever.js b/test/forever.js index b69839959..ac12d3e1c 100644 --- a/test/forever.js +++ b/test/forever.js @@ -1,20 +1,20 @@ var async = require('../lib'); var expect = require('chai').expect; -describe('forever', function(){ - context('function is asynchronous', function(){ - it('executes the function over and over until it yields an error', function(done){ +describe('forever', () => { + context('function is asynchronous', () => { + it('executes the function over and over until it yields an error', (done) => { var counter = 0; function addOne(callback) { counter++; if (counter === 50) { return callback('too big!'); } - async.setImmediate(function () { + async.setImmediate(() => { callback(); }); } - async.forever(addOne, function (err) { + async.forever(addOne, (err) => { expect(err).to.eql('too big!'); expect(counter).to.eql(50); done(); @@ -22,8 +22,8 @@ describe('forever', function(){ }); }); - context('function is synchronous', function(){ - it('does not cause a stack overflow @nodeonly', function(done){ // this will take forever in a browser + context('function is synchronous', () => { + it('does not cause a stack overflow @nodeonly', (done) => { // this will take forever in a browser var counter = 0; function addOne(callback) { counter++; @@ -32,7 +32,7 @@ describe('forever', function(){ } callback(); } - async.forever(addOne, function (err) { + async.forever(addOne, (err) => { expect(err).to.eql('too big!'); expect(counter).to.eql(50000); done(); diff --git a/test/groupBy.js b/test/groupBy.js index 796d353db..dab125bee 100644 --- a/test/groupBy.js +++ b/test/groupBy.js @@ -6,16 +6,16 @@ describe('groupBy', function() { this.timeout(250); function groupByIteratee(callOrder, val, next) { - setTimeout(function() { + setTimeout(() => { callOrder.push(val); next(null, val+1); }, val * 25); } - context('groupBy', function() { + context('groupBy', () => { it('basics', function(done) { var callOrder = []; - async.groupBy([1, 3, 2], groupByIteratee.bind(this, callOrder), function(err, result) { + async.groupBy([1, 3, 2], groupByIteratee.bind(this, callOrder), (err, result) => { expect(err).to.eql(null); expect(callOrder).to.eql([1, 2, 3]); expect(result).to.eql({2: [1], 3: [2], 4: [3]}); @@ -23,24 +23,24 @@ describe('groupBy', function() { }); }); - it('error', function(done) { - async.groupBy([1, 3, 2], function(val, next) { + it('error', (done) => { + async.groupBy([1, 3, 2], (val, next) => { if (val === 3) { return next(new Error('fail')); } next(null, val+1); - }, function(err, result) { + }, (err, result) => { expect(err).to.not.eql(null); expect(result).to.eql({2: [1]}); done(); }); }); - it('original untouched', function(done) { + it('original untouched', (done) => { var obj = {a: 'b', b: 'c', c: 'd'}; - async.groupBy(obj, function(val, next) { + async.groupBy(obj, (val, next) => { next(null, val); - }, function(err, result) { + }, (err, result) => { expect(obj).to.eql({a: 'b', b: 'c', c: 'd'}); expect(result).to.eql({b: ['b'], c: ['c'], d: ['d']}); done(); @@ -49,7 +49,7 @@ describe('groupBy', function() { it('handles multiple matches', function(done) { var callOrder = []; - async.groupBy([1, 3, 2, 2], groupByIteratee.bind(this, callOrder), function(err, result) { + async.groupBy([1, 3, 2, 2], groupByIteratee.bind(this, callOrder), (err, result) => { expect(err).to.eql(null); expect(callOrder).to.eql([1, 2, 2, 3]); expect(result).to.eql({2: [1], 3: [2, 2], 4: [3]}); @@ -57,18 +57,18 @@ describe('groupBy', function() { }); }); - it('handles objects', function(done) { + it('handles objects', (done) => { var obj = {a: 'b', b: 'c', c: 'd'}; var concurrency = {b: 3, c: 2, d: 1}; var running = 0; - async.groupBy(obj, function(val, next) { + async.groupBy(obj, (val, next) => { running++; - async.setImmediate(function() { + async.setImmediate(() => { expect(running).to.equal(concurrency[val]); running--; next(null, val); }); - }, function(err, result) { + }, (err, result) => { expect(running).to.equal(0); expect(err).to.eql(null); expect(result).to.eql({b: ['b'], c: ['c'], d: ['d']}); @@ -76,35 +76,35 @@ describe('groupBy', function() { }); }); - it('handles undefined', function(done) { - async.groupBy(undefined, function(val, next) { + it('handles undefined', (done) => { + async.groupBy(undefined, (val, next) => { assert(false, 'iteratee should not be called'); next(); - }, function(err, result) { + }, (err, result) => { expect(err).to.eql(null); expect(result).to.eql({}); done(); }); }); - it('handles empty object', function(done) { - async.groupBy({}, function(val, next) { + it('handles empty object', (done) => { + async.groupBy({}, (val, next) => { assert(false, 'iteratee should not be called'); next(); - }, function(err, result) { + }, (err, result) => { expect(err).to.eql(null); expect(result).to.eql({}); done(); }); }); - it('main callback optional' , function(done) { + it('main callback optional' , (done) => { var arr = [1, 2, 3]; var runs = []; - async.groupBy(arr, function(val, next) { + async.groupBy(arr, (val, next) => { runs.push(val); var _done = (runs.length === arr.length); - async.setImmediate(function() { + async.setImmediate(() => { next(null); if (_done) { expect(runs).to.eql(arr); @@ -114,22 +114,22 @@ describe('groupBy', function() { }); }); - it('iteratee callback is only called once', function(done) { - async.groupBy([1, 2], function(item, callback) { + it('iteratee callback is only called once', (done) => { + async.groupBy([1, 2], (item, callback) => { try { callback(item); } catch (exception) { - expect(function() { + expect(() => { callback(exception); }).to.throw(/already called/); done(); } - }, function() { + }, () => { throw new Error(); }); }); - it('handles Map', function(done) { + it('handles Map', (done) => { if (typeof Map !== 'function') { return done(); } @@ -140,9 +140,9 @@ describe('groupBy', function() { ['c', 'a'] ]); - async.groupBy(map, function(val, next) { + async.groupBy(map, (val, next) => { next(null, val[1]+1); - }, function(err, result) { + }, (err, result) => { expect(err).to.eql(null); expect(result).to.eql({ a1: [ ['a', 'a'], ['c', 'a']], @@ -152,19 +152,19 @@ describe('groupBy', function() { }); }); - it('handles sparse results', function(done) { + it('handles sparse results', (done) => { var arr = [1, 2, 3]; - async.groupBy(arr, function(val, next) { + async.groupBy(arr, (val, next) => { if (val === 1) { return next(null, val+1); } else if (val === 2) { - async.setImmediate(function() { + async.setImmediate(() => { return next(null, val+1); }); } else { return next('error'); } - }, function(err, result) { + }, (err, result) => { expect(err).to.not.eql(null); expect(result).to.eql({2: [1]}); async.setImmediate(done); @@ -172,19 +172,19 @@ describe('groupBy', function() { }); }); - context('groupByLimit', function() { + context('groupByLimit', () => { var obj = {a: 'b', b: 'c', c: 'd'}; - it('basics', function(done) { + it('basics', (done) => { var running = 0; var concurrency = {'b': 2, 'c': 2, 'd': 1}; - async.groupByLimit(obj, 2, function(val, next) { + async.groupByLimit(obj, 2, (val, next) => { running++; - async.setImmediate(function() { + async.setImmediate(() => { expect(running).to.equal(concurrency[val]); running--; next(null, val); }); - }, function(err, result) { + }, (err, result) => { expect(running).to.equal(0); expect(err).to.eql(null); expect(result).to.eql({'b': ['b'], 'c': ['c'], 'd': ['d']}) @@ -192,35 +192,35 @@ describe('groupBy', function() { }); }); - it('error', function(done) { - async.groupByLimit(obj, 1, function(val, next) { + it('error', (done) => { + async.groupByLimit(obj, 1, (val, next) => { if (val === 'c') { return next(new Error('fail')); } next(null, val); - }, function(err, result) { + }, (err, result) => { expect(err).to.not.eql(null); expect(result).to.eql({b: ['b']}); done(); }); }); - it('handles empty object', function(done) { - async.groupByLimit({}, 2, function(val, next) { + it('handles empty object', (done) => { + async.groupByLimit({}, 2, (val, next) => { assert(false, 'iteratee should not be called'); next(); - }, function(err, result) { + }, (err, result) => { expect(err).to.eql(null); expect(result).to.eql({}); done(); }); }); - it('handles undefined', function(done) { - async.groupByLimit(undefined, 2, function(val, next) { + it('handles undefined', (done) => { + async.groupByLimit(undefined, 2, (val, next) => { assert(false, 'iteratee should not be called'); next(); - }, function(err, result) { + }, (err, result) => { expect(err).to.eql(null); expect(result).to.eql({}); done(); @@ -229,7 +229,7 @@ describe('groupBy', function() { it('limit exceeds size', function(done) { var callOrder = []; - async.groupByLimit([3, 2, 2, 1], 10, groupByIteratee.bind(this, callOrder), function(err, result) { + async.groupByLimit([3, 2, 2, 1], 10, groupByIteratee.bind(this, callOrder), (err, result) => { expect(err).to.eql(null); expect(result).to.eql({2: [1], 3: [2, 2], 4: [3]}); expect(callOrder).to.eql([1, 2, 2, 3]); @@ -239,7 +239,7 @@ describe('groupBy', function() { it('limit equal size', function(done) { var callOrder = []; - async.groupByLimit([3, 2, 2, 1], 4, groupByIteratee.bind(this, callOrder), function(err, result) { + async.groupByLimit([3, 2, 2, 1], 4, groupByIteratee.bind(this, callOrder), (err, result) => { expect(err).to.eql(null); expect(result).to.eql({2: [1], 3: [2, 2], 4: [3]}); expect(callOrder).to.eql([1, 2, 2, 3]); @@ -247,58 +247,58 @@ describe('groupBy', function() { }); }); - it('zero limit', function() { + it('zero limit', () => { expect(() => { - async.groupByLimit([3, 2, 2, 1], 0, function(val, next) { + async.groupByLimit([3, 2, 2, 1], 0, (val, next) => { assert(false, 'iteratee should not be called'); next(); - }, function() { + }, () => { assert(false, 'should not be called'); }); }).to.throw(/concurrency limit/) }); - it('does not continue replenishing after error', function(done) { + it('does not continue replenishing after error', (done) => { var started = 0; var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; var delay = 10; var limit = 3; var maxTime = 10 * arr.length; - async.groupByLimit(arr, limit, function(val, next) { + async.groupByLimit(arr, limit, (val, next) => { started++; if (started === 3) { return next(new Error('fail')); } - setTimeout(function() { + setTimeout(() => { next(); }, delay); - }, function(err, result) { + }, (err, result) => { expect(err).to.not.eql(null); expect(result).to.eql({}); }); - setTimeout(function() { + setTimeout(() => { expect(started).to.equal(3); done(); }, maxTime); }); }); - context('groupBySeries', function() { + context('groupBySeries', () => { var obj = {a: 'b', b: 'c', c: 'd'}; - it('basics', function(done) { + it('basics', (done) => { var running = 0; var concurrency = {'b': 1, 'c': 1, 'd': 1}; - async.groupBySeries(obj, function(val, next) { + async.groupBySeries(obj, (val, next) => { running++; - async.setImmediate(function() { + async.setImmediate(() => { expect(running).to.equal(concurrency[val]); running--; next(null, val); }); - }, function(err, result) { + }, (err, result) => { expect(running).to.equal(0); expect(err).to.eql(null); expect(result).to.eql({'b': ['b'], 'c': ['c'], 'd': ['d']}); @@ -306,45 +306,45 @@ describe('groupBy', function() { }); }); - it('error', function(done) { - async.groupBySeries(obj, function(val, next) { + it('error', (done) => { + async.groupBySeries(obj, (val, next) => { if (val === 'c') { return next(new Error('fail')); } next(null, val); - }, function(err, result) { + }, (err, result) => { expect(err).to.not.eql(null); expect(result).to.eql({b: ['b']}); done(); }); }); - it('handles arrays', function(done) { - async.groupBySeries(['a', 'a', 'b'], function(val, next) { + it('handles arrays', (done) => { + async.groupBySeries(['a', 'a', 'b'], (val, next) => { next(null, val); - }, function(err, result) { + }, (err, result) => { expect(err).to.eql(null); expect(result).to.eql({'a': ['a', 'a'], 'b': ['b']}); done(); }); }); - it('handles empty object', function(done) { - async.groupBySeries({}, function(val, next) { + it('handles empty object', (done) => { + async.groupBySeries({}, (val, next) => { assert(false, 'iteratee should not be called'); next(); - }, function(err, result) { + }, (err, result) => { expect(err).to.eql(null); expect(result).to.eql({}); done(); }); }); - it('handles undefined', function(done) { - async.groupBySeries(undefined, function(val, next) { + it('handles undefined', (done) => { + async.groupBySeries(undefined, (val, next) => { assert(false, 'iteratee should not be called'); next(); - }, function(err, result) { + }, (err, result) => { expect(err).to.eql(null); expect(result).to.eql({}); done(); diff --git a/test/linked_list.js b/test/linked_list.js index ab4b22335..ac29f1a4b 100644 --- a/test/linked_list.js +++ b/test/linked_list.js @@ -1,8 +1,8 @@ var DLL = require('../lib/internal/DoublyLinkedList').default; var expect = require('chai').expect; -describe('DoublyLinkedList', function () { - it('toArray', function() { +describe('DoublyLinkedList', () => { + it('toArray', () => { var list = new DLL(); expect(list.toArray()).to.eql([]); @@ -12,63 +12,63 @@ describe('DoublyLinkedList', function () { expect(list.toArray()).to.eql([0, 1, 2, 3, 4]); }); - it('remove', function() { + it('remove', () => { var list = new DLL(); for (var i = 0; i < 5; i++) { list.push({data: i}); } - list.remove(function (node) { + list.remove((node) => { return node.data === 3; }) expect(list.toArray()).to.eql([0, 1, 2, 4]); }); - it('remove (head)', function() { + it('remove (head)', () => { var list = new DLL(); for (var i = 0; i < 5; i++) { list.push({data: i}); } - list.remove(function (node) { + list.remove((node) => { return node.data === 0; }) expect(list.toArray()).to.eql([1, 2, 3, 4]); }); - it('remove (tail)', function() { + it('remove (tail)', () => { var list = new DLL(); for (var i = 0; i < 5; i++) { list.push({data: i}); } - list.remove(function (node) { + list.remove((node) => { return node.data === 4; }) expect(list.toArray()).to.eql([0, 1, 2, 3]); }); - it('remove (all)', function() { + it('remove (all)', () => { var list = new DLL(); for (var i = 0; i < 5; i++) { list.push({data: i}); } - list.remove(function (node) { + list.remove((node) => { return node.data < 5; }) expect(list.toArray()).to.eql([]); }); - it('empty', function() { + it('empty', () => { var list = new DLL(); for (var i = 0; i < 5; i++) { diff --git a/test/map.js b/test/map.js index eb0c3eacd..c104ab996 100644 --- a/test/map.js +++ b/test/map.js @@ -2,10 +2,10 @@ var async = require('../lib'); var expect = require('chai').expect; var assert = require('assert'); -describe("map", function() { +describe("map", () => { function mapIteratee(call_order, x, callback) { - setTimeout(function() { + setTimeout(() => { call_order.push(x); callback(null, x * 2); }, x * 25); @@ -13,7 +13,7 @@ describe("map", function() { it('basic', function(done) { var call_order = []; - async.map([1, 3, 2], mapIteratee.bind(this, call_order), function(err, results) { + async.map([1, 3, 2], mapIteratee.bind(this, call_order), (err, results) => { assert(err === null, err + " passed instead of 'null'"); expect(call_order).to.eql([1, 2, 3]); expect(results).to.eql([2, 6, 4]); @@ -21,14 +21,14 @@ describe("map", function() { }); }); - it('with reflect', function(done) { + it('with reflect', (done) => { var call_order = []; - async.map([1, 3, 2], async.reflect(function(item, cb) { - setTimeout(function() { + async.map([1, 3, 2], async.reflect((item, cb) => { + setTimeout(() => { call_order.push(item); cb(null, item * 2); }, item * 25); - }), function(err, results) { + }), (err, results) => { assert(err === null, err + " passed instead of 'null'"); expect(call_order).to.eql([1, 2, 3]); expect(results).to.eql([{ @@ -42,10 +42,10 @@ describe("map", function() { }); }); - it('error with reflect', function(done) { + it('error with reflect', (done) => { var call_order = []; - async.map([-1, 1, 3, 2], async.reflect(function(item, cb) { - setTimeout(function() { + async.map([-1, 1, 3, 2], async.reflect((item, cb) => { + setTimeout(() => { call_order.push(item); if (item < 0) { cb('number less then zero'); @@ -53,7 +53,7 @@ describe("map", function() { cb(null, item * 2); } }, item * 25); - }), function(err, results) { + }), (err, results) => { assert(err === null, err + " passed instead of 'null'"); expect(call_order).to.eql([-1, 1, 2, 3]); expect(results).to.eql([{ @@ -69,21 +69,21 @@ describe("map", function() { }); }); - it('map original untouched', function(done) { + it('map original untouched', (done) => { var a = [1, 2, 3]; - async.map(a, function(x, callback) { + async.map(a, (x, callback) => { callback(null, x * 2); - }, function(err, results) { + }, (err, results) => { expect(results).to.eql([2, 4, 6]); expect(a).to.eql([1, 2, 3]); done(); }); }); - it('map without main callback', function(done) { + it('map without main callback', (done) => { var a = [1, 2, 3]; var r = []; - async.map(a, function(x, callback) { + async.map(a, (x, callback) => { r.push(x); var done_ = r.length == a.length; callback(null); @@ -94,35 +94,35 @@ describe("map", function() { }); }); - it('map error', function(done) { - async.map([1, 2, 3], function(x, callback) { + it('map error', (done) => { + async.map([1, 2, 3], (x, callback) => { callback('error'); - }, function(err) { + }, (err) => { expect(err).to.equal('error'); }); setTimeout(done, 50); }); - it('map undefined array', function(done) { - async.map(undefined, function(x, callback) { + it('map undefined array', (done) => { + async.map(undefined, (x, callback) => { callback(); - }, function(err, result) { + }, (err, result) => { expect(err).to.equal(null); expect(result).to.eql([]); }); setTimeout(done, 50); }); - it('map object', function(done) { + it('map object', (done) => { async.map({ a: 1, b: 2, c: 3 - }, function(val, callback) { + }, (val, callback) => { callback(null, val * 2); - }, function(err, result) { + }, (err, result) => { if (err) throw err; - expect(Object.prototype.toString.call(result)).to.equal('[object Array]'); + expect(Array.isArray(result)).to.equal(true); expect(result).to.contain(2); expect(result).to.contain(4); expect(result).to.contain(6); @@ -132,7 +132,7 @@ describe("map", function() { it('mapSeries', function(done) { var call_order = []; - async.mapSeries([1, 3, 2], mapIteratee.bind(this, call_order), function(err, results) { + async.mapSeries([1, 3, 2], mapIteratee.bind(this, call_order), (err, results) => { assert(err === null, err + " passed instead of 'null'"); expect(call_order).to.eql([1, 3, 2]); expect(results).to.eql([2, 6, 4]); @@ -140,33 +140,33 @@ describe("map", function() { }); }); - it('mapSeries error', function(done) { - async.mapSeries([1, 2, 3], function(x, callback) { + it('mapSeries error', (done) => { + async.mapSeries([1, 2, 3], (x, callback) => { callback('error'); - }, function(err) { + }, (err) => { expect(err).to.equal('error'); }); setTimeout(done, 50); }); - it('mapSeries undefined array', function(done) { - async.mapSeries(undefined, function(x, callback) { + it('mapSeries undefined array', (done) => { + async.mapSeries(undefined, (x, callback) => { callback(); - }, function(err, result) { + }, (err, result) => { expect(err).to.equal(null); expect(result).to.eql([]); }); setTimeout(done, 50); }); - it('mapSeries object', function(done) { + it('mapSeries object', (done) => { async.mapSeries({ a: 1, b: 2, c: 3 - }, function(val, callback) { + }, (val, callback) => { callback(null, val * 2); - }, function(err, result) { + }, (err, result) => { if (err) throw err; expect(result).to.contain(2); expect(result).to.contain(4); @@ -177,7 +177,7 @@ describe("map", function() { it('mapLimit', function(done) { var call_order = []; - async.mapLimit([2, 4, 3], 2, mapIteratee.bind(this, call_order), function(err, results) { + async.mapLimit([2, 4, 3], 2, mapIteratee.bind(this, call_order), (err, results) => { assert(err === null, err + " passed instead of 'null'"); expect(call_order).to.eql([2, 4, 3]); expect(results).to.eql([4, 8, 6]); @@ -185,21 +185,21 @@ describe("map", function() { }); }); - it('mapLimit empty array', function(done) { - async.mapLimit([], 2, function(x, callback) { + it('mapLimit empty array', (done) => { + async.mapLimit([], 2, (x, callback) => { assert(false, 'iteratee should not be called'); callback(); - }, function(err) { + }, (err) => { if (err) throw err; assert(true, 'should call callback'); }); setTimeout(done, 25); }); - it('mapLimit undefined array', function(done) { - async.mapLimit(undefined, 2, function(x, callback) { + it('mapLimit undefined array', (done) => { + async.mapLimit(undefined, 2, (x, callback) => { callback(); - }, function(err, result) { + }, (err, result) => { expect(err).to.equal(null); expect(result).to.eql([]); }); @@ -208,7 +208,7 @@ describe("map", function() { it('mapLimit limit exceeds size', function(done) { var call_order = []; - async.mapLimit([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 20, mapIteratee.bind(this, call_order), function(err, results) { + async.mapLimit([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 20, mapIteratee.bind(this, call_order), (err, results) => { expect(call_order).to.eql([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); expect(results).to.eql([0, 2, 4, 6, 8, 10, 12, 14, 16, 18]); done(); @@ -217,90 +217,90 @@ describe("map", function() { it('mapLimit limit equal size', function(done) { var call_order = []; - async.mapLimit([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 10, mapIteratee.bind(this, call_order), function(err, results) { + async.mapLimit([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 10, mapIteratee.bind(this, call_order), (err, results) => { expect(call_order).to.eql([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); expect(results).to.eql([0, 2, 4, 6, 8, 10, 12, 14, 16, 18]); done(); }); }); - it('mapLimit zero limit', function() { + it('mapLimit zero limit', () => { expect(() => { - async.mapLimit([0, 1, 2, 3, 4, 5], 0, function(x, callback) { + async.mapLimit([0, 1, 2, 3, 4, 5], 0, (x, callback) => { assert(false, 'iteratee should not be called'); callback(); - }, function() { + }, () => { assert(false, 'should not be called'); }); }).to.throw(/concurrency limit/) }); - it('mapLimit error', function(done) { + it('mapLimit error', (done) => { var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; var call_order = []; - async.mapLimit(arr, 3, function(x, callback) { + async.mapLimit(arr, 3, (x, callback) => { call_order.push(x); if (x === 2) { callback('error'); } - }, function(err) { + }, (err) => { expect(call_order).to.eql([0, 1, 2]); expect(err).to.equal('error'); }); setTimeout(done, 25); }); - it('mapLimit does not continue replenishing after error', function(done) { + it('mapLimit does not continue replenishing after error', (done) => { var started = 0; var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; var delay = 10; var limit = 3; var maxTime = 10 * arr.length; - async.mapLimit(arr, limit, function(x, callback) { + async.mapLimit(arr, limit, (x, callback) => { started++; if (started === 3) { return callback(new Error("Test Error")); } - setTimeout(function() { + setTimeout(() => { callback(); }, delay); - }, function() {}); + }, () => {}); - setTimeout(function() { + setTimeout(() => { expect(started).to.equal(3); done(); }, maxTime); }); - it('map with Map', function(done) { + it('map with Map', (done) => { if (typeof Map !== 'function') return done(); var map = new Map(); map.set(1, "a"); map.set(2, "b"); - async.map(map, function(val, cb) { + async.map(map, (val, cb) => { cb(null, val); - }, function(err, result) { + }, (err, result) => { assert(Array.isArray(result), "map should return an array for an iterable"); done(); }); }); // Issue 1106 on github: https://github.com/caolan/async/issues/1106 - it('map main callback is called only once', function(done) { - async.map([1, 2], function(item, callback) { + it('map main callback is called only once', (done) => { + async.map([1, 2], (item, callback) => { try { callback(item); } catch (exception) { - expect(function() { + expect(() => { callback(exception); }).to.throw(/already called/); done(); } - }, function() { + }, () => { throw new Error(); }); }); diff --git a/test/mapValues.js b/test/mapValues.js index 612feffcb..83cc1260b 100644 --- a/test/mapValues.js +++ b/test/mapValues.js @@ -1,25 +1,25 @@ var async = require('../lib'); var expect = require('chai').expect; -describe('mapValues', function () { +describe('mapValues', () => { var obj = {a: 1, b: 2, c: 3}; - context('mapValuesLimit', function () { - it('basics', function (done) { + context('mapValuesLimit', () => { + it('basics', (done) => { var running = 0; var concurrency = { a: 2, b: 2, c: 1 }; - async.mapValuesLimit(obj, 2, function (val, key, next) { + async.mapValuesLimit(obj, 2, (val, key, next) => { running++; - async.setImmediate(function () { + async.setImmediate(() => { expect(running).to.equal(concurrency[key]); running--; next(null, key + val); }); - }, function (err, result) { + }, (err, result) => { expect(running).to.equal(0); expect(err).to.eql(null); expect(result).to.eql({a: 'a1', b: 'b2', c: 'c3'}); @@ -27,13 +27,13 @@ describe('mapValues', function () { }); }); - it('error', function (done) { - async.mapValuesLimit(obj, 1, function(val, key, next) { + it('error', (done) => { + async.mapValuesLimit(obj, 1, (val, key, next) => { if (key === 'b') { return next(new Error("fail")); } next(null, val); - }, function (err, result) { + }, (err, result) => { expect(err).to.not.eql(null); expect(result).to.eql({a: 1}); done(); @@ -41,22 +41,22 @@ describe('mapValues', function () { }); }); - context('mapValues', function () { - it('basics', function (done) { + context('mapValues', () => { + it('basics', (done) => { var running = 0; var concurrency = { a: 3, b: 2, c: 1 }; - async.mapValues(obj, function (val, key, next) { + async.mapValues(obj, (val, key, next) => { running++; - async.setImmediate(function () { + async.setImmediate(() => { expect(running).to.equal(concurrency[key]); running--; next(null, key + val); }); - }, function (err, result) { + }, (err, result) => { expect(running).to.equal(0); expect(err).to.eql(null); expect(result).to.eql({a: 'a1', b: 'b2', c: 'c3'}); @@ -65,22 +65,22 @@ describe('mapValues', function () { }); }); - context('mapValuesSeries', function () { - it('basics', function (done) { + context('mapValuesSeries', () => { + it('basics', (done) => { var running = 0; var concurrency = { a: 1, b: 1, c: 1 }; - async.mapValuesSeries(obj, function (val, key, next) { + async.mapValuesSeries(obj, (val, key, next) => { running++; - async.setImmediate(function () { + async.setImmediate(() => { expect(running).to.equal(concurrency[key]); running--; next(null, key + val); }); - }, function (err, result) { + }, (err, result) => { expect(running).to.equal(0); expect(err).to.eql(null); expect(result).to.eql({a: 'a1', b: 'b2', c: 'c3'}); diff --git a/test/memoize.js b/test/memoize.js index 2cadafd48..b2c11b382 100644 --- a/test/memoize.js +++ b/test/memoize.js @@ -2,25 +2,25 @@ var async = require('../lib'); var expect = require('chai').expect; var assert = require('assert'); -describe("memoize", function() { +describe("memoize", () => { - it('memoize', function(done) { + it('memoize', (done) => { var call_order = []; var fn = function (arg1, arg2, callback) { - async.setImmediate(function () { + async.setImmediate(() => { call_order.push(['fn', arg1, arg2]); callback(null, arg1 + arg2); }); }; var fn2 = async.memoize(fn); - fn2(1, 2, function (err, result) { + fn2(1, 2, (err, result) => { assert(err === null, err + " passed instead of 'null'"); expect(result).to.equal(3); - fn2(1, 2, function (err, result) { + fn2(1, 2, (err, result) => { expect(result).to.equal(3); - fn2(2, 2, function (err, result) { + fn2(2, 2, (err, result) => { expect(result).to.equal(4); expect(call_order).to.eql([['fn',1,2], ['fn',2,2]]); done(); @@ -29,21 +29,21 @@ describe("memoize", function() { }); }); - it('maintains asynchrony', function(done) { + it('maintains asynchrony', (done) => { var call_order = []; var fn = function (arg1, arg2, callback) { call_order.push(['fn', arg1, arg2]); - async.setImmediate(function () { + async.setImmediate(() => { call_order.push(['cb', arg1, arg2]); callback(null, arg1 + arg2); }); }; var fn2 = async.memoize(fn); - fn2(1, 2, function (err, result) { + fn2(1, 2, (err, result) => { expect(result).to.equal(3); - fn2(1, 2, function (err, result) { + fn2(1, 2, (err, result) => { expect(result).to.equal(3); async.nextTick(memoize_done); call_order.push('tick3'); @@ -57,9 +57,9 @@ describe("memoize", function() { ['fn',1,2], // initial async call 'tick1', // async caller ['cb',1,2], // async callback - // ['fn',1,2], // memoized // memoized async body + // ['fn',1,2], // memoized // memoized async body 'tick2', // handler for first async call - // ['cb',1,2], // memoized // memoized async response body + // ['cb',1,2], // memoized // memoized async response body 'tick3' // handler for memoized async call ]; expect(call_order).to.eql(async_call_order); @@ -67,23 +67,23 @@ describe("memoize", function() { } }); - it('unmemoize', function(done) { + it('unmemoize', (done) => { var call_order = []; var fn = function (arg1, arg2, callback) { call_order.push(['fn', arg1, arg2]); - async.setImmediate(function () { + async.setImmediate(() => { callback(null, arg1 + arg2); }); }; var fn2 = async.memoize(fn); var fn3 = async.unmemoize(fn2); - fn3(1, 2, function (err, result) { + fn3(1, 2, (err, result) => { expect(result).to.equal(3); - fn3(1, 2, function (err, result) { + fn3(1, 2, (err, result) => { expect(result).to.equal(3); - fn3(2, 2, function (err, result) { + fn3(2, 2, (err, result) => { expect(result).to.equal(4); expect(call_order).to.eql([['fn',1,2], ['fn',1,2], ['fn',2,2]]); done(); @@ -92,40 +92,40 @@ describe("memoize", function() { }); }); - it('unmemoize a not memoized function', function(done) { + it('unmemoize a not memoized function', (done) => { var fn = function (arg1, arg2, callback) { callback(null, arg1 + arg2); }; var fn2 = async.unmemoize(fn); - fn2(1, 2, function(err, result) { + fn2(1, 2, (err, result) => { expect(result).to.equal(3); done(); }); }); - it('error', function(done) { + it('error', (done) => { var testerr = new Error('test'); var fn = function (arg1, arg2, callback) { callback(testerr, arg1 + arg2); }; - async.memoize(fn)(1, 2, function (err) { + async.memoize(fn)(1, 2, (err) => { expect(err).to.equal(testerr); done(); }); }); - it('should not memoize result if error occurs', function(done) { + it('should not memoize result if error occurs', (done) => { var testerr = new Error('test'); var fn = function (arg1, arg2, callback) { callback(testerr, arg1 + arg2); }; var memoized = async.memoize(fn); - memoized(1, 2, function (err) { + memoized(1, 2, (err) => { expect(err).to.equal(testerr); testerr = null; - memoized(1, 3, function (err, result) { + memoized(1, 3, (err, result) => { expect(err).to.equal(null); expect(result).to.equal(4); done(); @@ -133,63 +133,63 @@ describe("memoize", function() { }); }); - it('multiple calls', function(done) { + it('multiple calls', (done) => { var fn = function (arg1, arg2, callback) { assert(true); - setTimeout(function(){ + setTimeout(() => { callback(null, arg1, arg2); }, 10); }; var fn2 = async.memoize(fn); - fn2(1, 2, function(err, result) { + fn2(1, 2, (err, result) => { expect(result).to.equal(1, 2); }); - fn2(1, 2, function(err, result) { + fn2(1, 2, (err, result) => { expect(result).to.equal(1, 2); done(); }); }); - it('custom hash function', function(done) { + it('custom hash function', (done) => { var fn = function (arg1, arg2, callback) { callback(null, arg1 + arg2); }; - var fn2 = async.memoize(fn, function () { + var fn2 = async.memoize(fn, () => { return 'custom hash'; }); - fn2(1, 2, function (err, result) { + fn2(1, 2, (err, result) => { expect(result).to.equal(3); - fn2(2, 2, function (err, result) { + fn2(2, 2, (err, result) => { expect(result).to.equal(3); done(); }); }); }); - it('manually added memo value', function(done) { - var fn = async.memoize(function() { + it('manually added memo value', (done) => { + var fn = async.memoize(() => { throw new Error("Function should never be called"); }); fn.memo.foo = ["bar"]; - fn("foo", function(val) { + fn("foo", (err, val) => { expect(val).to.equal("bar"); done(); }); }); - it('avoid constructor key return undefined', function(done) { - var fn = async.memoize(function(name, callback) { - setTimeout(function(){ + it('avoid constructor key return undefined', (done) => { + var fn = async.memoize((name, callback) => { + setTimeout(() => { callback(null, name); }, 100); }); - fn('constructor', function(error, results) { + fn('constructor', (error, results) => { expect(results).to.equal('constructor'); done(); }); }); - it('avoid __proto__ key return undefined', function(done) { + it('avoid __proto__ key return undefined', (done) => { // Skip test if there is a Object.create bug (node 0.10 and some Chrome 30x versions) var x = Object.create(null); /* jshint proto: true */ @@ -198,24 +198,24 @@ describe("memoize", function() { return done(); } - var fn = async.memoize(function(name, callback) { - setTimeout(function(){ + var fn = async.memoize((name, callback) => { + setTimeout(() => { callback(null, name); }, 100); }); - fn('__proto__', function(error, results) { + fn('__proto__', (error, results) => { expect(results).to.equal('__proto__'); done(); }); }); - it('allow hasOwnProperty as key', function(done) { - var fn = async.memoize(function(name, callback) { - setTimeout(function(){ + it('allow hasOwnProperty as key', (done) => { + var fn = async.memoize((name, callback) => { + setTimeout(() => { callback(null, name); }, 100); }); - fn('hasOwnProperty', function(error, results) { + fn('hasOwnProperty', (error, results) => { expect(results).to.equal('hasOwnProperty'); done(); }); diff --git a/test/nextTick.js b/test/nextTick.js index e590d9410..71af1a012 100644 --- a/test/nextTick.js +++ b/test/nextTick.js @@ -1,31 +1,31 @@ var async = require('../lib'); var expect = require('chai').expect; -describe("nextTick", function () { +describe("nextTick", () => { - it('basics', function(done){ + it('basics', (done) => { var call_order = []; - async.nextTick(function(){call_order.push('two');}); + async.nextTick(() => {call_order.push('two');}); call_order.push('one'); - setTimeout(function(){ + setTimeout(() => { expect(call_order).to.eql(['one','two']); done(); }, 50); }); - it('nextTick in the browser @nodeonly', function(done){ + it('nextTick in the browser @nodeonly', (done) => { var call_order = []; - async.nextTick(function(){call_order.push('two');}); + async.nextTick(() => {call_order.push('two');}); call_order.push('one'); - setTimeout(function(){ + setTimeout(() => { expect(call_order).to.eql(['one','two']); done(); }, 50); }); - it("extra args", function (done) { - async.nextTick(function (a, b, c) { + it("extra args", (done) => { + async.nextTick((a, b, c) => { expect([a, b, c]).to.eql([1, 2, 3]); done(); }, 1, 2, 3); diff --git a/test/parallel.js b/test/parallel.js index c7de8881b..1fadaa8a9 100644 --- a/test/parallel.js +++ b/test/parallel.js @@ -3,31 +3,31 @@ var expect = require('chai').expect; var assert = require('assert'); var getFunctionsObject = require('./support/get_function_object'); -describe('parallel', function() { +describe('parallel', () => { - it('parallel', function(done) { + it('parallel', (done) => { var call_order = []; async.parallel([ function(callback){ - setTimeout(function(){ + setTimeout(() => { call_order.push(1); callback(null, 1); }, 50); }, function(callback){ - setTimeout(function(){ + setTimeout(() => { call_order.push(2); callback(null, 2); }, 100); }, function(callback){ - setTimeout(function(){ + setTimeout(() => { call_order.push(3); callback(null, 3,3); }, 25); } ], - function(err, results){ + (err, results) => { assert(err === null, err + " passed instead of 'null'"); expect(call_order).to.eql([3,1,2]); expect(results).to.eql([1,2,[3,3]]); @@ -35,15 +35,15 @@ describe('parallel', function() { }); }); - it('parallel empty array', function(done) { - async.parallel([], function(err, results){ + it('parallel empty array', (done) => { + async.parallel([], (err, results) => { assert(err === null, err + " passed instead of 'null'"); expect(results).to.eql([]); done(); }); }); - it('parallel error', function(done) { + it('parallel error', (done) => { async.parallel([ function(callback){ callback('error', 1); @@ -52,22 +52,22 @@ describe('parallel', function() { callback('error2', 2); } ], - function(err){ + (err) => { expect(err).to.equal('error'); }); setTimeout(done, 100); }); - it('parallel no callback', function(done) { + it('parallel no callback', (done) => { async.parallel([ function(callback){callback();}, function(callback){callback(); done();}, ]); }); - it('parallel object', function(done) { + it('parallel object', (done) => { var call_order = []; - async.parallel(getFunctionsObject(call_order), function(err, results){ + async.parallel(getFunctionsObject(call_order), (err, results) => { expect(err).to.equal(null); expect(call_order).to.eql([3,1,2]); expect(results).to.eql({ @@ -80,30 +80,30 @@ describe('parallel', function() { }); // Issue 10 on github: https://github.com/caolan/async/issues#issue/10 - it('paralel falsy return values', function(done) { + it('paralel falsy return values', (done) => { function taskFalse(callback) { - async.nextTick(function() { + async.nextTick(() => { callback(null, false); }); } function taskUndefined(callback) { - async.nextTick(function() { + async.nextTick(() => { callback(null, undefined); }); } function taskEmpty(callback) { - async.nextTick(function() { + async.nextTick(() => { callback(null); }); } function taskNull(callback) { - async.nextTick(function() { + async.nextTick(() => { callback(null, null); }); } async.parallel( [taskFalse, taskUndefined, taskEmpty, taskNull], - function(err, results) { + (err, results) => { expect(results.length).to.equal(4); assert.strictEqual(results[0], false); assert.strictEqual(results[1], undefined); @@ -115,30 +115,30 @@ describe('parallel', function() { }); - it('parallel limit', function(done) { + it('parallel limit', (done) => { var call_order = []; async.parallelLimit([ function(callback){ - setTimeout(function(){ + setTimeout(() => { call_order.push(1); callback(null, 1); }, 50); }, function(callback){ - setTimeout(function(){ + setTimeout(() => { call_order.push(2); callback(null, 2); }, 100); }, function(callback){ - setTimeout(function(){ + setTimeout(() => { call_order.push(3); callback(null, 3,3); }, 25); } ], 2, - function(err, results){ + (err, results) => { assert(err === null, err + " passed instead of 'null'"); expect(call_order).to.eql([1,3,2]); expect(results).to.eql([1,2,[3,3]]); @@ -146,15 +146,15 @@ describe('parallel', function() { }); }); - it('parallel limit empty array', function(done) { - async.parallelLimit([], 2, function(err, results){ + it('parallel limit empty array', (done) => { + async.parallelLimit([], 2, (err, results) => { assert(err === null, err + " passed instead of 'null'"); expect(results).to.eql([]); done(); }); }); - it('parallel limit error', function(done) { + it('parallel limit error', (done) => { async.parallelLimit([ function(callback){ callback('error', 1); @@ -164,22 +164,22 @@ describe('parallel', function() { } ], 1, - function(err){ + (err) => { expect(err).to.equal('error'); }); setTimeout(done, 100); }); - it('parallel limit no callback', function(done) { + it('parallel limit no callback', (done) => { async.parallelLimit([ function(callback){callback();}, function(callback){callback(); done();}, ], 1); }); - it('parallel limit object', function(done) { + it('parallel limit object', (done) => { var call_order = []; - async.parallelLimit(getFunctionsObject(call_order), 2, function(err, results){ + async.parallelLimit(getFunctionsObject(call_order), 2, (err, results) => { expect(err).to.equal(null); expect(call_order).to.eql([1,3,2]); expect(results).to.eql({ @@ -191,7 +191,7 @@ describe('parallel', function() { }); }); - it('parallel limit canceled', function(done) { + it('parallel limit canceled', (done) => { const call_order = [] async.parallelLimit([ function(callback){ @@ -208,7 +208,7 @@ describe('parallel', function() { } ], 1, - function(){ + () => { throw new Error('should not get here') }); setTimeout(() => { @@ -217,17 +217,17 @@ describe('parallel', function() { }, 25); }); - it('parallel call in another context @nycinvalid @nodeonly', function(done) { + it('parallel call in another context @nycinvalid @nodeonly', (done) => { var vm = require('vm'); var sandbox = { - async: async, - done: done + async, + done }; var fn = "(" + (function () { async.parallel([function (callback) { callback(); - }], function (err) { + }], (err) => { if (err) { return done(err); } @@ -238,19 +238,19 @@ describe('parallel', function() { vm.runInNewContext(fn, sandbox); }); - it('parallel error with reflect', function(done) { + it('parallel error with reflect', (done) => { async.parallel([ - async.reflect(function(callback){ + async.reflect((callback) => { callback('error', 1); }), - async.reflect(function(callback){ + async.reflect((callback) => { callback('error2', 2); }), - async.reflect(function(callback){ + async.reflect((callback) => { callback(null, 2); }) ], - function(err, results){ + (err, results) => { assert(err === null, err + " passed instead of 'null'"); expect(results).to.eql([ { error: 'error' }, @@ -261,24 +261,24 @@ describe('parallel', function() { }); }); - it('parallel object with reflect all (values and errors)', function(done) { + it('parallel object with reflect all (values and errors)', (done) => { var tasks = { - one: function(callback) { - setTimeout(function() { + one(callback) { + setTimeout(() => { callback(null, 'one'); }, 200); }, - two: function(callback) { + two(callback) { callback('two'); }, - three: function(callback) { - setTimeout(function() { + three(callback) { + setTimeout(() => { callback(null, 'three'); }, 100); } }; - async.parallel(async.reflectAll(tasks), function(err, results) { + async.parallel(async.reflectAll(tasks), (err, results) => { expect(results).to.eql({ one: { value: 'one' }, two: { error: 'two' }, @@ -288,29 +288,29 @@ describe('parallel', function() { }) }); - it('parallel empty object with reflect all', function(done) { + it('parallel empty object with reflect all', (done) => { var tasks = {}; - async.parallel(async.reflectAll(tasks), function(err, results) { + async.parallel(async.reflectAll(tasks), (err, results) => { expect(results).to.eql({}); done(); }) }); - it('parallel empty object with reflect all (errors)', function(done) { + it('parallel empty object with reflect all (errors)', (done) => { var tasks = { - one: function(callback) { + one(callback) { callback('one'); }, - two: function(callback) { + two(callback) { callback('two'); }, - three: function(callback) { + three(callback) { callback('three'); } }; - async.parallel(async.reflectAll(tasks), function(err, results) { + async.parallel(async.reflectAll(tasks), (err, results) => { expect(results).to.eql({ one: { error: 'one' }, two: { error: 'two' }, @@ -320,20 +320,20 @@ describe('parallel', function() { }) }); - it('parallel empty object with reflect all (values)', function(done) { + it('parallel empty object with reflect all (values)', (done) => { var tasks = { - one: function(callback) { + one(callback) { callback(null, 'one'); }, - two: function(callback) { + two(callback) { callback(null, 'two'); }, - three: function(callback) { + three(callback) { callback(null, 'three'); } }; - async.parallel(async.reflectAll(tasks), function(err, results) { + async.parallel(async.reflectAll(tasks), (err, results) => { expect(results).to.eql({ one: { value: 'one' }, two: { value: 'two' }, @@ -343,7 +343,7 @@ describe('parallel', function() { }) }); - it('parallel does not continue replenishing after error', function(done) { + it('parallel does not continue replenishing after error', (done) => { var started = 0; var arr = [ funcToCall, @@ -364,14 +364,14 @@ describe('parallel', function() { if (started === 3) { return callback(new Error ("Test Error")); } - setTimeout(function(){ + setTimeout(() => { callback(); }, delay); } - async.parallelLimit(arr, limit, function(){}); + async.parallelLimit(arr, limit, () => {}); - setTimeout(function(){ + setTimeout(() => { expect(started).to.equal(3); done(); }, maxTime); diff --git a/test/priorityQueue.js b/test/priorityQueue.js index f71e665cc..c3d5b7004 100644 --- a/test/priorityQueue.js +++ b/test/priorityQueue.js @@ -1,37 +1,37 @@ var async = require('../lib'); var expect = require('chai').expect; -describe('priorityQueue', function() { +describe('priorityQueue', () => { - it('priorityQueue', function (done) { + it('priorityQueue', (done) => { var call_order = []; // order of completion: 2,1,4,3 - var q = async.priorityQueue(function (task, callback) { + var q = async.priorityQueue((task, callback) => { call_order.push('process ' + task); callback('error', 'arg'); }, 1); - q.push(1, 1.4, function (err, arg) { + q.push(1, 1.4, (err, arg) => { expect(err).to.equal('error'); expect(arg).to.equal('arg'); expect(q.length()).to.equal(2); call_order.push('callback ' + 1); }); - q.push(2, 0.2, function (err, arg) { + q.push(2, 0.2, (err, arg) => { expect(err).to.equal('error'); expect(arg).to.equal('arg'); expect(q.length()).to.equal(3); call_order.push('callback ' + 2); }); - q.push(3, 3.8, function (err, arg) { + q.push(3, 3.8, (err, arg) => { expect(err).to.equal('error'); expect(arg).to.equal('arg'); expect(q.length()).to.equal(0); call_order.push('callback ' + 3); }); - q.push(4, 2.9, function (err, arg) { + q.push(4, 2.9, (err, arg) => { expect(err).to.equal('error'); expect(arg).to.equal('arg'); expect(q.length()).to.equal(1); @@ -53,7 +53,7 @@ describe('priorityQueue', function() { }; }); - it('concurrency', function (done) { + it('concurrency', (done) => { var call_order = [], delays = [160,80,240,80]; @@ -61,32 +61,32 @@ describe('priorityQueue', function() { // worker2: -1---4 // order of completion: 1,2,3,4 - var q = async.priorityQueue(function (task, callback) { - setTimeout(function () { + var q = async.priorityQueue((task, callback) => { + setTimeout(() => { call_order.push('process ' + task); callback('error', 'arg'); }, delays.splice(0,1)[0]); }, 2); - q.push(1, 1.4, function (err, arg) { + q.push(1, 1.4, (err, arg) => { expect(err).to.equal('error'); expect(arg).to.equal('arg'); expect(q.length()).to.equal(2); call_order.push('callback ' + 1); }); - q.push(2, 0.2, function (err, arg) { + q.push(2, 0.2, (err, arg) => { expect(err).to.equal('error'); expect(arg).to.equal('arg'); expect(q.length()).to.equal(1); call_order.push('callback ' + 2); }); - q.push(3, 3.8, function (err, arg) { + q.push(3, 3.8, (err, arg) => { expect(err).to.equal('error'); expect(arg).to.equal('arg'); expect(q.length()).to.equal(0); call_order.push('callback ' + 3); }); - q.push(4, 2.9, function (err, arg) { + q.push(4, 2.9, (err, arg) => { expect(err).to.equal('error'); expect(arg).to.equal('arg'); expect(q.length()).to.equal(0); @@ -108,12 +108,12 @@ describe('priorityQueue', function() { }; }); - it('pause in worker with concurrency', function(done) { + it('pause in worker with concurrency', (done) => { var call_order = []; - var q = async.priorityQueue(function (task, callback) { + var q = async.priorityQueue((task, callback) => { if (task.isLongRunning) { q.pause(); - setTimeout(function () { + setTimeout(() => { call_order.push(task.id); q.resume(); callback(); @@ -137,10 +137,10 @@ describe('priorityQueue', function() { }; }); - context('q.saturated(): ', function() { - it('should call the saturated callback if tasks length is concurrency', function(done) { + context('q.saturated(): ', () => { + it('should call the saturated callback if tasks length is concurrency', (done) => { var calls = []; - var q = async.priorityQueue(function(task, cb) { + var q = async.priorityQueue((task, cb) => { calls.push('process ' + task); async.setImmediate(cb); }, 4); @@ -149,7 +149,7 @@ describe('priorityQueue', function() { }; q.empty = function() { expect(calls.indexOf('saturated')).to.be.above(-1); - setTimeout(function() { + setTimeout(() => { expect(calls).eql([ 'process foo4', 'process foo3', @@ -167,18 +167,18 @@ describe('priorityQueue', function() { done(); }, 50); }; - q.push('foo0', 5, function () {calls.push('foo0 cb');}); - q.push('foo1', 4, function () {calls.push('foo1 cb');}); - q.push('foo2', 3, function () {calls.push('foo2 cb');}); - q.push('foo3', 2, function () {calls.push('foo3 cb');}); - q.push('foo4', 1, function () {calls.push('foo4 cb');}); + q.push('foo0', 5, () => {calls.push('foo0 cb');}); + q.push('foo1', 4, () => {calls.push('foo1 cb');}); + q.push('foo2', 3, () => {calls.push('foo2 cb');}); + q.push('foo3', 2, () => {calls.push('foo3 cb');}); + q.push('foo4', 1, () => {calls.push('foo4 cb');}); }); }); - context('q.unsaturated(): ',function() { - it('should have a default buffer property that equals 25% of the concurrenct rate', function(done) { + context('q.unsaturated(): ',() => { + it('should have a default buffer property that equals 25% of the concurrenct rate', (done) => { var calls = []; - var q = async.priorityQueue(function(task, cb) { + var q = async.priorityQueue((task, cb) => { // nop calls.push('process ' + task); async.setImmediate(cb); @@ -187,9 +187,9 @@ describe('priorityQueue', function() { done(); }); - it('should allow a user to change the buffer property', function(done) { + it('should allow a user to change the buffer property', (done) => { var calls = []; - var q = async.priorityQueue(function(task, cb) { + var q = async.priorityQueue((task, cb) => { // nop calls.push('process ' + task); async.setImmediate(cb); @@ -200,9 +200,9 @@ describe('priorityQueue', function() { done(); }); - it('should call the unsaturated callback if tasks length is less than concurrency minus buffer', function(done) { + it('should call the unsaturated callback if tasks length is less than concurrency minus buffer', (done) => { var calls = []; - var q = async.priorityQueue(function(task, cb) { + var q = async.priorityQueue((task, cb) => { calls.push('process ' + task); setTimeout(cb, 10); }, 4); @@ -211,7 +211,7 @@ describe('priorityQueue', function() { }; q.empty = function() { expect(calls.indexOf('unsaturated')).to.be.above(-1); - setTimeout(function() { + setTimeout(() => { expect(calls).eql([ 'process foo4', 'process foo3', @@ -232,11 +232,11 @@ describe('priorityQueue', function() { done(); }, 50); }; - q.push('foo0', 5, function () {calls.push('foo0 cb');}); - q.push('foo1', 4, function () {calls.push('foo1 cb');}); - q.push('foo2', 3, function () {calls.push('foo2 cb');}); - q.push('foo3', 2, function () {calls.push('foo3 cb');}); - q.push('foo4', 1, function () {calls.push('foo4 cb');}); + q.push('foo0', 5, () => {calls.push('foo0 cb');}); + q.push('foo1', 4, () => {calls.push('foo1 cb');}); + q.push('foo2', 3, () => {calls.push('foo2 cb');}); + q.push('foo3', 2, () => {calls.push('foo3 cb');}); + q.push('foo4', 1, () => {calls.push('foo4 cb');}); }); }); }); diff --git a/test/queue.js b/test/queue.js index 4539c14be..66a3f2387 100644 --- a/test/queue.js +++ b/test/queue.js @@ -7,7 +7,7 @@ describe('queue', function(){ // several tests of these tests are flakey with timing issues this.retries(3); - it('basics', function(done) { + it('basics', (done) => { var call_order = []; var delays = [40,10,60,10]; @@ -17,32 +17,32 @@ describe('queue', function(){ // worker2: -2---3 // order of completion: 2,1,4,3 - var q = async.queue(function (task, callback) { - setTimeout(function () { + var q = async.queue((task, callback) => { + setTimeout(() => { call_order.push('process ' + task); callback('error', 'arg'); }, delays.shift()); }, 2); - q.push(1, function (err, arg) { + q.push(1, (err, arg) => { expect(err).to.equal('error'); expect(arg).to.equal('arg'); expect(q.length()).to.equal(1); call_order.push('callback ' + 1); }); - q.push(2, function (err, arg) { + q.push(2, (err, arg) => { expect(err).to.equal('error'); expect(arg).to.equal('arg'); expect(q.length()).to.equal(2); call_order.push('callback ' + 2); }); - q.push(3, function (err, arg) { + q.push(3, (err, arg) => { expect(err).to.equal('error'); expect(arg).to.equal('arg'); expect(q.length()).to.equal(0); call_order.push('callback ' + 3); }); - q.push(4, function (err, arg) { + q.push(4, (err, arg) => { expect(err).to.equal('error'); expect(arg).to.equal('arg'); expect(q.length()).to.equal(0); @@ -64,38 +64,38 @@ describe('queue', function(){ }; }); - it('default concurrency', function(done) { + it('default concurrency', (done) => { var call_order = [], delays = [40,10,60,10]; // order of completion: 1,2,3,4 - var q = async.queue(function (task, callback) { - setTimeout(function () { + var q = async.queue((task, callback) => { + setTimeout(() => { call_order.push('process ' + task); callback('error', 'arg'); }, delays.shift()); }); - q.push(1, function (err, arg) { + q.push(1, (err, arg) => { expect(err).to.equal('error'); expect(arg).to.equal('arg'); expect(q.length()).to.equal(3); call_order.push('callback ' + 1); }); - q.push(2, function (err, arg) { + q.push(2, (err, arg) => { expect(err).to.equal('error'); expect(arg).to.equal('arg'); expect(q.length()).to.equal(2); call_order.push('callback ' + 2); }); - q.push(3, function (err, arg) { + q.push(3, (err, arg) => { expect(err).to.equal('error'); expect(arg).to.equal('arg'); expect(q.length()).to.equal(1); call_order.push('callback ' + 3); }); - q.push(4, function (err, arg) { + q.push(4, (err, arg) => { expect(err).to.equal('error'); expect(arg).to.equal('arg'); expect(q.length()).to.equal(0); @@ -117,19 +117,19 @@ describe('queue', function(){ }; }); - it('zero concurrency', function(done){ - expect(function () { - async.queue(function (task, callback) { + it('zero concurrency', (done) => { + expect(() => { + async.queue((task, callback) => { callback(null, task); }, 0); }).to.throw(); done(); }); - it('error propagation', function(done){ + it('error propagation', (done) => { var results = []; - var q = async.queue(function (task, callback) { + var q = async.queue((task, callback) => { callback(task.name === 'foo' ? new Error('fooError') : null); }, 2); @@ -138,7 +138,7 @@ describe('queue', function(){ done(); }; - q.push({name: 'bar'}, function (err) { + q.push({name: 'bar'}, (err) => { if(err) { results.push('barError'); return; @@ -147,7 +147,7 @@ describe('queue', function(){ results.push('bar'); }); - q.push({name: 'foo'}, function (err) { + q.push({name: 'foo'}, (err) => { if(err) { results.push('fooError'); return; @@ -157,10 +157,10 @@ describe('queue', function(){ }); }); - it('global error handler', function(done){ + it('global error handler', (done) => { var results = []; - var q = async.queue(function (task, callback) { + var q = async.queue((task, callback) => { callback(task.name === 'foo' ? new Error('fooError') : null); }, 2); @@ -178,7 +178,7 @@ describe('queue', function(){ q.push({name: 'foo'}); - q.push({name: 'bar'}, function(error) { + q.push({name: 'bar'}, (error) => { expect(error).to.not.exist; results.push('bar'); }); @@ -190,10 +190,10 @@ describe('queue', function(){ // Start with a concurrency of 1. Wait until a leter event loop and change // the concurrency to 2. Wait again for a later loop then verify the concurrency // Repeat that one more time by chaning the concurrency to 5. - it('changing concurrency', function(done) { + it('changing concurrency', (done) => { - var q = async.queue(function(task, callback){ - setTimeout(function(){ + var q = async.queue((task, callback) => { + setTimeout(() => { callback(); }, 10); }, 1); @@ -206,13 +206,13 @@ describe('queue', function(){ done(); }; - setTimeout(function(){ + setTimeout(() => { expect(q.concurrency).to.equal(1); q.concurrency = 2; - setTimeout(function(){ + setTimeout(() => { expect(q.running()).to.equal(2); q.concurrency = 5; - setTimeout(function(){ + setTimeout(() => { expect(q.running()).to.equal(5); }, 40); }, 40); @@ -231,10 +231,10 @@ describe('queue', function(){ // worker2: -2---3 // order of completion: 2,1,4,3 - var q = async.queue(function (task, callback) { + var q = async.queue((task, callback) => { running++; concurrencyList.push(running); - setTimeout(function () { + setTimeout(() => { call_order.push('process ' + task); running--; callback('error', 'arg'); @@ -259,18 +259,18 @@ describe('queue', function(){ }; }); - it('push with non-function', function(done) { - var q = async.queue(function () {}, 1); - expect(function () { + it('push with non-function', (done) => { + var q = async.queue(() => {}, 1); + expect(() => { q.push({}, 1); }).to.throw(); done(); }); - it('unshift', function(done) { + it('unshift', (done) => { var queue_order = []; - var q = async.queue(function (task, callback) { + var q = async.queue((task, callback) => { queue_order.push(task); callback(); }, 1); @@ -280,16 +280,16 @@ describe('queue', function(){ q.unshift(2); q.unshift(1); - setTimeout(function () { + setTimeout(() => { expect(queue_order).to.eql([ 1, 2, 3, 4 ]); done(); }, 100); }); - it('too many callbacks', function(done) { - var q = async.queue(function (task, callback) { + it('too many callbacks', (done) => { + var q = async.queue((task, callback) => { callback(); - expect(function() { + expect(() => { callback(); }).to.throw(); done(); @@ -298,7 +298,7 @@ describe('queue', function(){ q.push(1); }); - it('bulk task', function(done) { + it('bulk task', (done) => { var call_order = [], delays = [40,10,60,10]; @@ -306,14 +306,14 @@ describe('queue', function(){ // worker2: -2---3 // order of completion: 2,1,4,3 - var q = async.queue(function (task, callback) { - setTimeout(function () { + var q = async.queue((task, callback) => { + setTimeout(() => { call_order.push('process ' + task); callback('error', task); }, delays.splice(0,1)[0]); }, 2); - q.push( [1,2,3,4], function (err, arg) { + q.push( [1,2,3,4], (err, arg) => { expect(err).to.equal('error'); call_order.push('callback ' + arg); }); @@ -334,8 +334,8 @@ describe('queue', function(){ }; }); - it('idle', function(done) { - var q = async.queue(function (task, callback) { + it('idle', (done) => { + var q = async.queue((task, callback) => { // Queue is busy when workers are running expect(q.idle()).to.equal(false); callback(); @@ -359,17 +359,17 @@ describe('queue', function(){ }; }); - it('pause', function(done) { + it('pause', (done) => { var call_order = []; var running = 0; var concurrencyList = []; var pauseCalls = ['process 1', 'process 2', 'process 3']; - var q = async.queue(function (task, callback) { + var q = async.queue((task, callback) => { running++; call_order.push('process ' + task); concurrencyList.push(running); - setTimeout(function () { + setTimeout(() => { running--; callback(); }, 10) @@ -414,12 +414,12 @@ describe('queue', function(){ } }); - it('pause in worker with concurrency', function(done) { + it('pause in worker with concurrency', (done) => { var call_order = []; - var q = async.queue(function (task, callback) { + var q = async.queue((task, callback) => { if (task.isLongRunning) { q.pause(); - setTimeout(function () { + setTimeout(() => { call_order.push(task.id); q.resume(); callback(); @@ -443,9 +443,9 @@ describe('queue', function(){ }; }); - it('start paused', function(done) { - var q = async.queue(function (task, callback) { - setTimeout(function () { + it('start paused', (done) => { + var q = async.queue((task, callback) => { + setTimeout(() => { callback(); }, 40); }, 2); @@ -453,12 +453,12 @@ describe('queue', function(){ q.push([1, 2, 3]); - setTimeout(function () { + setTimeout(() => { expect(q.running()).to.equal(0); q.resume(); }, 5); - setTimeout(function () { + setTimeout(() => { expect(q.length()).to.equal(1); expect(q.running()).to.equal(2); q.resume(); @@ -469,9 +469,9 @@ describe('queue', function(){ }; }); - it('kill', function(done) { - var q = async.queue(function (/*task, callback*/) { - setTimeout(function () { + it('kill', (done) => { + var q = async.queue((/*task, callback*/) => { + setTimeout(() => { throw new Error("Function should never be called"); }, 20); }, 1); @@ -483,15 +483,15 @@ describe('queue', function(){ q.kill(); - setTimeout(function() { + setTimeout(() => { expect(q.length()).to.equal(0); done(); }, 40); }); - it('events', function(done) { + it('events', (done) => { var calls = []; - var q = async.queue(function(task, cb) { + var q = async.queue((task, cb) => { // nop calls.push('process ' + task); setTimeout(cb, 10); @@ -531,16 +531,16 @@ describe('queue', function(){ ]); done(); }; - q.push('foo', function () {calls.push('foo cb');}); - q.push('bar', function () {calls.push('bar cb');}); - q.push('zoo', function () {calls.push('zoo cb');}); - q.push('poo', function () {calls.push('poo cb');}); - q.push('moo', function () {calls.push('moo cb');}); + q.push('foo', () => {calls.push('foo cb');}); + q.push('bar', () => {calls.push('bar cb');}); + q.push('zoo', () => {calls.push('zoo cb');}); + q.push('poo', () => {calls.push('poo cb');}); + q.push('moo', () => {calls.push('moo cb');}); }); - it('empty', function(done) { + it('empty', (done) => { var calls = []; - var q = async.queue(function(task, cb) { + var q = async.queue((task, cb) => { // nop calls.push('process ' + task); async.setImmediate(cb); @@ -562,9 +562,9 @@ describe('queue', function(){ // #1367 - it('empty and not idle()', function(done) { + it('empty and not idle()', (done) => { var calls = []; - var q = async.queue(function(task, cb) { + var q = async.queue((task, cb) => { // nop calls.push('process ' + task); async.setImmediate(cb); @@ -589,9 +589,9 @@ describe('queue', function(){ q.push(1); }); - it('saturated', function(done) { + it('saturated', (done) => { var saturatedCalled = false; - var q = async.queue(function(task, cb) { + var q = async.queue((task, cb) => { async.setImmediate(cb); }, 2); @@ -606,9 +606,9 @@ describe('queue', function(){ q.push(['foo', 'bar', 'baz', 'moo']); }); - it('started', function(done) { + it('started', (done) => { - var q = async.queue(function(task, cb) { + var q = async.queue((task, cb) => { cb(null, task); }); @@ -618,10 +618,10 @@ describe('queue', function(){ done(); }); - context('q.saturated(): ', function() { - it('should call the saturated callback if tasks length is concurrency', function(done) { + context('q.saturated(): ', () => { + it('should call the saturated callback if tasks length is concurrency', (done) => { var calls = []; - var q = async.queue(function(task, cb) { + var q = async.queue((task, cb) => { calls.push('process ' + task); async.setImmediate(cb); }, 4); @@ -630,7 +630,7 @@ describe('queue', function(){ }; q.empty = function() { expect(calls.indexOf('saturated')).to.be.above(-1); - setTimeout(function() { + setTimeout(() => { expect(calls).eql([ 'process foo0', 'process foo1', @@ -648,18 +648,18 @@ describe('queue', function(){ done(); }, 50); }; - q.push('foo0', function () {calls.push('foo0 cb');}); - q.push('foo1', function () {calls.push('foo1 cb');}); - q.push('foo2', function () {calls.push('foo2 cb');}); - q.push('foo3', function () {calls.push('foo3 cb');}); - q.push('foo4', function () {calls.push('foo4 cb');}); + q.push('foo0', () => {calls.push('foo0 cb');}); + q.push('foo1', () => {calls.push('foo1 cb');}); + q.push('foo2', () => {calls.push('foo2 cb');}); + q.push('foo3', () => {calls.push('foo3 cb');}); + q.push('foo4', () => {calls.push('foo4 cb');}); }); }); - context('q.unsaturated(): ', function() { - it('should have a default buffer property that equals 25% of the concurrenct rate', function(done){ + context('q.unsaturated(): ', () => { + it('should have a default buffer property that equals 25% of the concurrenct rate', (done) => { var calls = []; - var q = async.queue(function(task, cb) { + var q = async.queue((task, cb) => { // nop calls.push('process ' + task); async.setImmediate(cb); @@ -667,9 +667,9 @@ describe('queue', function(){ expect(q.buffer).to.equal(2.5); done(); }); - it('should allow a user to change the buffer property', function(done){ + it('should allow a user to change the buffer property', (done) => { var calls = []; - var q = async.queue(function(task, cb) { + var q = async.queue((task, cb) => { // nop calls.push('process ' + task); async.setImmediate(cb); @@ -679,9 +679,9 @@ describe('queue', function(){ expect(q.buffer).to.equal(4); done(); }); - it('should call the unsaturated callback if tasks length is less than concurrency minus buffer', function(done){ + it('should call the unsaturated callback if tasks length is less than concurrency minus buffer', (done) => { var calls = []; - var q = async.queue(function(task, cb) { + var q = async.queue((task, cb) => { calls.push('process ' + task); async.setImmediate(cb); }, 4); @@ -690,7 +690,7 @@ describe('queue', function(){ }; q.empty = function() { expect(calls.indexOf('unsaturated')).to.be.above(-1); - setTimeout(function() { + setTimeout(() => { expect(calls).eql([ 'process foo0', 'process foo1', @@ -711,18 +711,18 @@ describe('queue', function(){ done(); }, 50); }; - q.push('foo0', function () {calls.push('foo0 cb');}); - q.push('foo1', function () {calls.push('foo1 cb');}); - q.push('foo2', function () {calls.push('foo2 cb');}); - q.push('foo3', function () {calls.push('foo3 cb');}); - q.push('foo4', function () {calls.push('foo4 cb');}); + q.push('foo0', () => {calls.push('foo0 cb');}); + q.push('foo1', () => {calls.push('foo1 cb');}); + q.push('foo2', () => {calls.push('foo2 cb');}); + q.push('foo3', () => {calls.push('foo3 cb');}); + q.push('foo4', () => {calls.push('foo4 cb');}); }); }); - context('workersList', function() { - it('should be the same length as running()', function(done) { - var q = async.queue(function(task, cb) { - async.setImmediate(function() { + context('workersList', () => { + it('should be the same length as running()', (done) => { + var q = async.queue((task, cb) => { + async.setImmediate(() => { expect(q.workersList().length).to.equal(q.running()); cb(); }); @@ -739,7 +739,7 @@ describe('queue', function(){ q.push('baz'); }); - it('should contain the items being processed', function(done) { + it('should contain the items being processed', (done) => { var itemsBeingProcessed = { 'foo': ['foo'], 'foo_cb': ['foo', 'bar'], @@ -750,17 +750,17 @@ describe('queue', function(){ }; function getWorkersListData(q) { - return q.workersList().map(function(v) { + return q.workersList().map((v) => { return v.data; }); } - var q = async.queue(function(task, cb) { + var q = async.queue((task, cb) => { expect( getWorkersListData(q) ).to.eql(itemsBeingProcessed[task]); expect(q.workersList().length).to.equal(q.running()); - async.setImmediate(function() { + async.setImmediate(() => { expect( getWorkersListData(q) ).to.eql(itemsBeingProcessed[task+'_cb']); @@ -781,16 +781,16 @@ describe('queue', function(){ }); }) - it('remove', function(done) { + it('remove', (done) => { var result = []; - var q = async.queue(function(data, cb) { + var q = async.queue((data, cb) => { result.push(data); async.setImmediate(cb); }); q.push([1, 2, 3, 4, 5]); - q.remove(function (node) { + q.remove((node) => { return node.data === 3; }); diff --git a/test/race.js b/test/race.js index d56205dea..6082d9905 100644 --- a/test/race.js +++ b/test/race.js @@ -1,8 +1,8 @@ var async = require('../lib'); var assert = require('assert'); -describe('race', function () { - it('should call each function in parallel and callback with first result', function raceTest10(done) { +describe('race', () => { + it('should call each function in parallel and callback with first result', (done) => { var finished = 0; var tasks = []; function eachTest(i) { @@ -15,23 +15,23 @@ describe('race', function () { for (var i = 0; i < 10; i++) { tasks[i] = eachTest(i); } - async.race(tasks, function (err, result) { + async.race(tasks, (err, result) => { assert.ifError(err); //0 finished first assert.strictEqual(result, 0); assert.strictEqual(finished, 1); - async.setImmediate(function () { + async.setImmediate(() => { assert.strictEqual(finished, 10); done(); }); }); }); - it('should callback with the first error', function raceTest20(done) { + it('should callback with the first error', (done) => { var tasks = []; function eachTest(i) { var index = i; return function (next) { - setTimeout(function () { + setTimeout(() => { next(new Error('ERR' + index)); }, 50 - index * 2); }; @@ -39,7 +39,7 @@ describe('race', function () { for (var i = 0; i <= 5; i++) { tasks[i] = eachTest(i); } - async.race(tasks, function (err, result) { + async.race(tasks, (err, result) => { assert.ok(err); assert.ok(err instanceof Error); assert.strictEqual(typeof result, 'undefined'); @@ -47,19 +47,19 @@ describe('race', function () { done(); }); }); - it('should callback when task is empty', function raceTest30(done) { - async.race([], function (err, result) { + it('should callback when task is empty', (done) => { + async.race([], (err, result) => { assert.ifError(err); assert.strictEqual(typeof result, 'undefined'); done(); }); }); - it('should callback in error the task arg is not an Array', function raceTest40() { + it('should callback in error the task arg is not an Array', () => { var errors = []; - async.race(null, function (err) { + async.race(null, (err) => { errors.push(err); }); - async.race({}, function (err) { + async.race({}, (err) => { errors.push(err); }); assert.strictEqual(errors.length, 2); diff --git a/test/reduce.js b/test/reduce.js index f5dce59d8..b3c58fc65 100644 --- a/test/reduce.js +++ b/test/reduce.js @@ -2,14 +2,14 @@ var async = require('../lib'); var expect = require('chai').expect; var assert = require('assert'); -describe('reduce', function() { +describe('reduce', () => { - it('reduce', function(done) { + it('reduce', (done) => { var call_order = []; - async.reduce([1,2,3], 0, function(a, x, callback){ + async.reduce([1,2,3], 0, (a, x, callback) => { call_order.push(x); callback(null, a + x); - }, function(err, result){ + }, (err, result) => { assert(err === null, err + " passed instead of 'null'"); expect(result).to.equal(6); expect(call_order).to.eql([1,2,3]); @@ -17,41 +17,41 @@ describe('reduce', function() { }); }); - it('reduce async with non-reference memo', function(done) { - async.reduce([1,3,2], 0, function(a, x, callback){ - setTimeout(function(){callback(null, a + x);}, Math.random()*100); - }, function(err, result){ + it('reduce async with non-reference memo', (done) => { + async.reduce([1,3,2], 0, (a, x, callback) => { + setTimeout(() => {callback(null, a + x);}, Math.random()*100); + }, (err, result) => { expect(result).to.equal(6); done(); }); }); - it('reduce error', function(done) { - async.reduce([1,2,3], 0, function(a, x, callback){ + it('reduce error', (done) => { + async.reduce([1,2,3], 0, (a, x, callback) => { callback('error'); - }, function(err){ + }, (err) => { expect(err).to.equal('error'); }); setTimeout(done, 50); }); - it('inject alias', function(done) { + it('inject alias', (done) => { expect(async.inject).to.equal(async.reduce); done(); }); - it('foldl alias', function(done) { + it('foldl alias', (done) => { expect(async.foldl).to.equal(async.reduce); done(); }); - it('reduceRight', function(done) { + it('reduceRight', (done) => { var call_order = []; var a = [1,2,3]; - async.reduceRight(a, 0, function(a, x, callback){ + async.reduceRight(a, 0, (a, x, callback) => { call_order.push(x); callback(null, a + x); - }, function(err, result){ + }, (err, result) => { expect(result).to.equal(6); expect(call_order).to.eql([3,2,1]); expect(a).to.eql([1,2,3]); @@ -59,7 +59,7 @@ describe('reduce', function() { }); }); - it('foldr alias', function(done) { + it('foldr alias', (done) => { expect(async.foldr).to.equal(async.reduceRight); done(); }); diff --git a/test/retry.js b/test/retry.js index d5e0d4052..4b18149ca 100644 --- a/test/retry.js +++ b/test/retry.js @@ -3,10 +3,10 @@ var expect = require('chai').expect; var assert = require('assert'); var _ = require('lodash'); -describe("retry", function () { +describe("retry", () => { // Issue 306 on github: https://github.com/caolan/async/issues/306 - it('retry when attempt succeeds',function(done) { + it('retry when attempt succeeds',(done) => { var failed = 3; var callCount = 0; var expectedResult = 'success'; @@ -16,7 +16,7 @@ describe("retry", function () { if (!failed) callback(null, expectedResult); else callback(true); // respond with error } - async.retry(fn, function(err, result){ + async.retry(fn, (err, result) => { assert(err === null, err + " passed instead of 'null'"); assert.equal(callCount, 3, 'did not retry the correct number of times'); assert.equal(result, expectedResult, 'did not return the expected result'); @@ -24,7 +24,7 @@ describe("retry", function () { }); }); - it('retry when all attempts fail',function(done) { + it('retry when all attempts fail',(done) => { var times = 3; var callCount = 0; var error = 'ERROR'; @@ -33,7 +33,7 @@ describe("retry", function () { callCount++; callback(error + callCount, erroredResult + callCount); // respond with indexed values } - async.retry(times, fn, function(err, result){ + async.retry(times, fn, (err, result) => { assert.equal(callCount, 3, "did not retry the correct number of times"); assert.equal(err, error + times, "Incorrect error was returned"); assert.equal(result, erroredResult + times, "Incorrect result was returned"); @@ -41,15 +41,15 @@ describe("retry", function () { }); }); - it('retry fails with invalid arguments',function(done) { - expect(function() { + it('retry fails with invalid arguments',(done) => { + expect(() => { async.retry(""); }).to.throw(); - expect(function() { + expect(() => { async.retry(); }).to.throw(); - expect(function() { - async.retry(function() {}, 2, function() {}); + expect(() => { + async.retry(() => {}, 2, () => {}); }).to.throw(); done(); }); @@ -67,7 +67,7 @@ describe("retry", function () { callback(error + callCount, erroredResult + callCount); // respond with indexed values } var start = Date.now(); - async.retry({ times: times, interval: interval}, fn, function(err, result){ + async.retry({ times, interval}, fn, (err, result) => { var duration = Date.now() - start; expect(duration).to.be.above(interval * (times - 1) - times); assert.equal(callCount, 3, "did not retry the correct number of times"); @@ -77,7 +77,7 @@ describe("retry", function () { }); }); - it('retry with custom interval when all attempts fail',function(done) { + it('retry with custom interval when all attempts fail',(done) => { var times = 3; var intervalFunc = function(retryCount) { return retryCount * 100; }; var callCount = 0; @@ -88,7 +88,7 @@ describe("retry", function () { callback(error + callCount, erroredResult + callCount); // respond with indexed values } var start = Date.now(); - async.retry({ times: times, interval: intervalFunc}, fn, function(err, result){ + async.retry({ times, interval: intervalFunc}, fn, (err, result) => { var duration = Date.now() - start; expect(duration).to.be.above(300 - times); assert.equal(callCount, 3, "did not retry the correct number of times"); @@ -98,79 +98,79 @@ describe("retry", function () { }); }); - it("should not require a callback", function (done) { + it("should not require a callback", (done) => { var called = false; - async.retry(3, function(cb) { + async.retry(3, (cb) => { called = true; cb(); }); - setTimeout(function () { + setTimeout(() => { assert(called); done(); }, 10); }); - it("should not require a callback and use the default times", function (done) { + it("should not require a callback and use the default times", (done) => { var calls = 0; - async.retry(function(cb) { + async.retry((cb) => { calls++; cb("fail"); }); - setTimeout(function () { + setTimeout(() => { expect(calls).to.equal(5); done(); }, 50); }); - it("should be cancelable", function (done) { + it("should be cancelable", (done) => { var calls = 0; - async.retry(2, function(cb) { + async.retry(2, (cb) => { calls++; cb(calls > 1 ? false : 'fail'); }, () => { throw new Error('should not get here') }); - setTimeout(function () { + setTimeout(() => { expect(calls).to.equal(2); done(); }, 10); }); - it('retry does not precompute the intervals (#1226)', function(done) { + it('retry does not precompute the intervals (#1226)', (done) => { var callTimes = []; function intervalFunc() { callTimes.push(Date.now()); return 100; - }; + } function fn(callback) { callback({}); // respond with indexed values } - async.retry({ times: 4, interval: intervalFunc}, fn, function(){ + async.retry({ times: 4, interval: intervalFunc}, fn, () => { expect(callTimes[1] - callTimes[0]).to.be.above(90); expect(callTimes[2] - callTimes[1]).to.be.above(90); done(); }); }); - it('retry passes all resolve arguments to callback', function(done) { + it('retry passes all resolve arguments to callback', (done) => { function fn(callback) { callback(null, 1, 2, 3); // respond with indexed values } - async.retry(5, fn, _.rest(function(args) { + async.retry(5, fn, _.rest((args) => { expect(args).to.be.eql([null, 1, 2, 3]); done(); })); }); // note this is a synchronous test ensuring retry is synchrnous in the fastest (most straightforward) case - it('retry calls fn immediately and will call callback if successful', function() { + it('retry calls fn immediately and will call callback if successful', () => { function fn(callback) { callback(null, {a: 1}); } - async.retry(5, fn, function(err, result) { + async.retry(5, fn, (err, result) => { expect(result).to.be.eql({a: 1}); }); }); - it('retry when all attempts fail and error continue test returns true',function(done) { + it('retry when all attempts fail and error continue test returns true',(done) => { var times = 3; var callCount = 0; var error = 'ERROR'; @@ -184,10 +184,10 @@ describe("retry", function () { return err && err !== special; } var options = { - times: times, + times, errorFilter: errorTest }; - async.retry(options, fn, function(err, result){ + async.retry(options, fn, (err, result) => { assert.equal(callCount, 3, "did not retry the correct number of times"); assert.equal(err, error + times, "Incorrect error was returned"); assert.equal(result, erroredResult + times, "Incorrect result was returned"); @@ -195,7 +195,7 @@ describe("retry", function () { }); }); - it('retry when some attempts fail and error test returns false at some invokation',function(done) { + it('retry when some attempts fail and error test returns false at some invokation',(done) => { var callCount = 0; var error = 'ERROR'; var special = 'SPECIAL_ERROR'; @@ -211,7 +211,7 @@ describe("retry", function () { var options = { errorFilter: errorTest }; - async.retry(options, fn, function(err, result){ + async.retry(options, fn, (err, result) => { assert.equal(callCount, 2, "did not retry the correct number of times"); assert.equal(err, special, "Incorrect error was returned"); assert.equal(result, erroredResult + 2, "Incorrect result was returned"); @@ -237,7 +237,7 @@ describe("retry", function () { return err && err !== special; } var start = Date.now(); - async.retry({ interval: interval, errorFilter: errorTest }, fn, function(err, result){ + async.retry({ interval, errorFilter: errorTest }, fn, (err, result) => { var duration = Date.now() - start; expect(duration).to.be.above(interval * (specialCount - 1) - specialCount); assert.equal(callCount, specialCount, "did not retry the correct number of times"); @@ -247,7 +247,7 @@ describe("retry", function () { }); }); - it('retry when first attempt succeeds and error test should not be called',function(done) { + it('retry when first attempt succeeds and error test should not be called',(done) => { var callCount = 0; var error = 'ERROR'; var erroredResult = 'RESULT'; @@ -263,7 +263,7 @@ describe("retry", function () { var options = { errorFilter: errorTest }; - async.retry(options, fn, _.rest(function(args) { + async.retry(options, fn, _.rest((args) => { assert.equal(callCount, 1, "did not retry the correct number of times"); expect(args).to.be.eql([null, erroredResult + callCount]); assert.equal(continueTestCalled, false, "error test function was called"); diff --git a/test/retryable.js b/test/retryable.js index 48d9ee902..fe04db09f 100644 --- a/test/retryable.js +++ b/test/retryable.js @@ -2,44 +2,44 @@ var async = require('../lib'); var expect = require('chai').expect; var assert = require('assert'); -describe('retryable', function () { - it('basics', function (done) { +describe('retryable', () => { + it('basics', (done) => { var calls = 0; - var retryableTask = async.retryable(3, function (arg, cb) { + var retryableTask = async.retryable(3, (arg, cb) => { calls++; expect(arg).to.equal(42); cb('fail'); }); - retryableTask(42, function (err) { + retryableTask(42, (err) => { expect(err).to.equal('fail'); expect(calls).to.equal(3); done(); }); }); - it('basics with error test function', function (done) { + it('basics with error test function', (done) => { var calls = 0; var special = 'special'; var opts = { - errorFilter: function(err) { + errorFilter(err) { return err == special; } }; - var retryableTask = async.retryable(opts, function (arg, cb) { + var retryableTask = async.retryable(opts, (arg, cb) => { calls++; expect(arg).to.equal(42); cb(calls === 3 ? 'fail' : special); }); - retryableTask(42, function (err) { + retryableTask(42, (err) => { expect(err).to.equal('fail'); expect(calls).to.equal(3); done(); }); }); - it('should work as an embedded task', function(done) { + it('should work as an embedded task', (done) => { var retryResult = 'RETRY'; var fooResults; var retryResults; @@ -50,29 +50,29 @@ describe('retryable', function () { fooResults = results; callback(null, 'FOO'); }], - retry: ['dep', async.retryable(function(results, callback) { + retry: ['dep', async.retryable((results, callback) => { retryResults = results; callback(null, retryResult); })] - }, function(err, results){ + }, (err, results) => { assert.equal(results.retry, retryResult, "Incorrect result was returned from retry function"); assert.equal(fooResults, retryResults, "Incorrect results were passed to retry function"); done(); }); }); - it('should work as an embedded task with interval', function(done) { + it('should work as an embedded task with interval', (done) => { var start = new Date().getTime(); var opts = {times: 5, interval: 20}; async.auto({ - foo: function(callback){ + foo(callback){ callback(null, 'FOO'); }, - retry: async.retryable(opts, function(callback) { + retry: async.retryable(opts, (callback) => { callback('err'); }) - }, function(){ + }, () => { var duration = new Date().getTime() - start; var expectedMinimumDuration = (opts.times -1) * opts.interval; assert(duration >= expectedMinimumDuration, diff --git a/test/seq.js b/test/seq.js index 1f7cbfcdf..1f7d3f97b 100644 --- a/test/seq.js +++ b/test/seq.js @@ -2,29 +2,29 @@ var async = require('../lib'); var expect = require('chai').expect; var assert = require('assert'); -describe('seq', function() { +describe('seq', () => { - it('seq', function(done) { + it('seq', (done) => { var add2 = function (n, cb) { expect(n).to.equal(3); - setTimeout(function () { + setTimeout(() => { cb(null, n + 2); }, 50); }; var mul3 = function (n, cb) { expect(n).to.equal(5); - setTimeout(function () { + setTimeout(() => { cb(null, n * 3); }, 15); }; var add1 = function (n, cb) { expect(n).to.equal(15); - setTimeout(function () { + setTimeout(() => { cb(null, n + 1); }, 100); }; var add2mul3add1 = async.seq(add2, mul3, add1); - add2mul3add1(3, function (err, result) { + add2mul3add1(3, (err, result) => { if (err) { return done(err); } @@ -34,72 +34,71 @@ describe('seq', function() { }); }); - it('seq error', function(done) { + it('seq error', (done) => { var testerr = new Error('test'); var add2 = function (n, cb) { expect(n).to.equal(3); - setTimeout(function () { + setTimeout(() => { cb(null, n + 2); }, 50); }; var mul3 = function (n, cb) { expect(n).to.equal(5); - setTimeout(function () { + setTimeout(() => { cb(testerr); }, 15); }; var add1 = function (n, cb) { assert(false, 'add1 should not get called'); - setTimeout(function () { + setTimeout(() => { cb(null, n + 1); }, 100); }; var add2mul3add1 = async.seq(add2, mul3, add1); - add2mul3add1(3, function (err) { + add2mul3add1(3, (err) => { expect(err).to.equal(testerr); done(); }); }); - it('seq binding', function(done) { + it('seq binding', (done) => { var testcontext = {name: 'foo'}; var add2 = function (n, cb) { expect(this).to.equal(testcontext); - setTimeout(function () { + setTimeout(() => { cb(null, n + 2); }, 50); }; var mul3 = function (n, cb) { expect(this).to.equal(testcontext); - setTimeout(function () { + setTimeout(() => { cb(null, n * 3); }, 15); }; var add2mul3 = async.seq(add2, mul3); - add2mul3.call(testcontext, 3, function (err, result) { + add2mul3.call(testcontext, 3, (err, result) => { if (err) { return done(err); } - expect(this).to.equal(testcontext); expect(result).to.equal(15); done(); }); }); - it('seq without callback', function(done) { + it('seq without callback', (done) => { var testcontext = {name: 'foo'}; var add2 = function (n, cb) { expect(this).to.equal(testcontext); - setTimeout(function () { + setTimeout(() => { cb(null, n + 2); }, 50); }; var mul3 = function () { expect(this).to.equal(testcontext); - setTimeout(function () { + setTimeout(() => { done(); }, 15); }; diff --git a/test/series.js b/test/series.js index 7d737fae0..8ee5374b4 100644 --- a/test/series.js +++ b/test/series.js @@ -3,30 +3,30 @@ var expect = require('chai').expect; var assert = require('assert'); var getFunctionsObject = require('./support/get_function_object'); -describe('series', function() { - it('series', function(done) { +describe('series', () => { + it('series', (done) => { var call_order = []; async.series([ function(callback){ - setTimeout(function(){ + setTimeout(() => { call_order.push(1); callback(null, 1); }, 25); }, function(callback){ - setTimeout(function(){ + setTimeout(() => { call_order.push(2); callback(null, 2); }, 50); }, function(callback){ - setTimeout(function(){ + setTimeout(() => { call_order.push(3); callback(null, 3,3); }, 15); } ], - function(err, results){ + (err, results) => { assert(err === null, err + " passed instead of 'null'"); expect(results).to.eql([1,2,[3,3]]); expect(call_order).to.eql([1,2,3]); @@ -34,29 +34,29 @@ describe('series', function() { }); }); - it('with reflect', function(done) { + it('with reflect', (done) => { var call_order = []; async.series([ - async.reflect(function(callback){ - setTimeout(function(){ + async.reflect((callback) => { + setTimeout(() => { call_order.push(1); callback(null, 1); }, 25); }), - async.reflect(function(callback){ - setTimeout(function(){ + async.reflect((callback) => { + setTimeout(() => { call_order.push(2); callback(null, 2); }, 50); }), - async.reflect(function(callback){ - setTimeout(function(){ + async.reflect((callback) => { + setTimeout(() => { call_order.push(3); callback(null, 3,3); }, 15); }) ], - function(err, results){ + (err, results) => { assert(err === null, err + " passed instead of 'null'"); expect(results).to.eql([ { value: 1 }, @@ -68,15 +68,15 @@ describe('series', function() { }); }); - it('empty array', function(done) { - async.series([], function(err, results){ + it('empty array', (done) => { + async.series([], (err, results) => { expect(err).to.equal(null); expect(results).to.eql([]); done(); }); }); - it('error', function(done) { + it('error', (done) => { async.series([ function(callback){ callback('error', 1); @@ -86,25 +86,25 @@ describe('series', function() { callback('error2', 2); } ], - function(err){ + (err) => { expect(err).to.equal('error'); }); setTimeout(done, 100); }); - it('error with reflect', function(done) { + it('error with reflect', (done) => { async.series([ - async.reflect(function(callback){ + async.reflect((callback) => { callback('error', 1); }), - async.reflect(function(callback){ + async.reflect((callback) => { callback('error2', 2); }), - async.reflect(function(callback){ + async.reflect((callback) => { callback(null, 1); }) ], - function(err, results){ + (err, results) => { assert(err === null, err + " passed instead of 'null'"); expect(results).to.eql([ { error: 'error' }, @@ -115,16 +115,16 @@ describe('series', function() { }); }); - it('no callback', function(done) { + it('no callback', (done) => { async.series([ function(callback){callback();}, function(callback){callback(); done();}, ]); }); - it('object', function(done) { + it('object', (done) => { var call_order = []; - async.series(getFunctionsObject(call_order), function(err, results){ + async.series(getFunctionsObject(call_order), (err, results) => { expect(err).to.equal(null); expect(results).to.eql({ one: 1, @@ -136,17 +136,17 @@ describe('series', function() { }); }); - it('call in another context @nycinvalid @nodeonly', function(done) { + it('call in another context @nycinvalid @nodeonly', (done) => { var vm = require('vm'); var sandbox = { - async: async, - done: done + async, + done }; var fn = "(" + (function () { async.series([function (callback) { callback(); - }], function (err) { + }], (err) => { if (err) { return done(err); } @@ -158,30 +158,30 @@ describe('series', function() { }); // Issue 10 on github: https://github.com/caolan/async/issues#issue/10 - it('falsy return values', function(done) { + it('falsy return values', (done) => { function taskFalse(callback) { - async.nextTick(function() { + async.nextTick(() => { callback(null, false); }); } function taskUndefined(callback) { - async.nextTick(function() { + async.nextTick(() => { callback(null, undefined); }); } function taskEmpty(callback) { - async.nextTick(function() { + async.nextTick(() => { callback(null); }); } function taskNull(callback) { - async.nextTick(function() { + async.nextTick(() => { callback(null, null); }); } async.series( [taskFalse, taskUndefined, taskEmpty, taskNull], - function(err, results) { + (err, results) => { expect(results.length).to.equal(4); assert.strictEqual(results[0], false); assert.strictEqual(results[1], undefined); diff --git a/test/setImmediate.js b/test/setImmediate.js index 854111ac4..6e4a400de 100644 --- a/test/setImmediate.js +++ b/test/setImmediate.js @@ -1,21 +1,21 @@ var async = require('../lib'); var expect = require('chai').expect; -describe("setImmediate", function () { +describe("setImmediate", () => { - it('basics', function(done){ + it('basics', (done) => { var call_order = []; - async.setImmediate(function(){call_order.push('two');}); + async.setImmediate(() => {call_order.push('two');}); call_order.push('one'); - setTimeout(function(){ + setTimeout(() => { expect(call_order).to.eql(['one','two']); done(); }, 25); }); - it("extra args", function (done) { - async.setImmediate(function (a, b, c) { + it("extra args", (done) => { + async.setImmediate((a, b, c) => { expect([a, b, c]).to.eql([1, 2, 3]); done(); }, 1, 2, 3); diff --git a/test/slice.js b/test/slice.js deleted file mode 100644 index 70205264d..000000000 --- a/test/slice.js +++ /dev/null @@ -1,32 +0,0 @@ -var slice = require('../lib/internal/slice').default; -var expect = require('chai').expect; - -describe('slice', function() { - it('should slice arrays', function() { - var arr = ['foo', 'bar', 'baz']; - var result = slice(arr, 2); - expect(arr).to.eql(['foo', 'bar', 'baz']); - expect(result).to.eql(['baz']); - }); - - it('should handle ArrayLike objects', function() { - var args = {0: 'foo', 1: 'bar', 2: 'baz', length: 3}; - var result = slice(args, 1); - expect(result).to.be.an('array'); - expect(result).to.eql(['bar', 'baz']); - }); - - it('should handle arguments', function() { - var foo = function() { - return slice(arguments, 1); - }; - var result = foo.apply(null, ['foo', 'bar', 'baz']); - expect(result).to.be.an('array'); - expect(result).to.eql(['bar', 'baz']); - }); - - it('should return an empty array on an invalid start', function() { - var result = slice(['foo', 'bar', 'baz'], 10); - expect(result).to.be.an('array').that.is.empty; - }); -}); diff --git a/test/some.js b/test/some.js index 989fecb6a..5b54ec3e5 100644 --- a/test/some.js +++ b/test/some.js @@ -2,94 +2,94 @@ var async = require('../lib'); var expect = require('chai').expect; var _ = require('lodash'); -describe("some", function () { +describe("some", () => { - it('some true', function(done){ - async.some([3,1,2], function(x, callback){ - setTimeout(function(){callback(null, x === 1);}, 0); - }, function(err, result){ + it('some true', (done) => { + async.some([3,1,2], (x, callback) => { + setTimeout(() => {callback(null, x === 1);}, 0); + }, (err, result) => { expect(err).to.equal(null); expect(result).to.equal(true); done(); }); }); - it('some false', function(done){ - async.some([3,1,2], function(x, callback){ - setTimeout(function(){callback(null, x === 10);}, 0); - }, function(err, result){ + it('some false', (done) => { + async.some([3,1,2], (x, callback) => { + setTimeout(() => {callback(null, x === 10);}, 0); + }, (err, result) => { expect(err).to.equal(null); expect(result).to.equal(false); done(); }); }); - it('some early return', function(done){ + it('some early return', (done) => { var call_order = []; - async.some([1,2,3], function(x, callback){ - setTimeout(function(){ + async.some([1,2,3], (x, callback) => { + setTimeout(() => { call_order.push(x); callback(null, x === 1); }, x*5); - }, function(){ + }, () => { call_order.push('callback'); }); - setTimeout(function(){ + setTimeout(() => { expect(call_order).to.eql([1,'callback',2,3]); done(); }, 25); }); - it('some error', function(done){ - async.some([3,1,2], function(x, callback){ - setTimeout(function(){callback('error');}, 0); - }, function(err, result){ + it('some error', (done) => { + async.some([3,1,2], (x, callback) => { + setTimeout(() => {callback('error');}, 0); + }, (err, result) => { expect(err).to.equal('error'); expect(result).to.not.exist; done(); }); }); - it('some no callback', function(done) { + it('some no callback', (done) => { var calls = []; - async.some([1, 2, 3], function (val, cb) { + async.some([1, 2, 3], (val, cb) => { calls.push(val); cb(); }); - setTimeout(function () { + setTimeout(() => { expect(calls).to.eql([1, 2, 3]); done(); }, 10); }); - it('someLimit true', function(done){ - async.someLimit([3,1,2], 2, function(x, callback){ - setTimeout(function(){callback(null, x === 2);}, 0); - }, function(err, result){ + it('someLimit true', (done) => { + async.someLimit([3,1,2], 2, (x, callback) => { + setTimeout(() => {callback(null, x === 2);}, 0); + }, (err, result) => { expect(err).to.equal(null); expect(result).to.equal(true); done(); }); }); - it('someLimit false', function(done){ - async.someLimit([3,1,2], 2, function(x, callback){ - setTimeout(function(){callback(null, x === 10);}, 0); - }, function(err, result){ + it('someLimit false', (done) => { + async.someLimit([3,1,2], 2, (x, callback) => { + setTimeout(() => {callback(null, x === 10);}, 0); + }, (err, result) => { expect(err).to.equal(null); expect(result).to.equal(false); done(); }); }); - it('someLimit short-circuit', function(done){ + it('someLimit short-circuit', (done) => { var calls = 0; - async.someLimit([3,1,2], 1, function(x, callback){ + async.someLimit([3,1,2], 1, (x, callback) => { calls++; callback(null, x === 1); - }, function(err, result){ + }, (err, result) => { expect(err).to.equal(null); expect(result).to.equal(true); expect(calls).to.equal(2); @@ -98,41 +98,41 @@ describe("some", function () { }); - it('someSeries doesn\'t cause stack overflow (#1293)', function(done) { + it('someSeries doesn\'t cause stack overflow (#1293)', (done) => { var arr = _.range(10000); let calls = 0; - async.someSeries(arr, function(data, cb) { + async.someSeries(arr, (data, cb) => { calls += 1; async.setImmediate(_.partial(cb, null, true)); - }, function(err) { + }, (err) => { expect(err).to.equal(null); expect(calls).to.equal(1); done(); }); }); - it('someLimit doesn\'t cause stack overflow (#1293)', function(done) { + it('someLimit doesn\'t cause stack overflow (#1293)', (done) => { var arr = _.range(10000); let calls = 0; - async.someLimit(arr, 100, function(data, cb) { + async.someLimit(arr, 100, (data, cb) => { calls += 1; async.setImmediate(_.partial(cb, null, true)); - }, function(err) { + }, (err) => { expect(err).to.equal(null); expect(calls).to.equal(100); done(); }); }); - it('any alias', function(){ + it('any alias', () => { expect(async.any).to.equal(async.some); }); - it('anyLimit alias', function(){ + it('anyLimit alias', () => { expect(async.anyLimit).to.equal(async.someLimit); }); - it('anySeries alias', function(){ + it('anySeries alias', () => { expect(async.anySeries).to.be.a('function'); expect(async.anySeries).to.equal(async.someSeries); }); diff --git a/test/sortBy.js b/test/sortBy.js index 1636276b2..1d2de8219 100644 --- a/test/sortBy.js +++ b/test/sortBy.js @@ -2,33 +2,33 @@ var async = require('../lib'); var expect = require('chai').expect; var assert = require('assert'); -describe('sortBy', function(){ - it('sortBy', function(done) { - async.sortBy([{a:1},{a:15},{a:6}], function(x, callback){ - setTimeout(function(){callback(null, x.a);}, 0); - }, function(err, result){ +describe('sortBy', () => { + it('sortBy', (done) => { + async.sortBy([{a:1},{a:15},{a:6}], (x, callback) => { + setTimeout(() => {callback(null, x.a);}, 0); + }, (err, result) => { assert(err === null, err + " passed instead of 'null'"); expect(result).to.eql([{a:1},{a:6},{a:15}]); done(); }); }); - it('sortBy inverted', function(done) { - async.sortBy([{a:1},{a:15},{a:6}], function(x, callback){ - setTimeout(function(){callback(null, x.a*-1);}, 0); - }, function(err, result){ + it('sortBy inverted', (done) => { + async.sortBy([{a:1},{a:15},{a:6}], (x, callback) => { + setTimeout(() => {callback(null, x.a*-1);}, 0); + }, (err, result) => { expect(result).to.eql([{a:15},{a:6},{a:1}]); done(); }); }); - it('sortBy error', function(done) { + it('sortBy error', (done) => { var error = new Error('asdas'); - async.sortBy([{a:1},{a:15},{a:6}], function(x, callback){ - async.setImmediate(function(){ + async.sortBy([{a:1},{a:15},{a:6}], (x, callback) => { + async.setImmediate(() => { callback(error); }); - }, function(err){ + }, (err) => { expect(err).to.equal(error); done(); }); diff --git a/test/support/get_function_object.js b/test/support/get_function_object.js index 008fd8f23..c31088f46 100644 --- a/test/support/get_function_object.js +++ b/test/support/get_function_object.js @@ -1,19 +1,19 @@ module.exports = function (call_order) { return { - one: function(callback) { - setTimeout(function() { + one(callback) { + setTimeout(() => { call_order.push(1); callback(null, 1); }, 125); }, - two: function(callback) { - setTimeout(function() { + two(callback) { + setTimeout(() => { call_order.push(2); callback(null, 2); }, 200); }, - three: function(callback) { - setTimeout(function() { + three(callback) { + setTimeout(() => { call_order.push(3); callback(null, 3, 3); }, 50); diff --git a/test/timeout.js b/test/timeout.js index cd4a75115..81e90fcfd 100644 --- a/test/timeout.js +++ b/test/timeout.js @@ -1,23 +1,23 @@ var async = require('../lib'); var expect = require('chai').expect; -describe('timeout', function () { +describe('timeout', () => { - it('timeout with series', function(done){ + it('timeout with series', (done) => { async.series([ - async.timeout(function asyncFn(callback) { - setTimeout(function() { + async.timeout((callback) => { + setTimeout(() => { callback(null, 'I didn\'t time out'); }, 25); }, 50), - async.timeout(function asyncFn(callback) { - setTimeout(function() { + async.timeout((callback) => { + setTimeout(() => { callback(null, 'I will time out'); }, 75); }, 50) ], - function(err, results) { - expect(err.message).to.equal('Callback function "asyncFn" timed out.'); + (err, results) => { + expect(err.message).to.equal('Callback function "anonymous" timed out.'); expect(err.code).to.equal('ETIMEDOUT'); expect(err.info).to.equal(undefined); expect(results[0]).to.equal('I didn\'t time out'); @@ -25,22 +25,22 @@ describe('timeout', function () { }); }); - it('timeout with series and info', function (done) { + it('timeout with series and info', (done) => { var info = { custom: 'info about callback' }; async.series([ - async.timeout(function asyncFn(callback) { - setTimeout(function() { + async.timeout((callback) => { + setTimeout(() => { callback(null, 'I didn\'t time out'); }, 25); }, 50), - async.timeout(function asyncFn(callback) { - setTimeout(function() { + async.timeout((callback) => { + setTimeout(() => { callback(null, 'I will time out'); }, 75); }, 50, info) ], - function(err, results) { - expect(err.message).to.equal('Callback function "asyncFn" timed out.'); + (err, results) => { + expect(err.message).to.equal('Callback function "anonymous" timed out.'); expect(err.code).to.equal('ETIMEDOUT'); expect(err.info).to.equal(info); expect(results[0]).to.equal('I didn\'t time out'); @@ -48,21 +48,21 @@ describe('timeout', function () { }); }); - it('timeout with parallel', function(done){ + it('timeout with parallel', (done) => { async.parallel([ - async.timeout(function asyncFn(callback) { - setTimeout(function() { + async.timeout((callback) => { + setTimeout(() => { callback(null, 'I didn\'t time out'); }, 25); }, 50), - async.timeout(function asyncFn(callback) { - setTimeout(function() { + async.timeout((callback) => { + setTimeout(() => { callback(null, 'I will time out'); }, 75); }, 50) ], - function(err, results) { - expect(err.message).to.equal('Callback function "asyncFn" timed out.'); + (err, results) => { + expect(err.message).to.equal('Callback function "anonymous" timed out.'); expect(err.code).to.equal('ETIMEDOUT'); expect(err.info).to.equal(undefined); expect(results[0]).to.equal('I didn\'t time out'); @@ -70,14 +70,14 @@ describe('timeout', function () { }); }); - it('timeout with multiple calls (#1418)', function(done) { - var timeout = async.timeout(function asyncFn(n, callback) { + it('timeout with multiple calls (#1418)', (done) => { + var timeout = async.timeout((n, callback) => { if (n < 1) { - setTimeout(function() { + setTimeout(() => { callback(null, 'I will time out'); }, 75); } else { - async.setImmediate(function() { + async.setImmediate(() => { callback(null, 'I didn\'t time out'); }) } @@ -85,8 +85,8 @@ describe('timeout', function () { async.series([ function(cb) { - timeout(0, function(err, result) { - expect(err.message).to.equal('Callback function "asyncFn" timed out.'); + timeout(0, (err, result) => { + expect(err.message).to.equal('Callback function "anonymous" timed out.'); expect(err.code).to.equal('ETIMEDOUT'); expect(err.info).to.equal(undefined); expect(result).to.equal(undefined); @@ -94,13 +94,13 @@ describe('timeout', function () { }); }, function(cb) { - timeout(1, function(err, result) { + timeout(1, (err, result) => { expect(err).to.equal(null); expect(result).to.equal('I didn\'t time out'); cb(); }); } - ], function(err) { + ], (err) => { expect(err).to.equal(null); done(); }); diff --git a/test/times.js b/test/times.js index ad1dfcdf4..ac7d49c4b 100644 --- a/test/times.js +++ b/test/times.js @@ -2,86 +2,86 @@ var async = require('../lib'); var expect = require('chai').expect; var assert = require('assert'); -describe('times', function() { +describe('times', () => { - it('times', function(done) { - async.times(5, function(n, next) { + it('times', (done) => { + async.times(5, (n, next) => { next(null, n); - }, function(err, results) { + }, (err, results) => { assert(err === null, err + " passed instead of 'null'"); expect(results).to.eql([0,1,2,3,4]); done(); }); }); - it('times 3', function(done) { + it('times 3', (done) => { var args = []; - async.times(3, function(n, callback){ - setTimeout(function(){ + async.times(3, (n, callback) => { + setTimeout(() => { args.push(n); callback(); }, n * 25); - }, function(err){ + }, (err) => { if (err) throw err; expect(args).to.eql([0,1,2]); done(); }); }); - it('times 0', function(done) { - async.times(0, function(n, callback){ + it('times 0', (done) => { + async.times(0, (n, callback) => { assert(false, 'iteratee should not be called'); callback(); - }, function(err){ + }, (err) => { if (err) throw err; assert(true, 'should call callback'); }); setTimeout(done, 25); }); - it('times error', function(done) { - async.times(3, function(n, callback){ + it('times error', (done) => { + async.times(3, (n, callback) => { callback('error'); - }, function(err){ + }, (err) => { expect(err).to.equal('error'); }); setTimeout(done, 50); }); - it('timesSeries', function(done) { + it('timesSeries', (done) => { var call_order = []; - async.timesSeries(5, function(n, callback){ - setTimeout(function(){ + async.timesSeries(5, (n, callback) => { + setTimeout(() => { call_order.push(n); callback(null, n); }, 100 - n * 10); - }, function(err, results){ + }, (err, results) => { expect(call_order).to.eql([0,1,2,3,4]); expect(results).to.eql([0,1,2,3,4]); done(); }); }); - it('timesSeries error', function(done) { - async.timesSeries(5, function(n, callback){ + it('timesSeries error', (done) => { + async.timesSeries(5, (n, callback) => { callback('error'); - }, function(err){ + }, (err) => { expect(err).to.equal('error'); }); setTimeout(done, 50); }); - it('timesLimit', function(done) { + it('timesLimit', (done) => { var limit = 2; var running = 0; - async.timesLimit(5, limit, function (i, next) { + async.timesLimit(5, limit, (i, next) => { running++; assert(running <= limit && running > 0, running); - setTimeout(function () { + setTimeout(() => { running--; next(null, i * 2); }, (3 - i) * 10); - }, function(err, results){ + }, (err, results) => { assert(err === null, err + " passed instead of 'null'"); expect(results).to.eql([0, 2, 4, 6, 8]); done(); diff --git a/test/transform.js b/test/transform.js index a02b54bad..e8ab5d5e7 100644 --- a/test/transform.js +++ b/test/transform.js @@ -1,25 +1,25 @@ var async = require('../lib'); var expect = require('chai').expect; -describe('transform', function() { +describe('transform', () => { - it('transform implictly determines memo if not provided', function(done) { - async.transform([1,2,3], function(memo, x, v, callback){ + it('transform implictly determines memo if not provided', (done) => { + async.transform([1,2,3], (memo, x, v, callback) => { memo.push(x + 1); callback(); - }, function(err, result){ + }, (err, result) => { expect(result).to.eql([2, 3, 4]); done(); }); }); - it('transform async with object memo', function(done) { - async.transform([1,3,2], {}, function(memo, v, k, callback){ - setTimeout(function() { + it('transform async with object memo', (done) => { + async.transform([1,3,2], {}, (memo, v, k, callback) => { + setTimeout(() => { memo[k] = v; callback(); }); - }, function(err, result) { + }, (err, result) => { expect(err).to.equal(null); expect(result).to.eql({ 0: 1, @@ -30,31 +30,31 @@ describe('transform', function() { }); }); - it('transform iterating object', function(done) { - async.transform({a: 1, b: 3, c: 2}, function(memo, v, k, callback){ - setTimeout(function() { + it('transform iterating object', (done) => { + async.transform({a: 1, b: 3, c: 2}, (memo, v, k, callback) => { + setTimeout(() => { memo[k] = v + 1; callback(); }); - }, function(err, result) { + }, (err, result) => { expect(err).to.equal(null); expect(result).to.eql({a: 2, b: 4, c: 3}); done(); }); }); - it('transform error', function(done) { - async.transform([1,2,3], function(a, v, k, callback){ + it('transform error', (done) => { + async.transform([1,2,3], (a, v, k, callback) => { callback('error'); - }, function(err){ + }, (err) => { expect(err).to.equal('error'); done(); }); }); - it('transform with two arguments', function(done) { + it('transform with two arguments', (done) => { try { - async.transform([1, 2, 3], function (a, v, k, callback) { + async.transform([1, 2, 3], (a, v, k, callback) => { callback(); }); done(); diff --git a/test/tryEach.js b/test/tryEach.js index db884a58c..6ac652384 100644 --- a/test/tryEach.js +++ b/test/tryEach.js @@ -2,42 +2,42 @@ var async = require('../lib'); var expect = require('chai').expect; var assert = require('assert'); -describe('tryEach', function () { - it('no callback', function () { +describe('tryEach', () => { + it('no callback', () => { async.tryEach([]); }); - it('empty', function (done) { - async.tryEach([], function (err, results) { + it('empty', (done) => { + async.tryEach([], (err, results) => { expect(err).to.equal(null); expect(results).to.eql(undefined); done(); }); }); - it('one task, multiple results', function (done) { + it('one task, multiple results', (done) => { var RESULTS = ['something', 'something2']; async.tryEach([ function (callback) { callback(null, RESULTS[0], RESULTS[1]); } - ], function (err, results) { + ], (err, results) => { expect(err).to.equal(null); expect(results).to.eql(RESULTS); done(); }); }); - it('one task', function (done) { + it('one task', (done) => { var RESULT = 'something'; async.tryEach([ function (callback) { callback(null, RESULT); } - ], function (err, results) { + ], (err, results) => { expect(err).to.equal(null); expect(results).to.eql(RESULT); done(); }); }); - it('two tasks, one failing', function (done) { + it('two tasks, one failing', (done) => { var RESULT = 'something'; async.tryEach([ function (callback) { @@ -46,13 +46,13 @@ describe('tryEach', function () { function (callback) { callback(null, RESULT); } - ], function (err, results) { + ], (err, results) => { expect(err).to.equal(null); expect(results).to.eql(RESULT); done(); }); }); - it('two tasks, both failing', function (done) { + it('two tasks, both failing', (done) => { var ERROR_RESULT = new Error('Failure2'); async.tryEach([ function (callback) { @@ -61,13 +61,13 @@ describe('tryEach', function () { function (callback) { callback(ERROR_RESULT); } - ], function (err, results) { + ], (err, results) => { expect(err).to.equal(ERROR_RESULT); expect(results).to.eql(undefined); done(); }); }); - it('two tasks, non failing', function (done) { + it('two tasks, non failing', (done) => { var RESULT = 'something'; async.tryEach([ function (callback) { @@ -76,7 +76,7 @@ describe('tryEach', function () { function () { assert.fail('Should not been called'); }, - ], function (err, results) { + ], (err, results) => { expect(err).to.equal(null); expect(results).to.eql(RESULT); done(); diff --git a/test/until.js b/test/until.js index 2b82fe165..9ea060503 100644 --- a/test/until.js +++ b/test/until.js @@ -2,22 +2,22 @@ var async = require('../lib'); var expect = require('chai').expect; var assert = require('assert'); -describe('until', function(){ - it('until', function(done) { +describe('until', () => { + it('until', (done) => { var call_order = []; var count = 0; async.until( - function (c) { + (c) => { expect(c).to.equal(undefined); call_order.push(['test', count]); return (count == 5); }, - function (cb) { + (cb) => { call_order.push(['iteratee', count]); count++; cb(null, count); }, - function (err, result) { + (err, result) => { assert(err === null, err + " passed instead of 'null'"); expect(result).to.equal(5, 'last result passed through'); expect(call_order).to.eql([ @@ -50,21 +50,21 @@ describe('until', function(){ }, 10) }) - it('doUntil', function(done) { + it('doUntil', (done) => { var call_order = []; var count = 0; async.doUntil( - function (cb) { + (cb) => { call_order.push(['iteratee', count]); count++; cb(null, count); }, - function (c) { + (c) => { expect(c).to.equal(count); call_order.push(['test', count]); return (count == 5); }, - function (err, result) { + (err, result) => { assert(err === null, err + " passed instead of 'null'"); expect(result).to.equal(5, 'last result passed through'); expect(call_order).to.eql([ @@ -80,20 +80,20 @@ describe('until', function(){ ); }); - it('doUntil callback params', function(done) { + it('doUntil callback params', (done) => { var call_order = []; var count = 0; async.doUntil( - function (cb) { + (cb) => { call_order.push(['iteratee', count]); count++; cb(null, count); }, - function (c) { + (c) => { call_order.push(['test', c]); return (c == 5); }, - function (err, result) { + (err, result) => { if (err) throw err; expect(result).to.equal(5, 'last result passed through'); expect(call_order).to.eql([ diff --git a/test/waterfall.js b/test/waterfall.js index 1501f0332..4736093fa 100644 --- a/test/waterfall.js +++ b/test/waterfall.js @@ -2,20 +2,20 @@ var async = require('../lib'); var expect = require('chai').expect; var assert = require('assert'); -describe("waterfall", function () { +describe("waterfall", () => { - it('basics', function(done){ + it('basics', (done) => { var call_order = []; async.waterfall([ function(callback){ call_order.push('fn1'); - setTimeout(function(){callback(null, 'one', 'two');}, 0); + setTimeout(() => {callback(null, 'one', 'two');}, 0); }, function(arg1, arg2, callback){ call_order.push('fn2'); expect(arg1).to.equal('one'); expect(arg2).to.equal('two'); - setTimeout(function(){callback(null, arg1, arg2, 'three');}, 25); + setTimeout(() => {callback(null, arg1, arg2, 'three');}, 25); }, function(arg1, arg2, arg3, callback){ call_order.push('fn3'); @@ -29,34 +29,34 @@ describe("waterfall", function () { expect(call_order).to.eql(['fn1','fn2','fn3','fn4']); callback(null, 'test'); } - ], function(err){ + ], (err) => { expect(err === null, err + " passed instead of 'null'"); done(); }); }); - it('empty array', function(done){ - async.waterfall([], function(err){ + it('empty array', (done) => { + async.waterfall([], (err) => { if (err) throw err; done(); }); }); - it('non-array', function(done){ - async.waterfall({}, function(err){ + it('non-array', (done) => { + async.waterfall({}, (err) => { expect(err.message).to.equal('First argument to waterfall must be an array of functions'); done(); }); }); - it('no callback', function(done){ + it('no callback', (done) => { async.waterfall([ function(callback){callback();}, function(callback){callback(); done();} ]); }); - it('async', function(done){ + it('async', (done) => { var call_order = []; async.waterfall([ function(callback){ @@ -75,7 +75,7 @@ describe("waterfall", function () { ]); }); - it('error', function(done){ + it('error', (done) => { async.waterfall([ function(callback){ callback('error'); @@ -84,14 +84,14 @@ describe("waterfall", function () { assert(false, 'next function should not be called'); callback(); } - ], function(err){ + ], (err) => { expect(err).to.equal('error'); done(); }); }); - it('canceled', function(done){ + it('canceled', (done) => { const call_order = [] async.waterfall([ function(callback){ @@ -103,7 +103,7 @@ describe("waterfall", function () { assert(false, 'next function should not be called'); callback(); } - ], function(){ + ], () => { throw new Error('should not get here') }); setTimeout(() => { @@ -112,7 +112,7 @@ describe("waterfall", function () { }, 10) }); - it('multiple callback calls', function(){ + it('multiple callback calls', () => { var arr = [ function(callback){ callback(null, 'one', 'two'); @@ -122,18 +122,18 @@ describe("waterfall", function () { callback(null, arg1, arg2, 'three'); } ]; - expect(function () { - async.waterfall(arr, function () {}); + expect(() => { + async.waterfall(arr, () => {}); }).to.throw(/already called/); }); - it('multiple callback calls (trickier) @nodeonly', function(done){ + it('multiple callback calls (trickier) @nodeonly', (done) => { // do a weird dance to catch the async thrown error before mocha var listeners = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); - process.once('uncaughtException', function onErr(err) { - listeners.forEach(function(listener) { + process.once('uncaughtException', (err) => { + listeners.forEach((listener) => { process.on('uncaughtException', listener); }); // can't throw errors in a uncaughtException handler, defer @@ -156,17 +156,17 @@ describe("waterfall", function () { ]); }); - it('call in another context @nycinvalid @nodeonly', function(done) { + it('call in another context @nycinvalid @nodeonly', (done) => { var vm = require('vm'); var sandbox = { - async: async, - done: done + async, + done }; var fn = "(" + (function () { async.waterfall([function (callback) { callback(); - }], function (err) { + }], (err) => { if (err) { return done(err); } @@ -177,13 +177,13 @@ describe("waterfall", function () { vm.runInNewContext(fn, sandbox); }); - it('should not use unnecessary deferrals', function (done) { + it('should not use unnecessary deferrals', (done) => { var sameStack = true; async.waterfall([ function (cb) { cb(null, 1); }, function (arg, cb) { cb(); } - ], function() { + ], () => { expect(sameStack).to.equal(true); done(); }); diff --git a/test/whilst.js b/test/whilst.js index 2ce2f23ff..844e55959 100644 --- a/test/whilst.js +++ b/test/whilst.js @@ -2,23 +2,23 @@ var async = require('../lib'); var expect = require('chai').expect; var assert = require('assert'); -describe('whilst', function(){ - it('whilst', function(done) { +describe('whilst', () => { + it('whilst', (done) => { var call_order = []; var count = 0; async.whilst( - function (c) { + (c) => { expect(c).to.equal(undefined); call_order.push(['test', count]); return (count < 5); }, - function (cb) { + (cb) => { call_order.push(['iteratee', count]); count++; cb(null, count); }, - function (err, result) { + (err, result) => { assert(err === null, err + " passed instead of 'null'"); expect(result).to.equal(5, 'last result passed through'); expect(call_order).to.eql([ @@ -35,11 +35,11 @@ describe('whilst', function(){ ); }); - it('whilst optional callback', function(done) { + it('whilst optional callback', (done) => { var counter = 0; async.whilst( - function () { return counter < 2; }, - function (cb) { + () => { return counter < 2; }, + (cb) => { counter++; cb(); } @@ -48,11 +48,11 @@ describe('whilst', function(){ done(); }); - it('whilst canceling', function(done) { + it('whilst canceling', (done) => { var counter = 0; async.whilst( - function () { return counter < 3; }, - function (cb) { + () => { return counter < 3; }, + (cb) => { counter++; cb(counter === 2 ? false : null); }, @@ -64,22 +64,22 @@ describe('whilst', function(){ }, 10) }); - it('doWhilst', function(done) { + it('doWhilst', (done) => { var call_order = []; var count = 0; async.doWhilst( - function (cb) { + (cb) => { call_order.push(['iteratee', count]); count++; cb(null, count); }, - function (c) { + (c) => { expect(c).to.equal(count); call_order.push(['test', count]); return (count < 5); }, - function (err, result) { + (err, result) => { assert(err === null, err + " passed instead of 'null'"); expect(result).to.equal(5, 'last result passed through'); expect(call_order).to.eql([ @@ -95,20 +95,20 @@ describe('whilst', function(){ ); }); - it('doWhilst callback params', function(done) { + it('doWhilst callback params', (done) => { var call_order = []; var count = 0; async.doWhilst( - function (cb) { + (cb) => { call_order.push(['iteratee', count]); count++; cb(null, count); }, - function (c) { + (c) => { call_order.push(['test', c]); return (c < 5); }, - function (err, result) { + (err, result) => { if (err) throw err; expect(result).to.equal(5, 'last result passed through'); expect(call_order).to.eql([ @@ -124,15 +124,15 @@ describe('whilst', function(){ ); }); - it('doWhilst - error', function(done) { + it('doWhilst - error', (done) => { var error = new Error('asdas'); async.doWhilst( - function (cb) { + (cb) => { cb(error); }, - function () {}, - function (err) { + () => {}, + (err) => { expect(err).to.equal(error); done(); }