From 2192b79337d07e44580987d6dec1222cbf60c10b Mon Sep 17 00:00:00 2001 From: Beng89 Date: Mon, 26 Oct 2015 23:45:30 -0500 Subject: [PATCH] Added definitions and test for node-array-ext. --- node-array-ext/node-array-ext-tests.ts | 23 +++++++++++++++++++++++ node-array-ext/node-array-ext.d.ts | 17 +++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 node-array-ext/node-array-ext-tests.ts create mode 100644 node-array-ext/node-array-ext.d.ts diff --git a/node-array-ext/node-array-ext-tests.ts b/node-array-ext/node-array-ext-tests.ts new file mode 100644 index 0000000000..8981165cd3 --- /dev/null +++ b/node-array-ext/node-array-ext-tests.ts @@ -0,0 +1,23 @@ +/// +import extensions = require("node-array-ext"); + +var array: Array = [ "hello", "world", "test" ]; +var result: string = ""; +var finish = function(err?: Error) { + if(err) { + console.log(err); + } + else { + console.log(result); + } +} +function each(i: number, element: string, next: (err?: Error) => void): void { + setTimeout(function() { + console.log("%s => %s", i, element); + result += element + " "; + next(); + }, 50 * (array.length - i)); +} + +extensions.asyncEach(array, each, finish); +extensions.awaitEach(array, each, finish); \ No newline at end of file diff --git a/node-array-ext/node-array-ext.d.ts b/node-array-ext/node-array-ext.d.ts new file mode 100644 index 0000000000..e8474d6a64 --- /dev/null +++ b/node-array-ext/node-array-ext.d.ts @@ -0,0 +1,17 @@ +// Type definitions for node-array-ext v1.0.00 +// Project: https://github.com/Beng89/node-array-ext +// Definitions by: Ben Goltz +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "node-array-ext" { + /** + * Processes each of the elements in the array and triggers a callback once every element has been processed. + * - note that the elements are called in order but are not guaranteed to finish in order. + */ + export function asyncEach (array: Array, each: (i: number, element: T, done: (err?: Error) => void) => void, finish: (err?: Error) => void): void; + /** + * Processes each of the elements in the array and triggers a callback once every element has been processed. + * - note that the elements are called in order and are guaranteed to finish in order. + */ + export function awaitEach (array: Array, each: (i: number, element: T, done: (err?: Error) => void) => void, finish: (err?: Error) => void): void; +} \ No newline at end of file