From 812950328d12e7955de42967d58805446a403fa6 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 27 Mar 2018 23:41:41 -0600 Subject: [PATCH] v5.1.0 --- forEachAsync.js => foreachasync.js | 29 ++++++++++++++--------------- package.json | 19 +++++++++---------- test-bluebird.js | 12 +++++------- test-native.js | 9 ++++----- 4 files changed, 32 insertions(+), 37 deletions(-) rename forEachAsync.js => foreachasync.js (83%) diff --git a/forEachAsync.js b/foreachasync.js similarity index 83% rename from forEachAsync.js rename to foreachasync.js index 5e61688..e546d76 100644 --- a/forEachAsync.js +++ b/foreachasync.js @@ -2,17 +2,15 @@ ;(function (exports) { 'use strict'; - var BREAK = {} - , exp = {} - ; + var BREAK = {}; + var exp = {}; function create(PromiseA) { PromiseA = PromiseA.Promise || PromiseA; function forEachAsync(arr, fn, thisArg) { - var result = PromiseA.resolve() - ; + var result = PromiseA.resolve(); arr.forEach(function (item, k) { result = result.then(function () { @@ -61,17 +59,18 @@ exports.create = forEachAsync.create = function () {}; */ - - try { - exp.forEachAsync = create(require('bluebird')); - } catch(e) { - if ('undefined' !== typeof Promise) { - exp.forEachAsync = create(Promise); - } else { - try { + /* globals Promise */ + if ('undefined' !== typeof Promise) { + exp.forEachAsync = create(Promise); + } + else { + try { + exp.forEachAsync = create(require('bluebird')); + } catch(e) { + try { exp.forEachAsync = create(require('es6-promise')); } catch(e) { - try { + try { exp.forEachAsync = create(require('rsvp')); } catch(e) { console.warn('forEachAsync needs requires a promise implementation and your environment does not provide one.' @@ -87,4 +86,4 @@ }; exports.forEachAsync.create = create; -}('undefined' !== typeof exports && exports || new Function('return this')())); +}('undefined' !== typeof exports && exports || window)); diff --git a/package.json b/package.json index a74e7d8..3b07c6d 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "foreachasync", - "version": "5.0.5", + "version": "5.1.0", "description": "A node- and browser-ready async (now with promises) counterpart of Array.prototype.forEach", - "homepage": "https://github.com/FuturesJS/forEachAsync", - "main": "forEachAsync.js", + "homepage": "https://git.coolaj86.com/coolaj86/foreachasync.js", + "main": "foreachasync.js", "directories": { "test": "test" }, @@ -12,7 +12,7 @@ }, "repository": { "type": "git", - "url": "git://github.com/FuturesJS/forEachAsync.git" + "url": "git://git.coolaj86.com/coolaj86/foreachasync.js.git" }, "keywords": [ "futuresjs", @@ -26,13 +26,12 @@ "each" ], "optionalDependencies": { - "bluebird": "^2.5.3" + "bluebird": "^3.5.1" }, - "author": "AJ ONeal (http://coolaj86.com/)", - "license": "Apache2", + "author": "AJ ONeal (https://coolaj86.com/)", + "license": "(MIT or Apache-2.0)", "bugs": { - "url": "https://github.com/FuturesJS/forEachAsync/issues" + "url": "https://git.coolaj86.com/coolaj86/foreachasync.js/issues" }, - "dependencies": { - } + "dependencies": {} } diff --git a/test-bluebird.js b/test-bluebird.js index e8aab64..7bae7b1 100644 --- a/test-bluebird.js +++ b/test-bluebird.js @@ -1,16 +1,14 @@ (function () { "use strict"; - var PromiseA = require('bluebird') - , forEachAsync = require('./forEachAsync').forEachAsync - , context = {} - ; + var PromiseA = require('bluebird'); + var forEachAsync = require('./forEachAsync').forEachAsync; + var context = {}; forEachAsync([0, 500, 70, 200, 400, 100], function (element, i, arr) { console.log(i, '/', arr.length, 'began'); - var result - ; + var result; // test that thisness is applied this[element] = i; @@ -20,7 +18,7 @@ result = PromiseA.resolve(); } else { // test asynchronous callbacks - result = new Promise(function (resolve/*, reject*/) { + result = new PromiseA(function (resolve/*, reject*/) { setTimeout(resolve, element); }); } diff --git a/test-native.js b/test-native.js index 58113f3..f98c3a6 100644 --- a/test-native.js +++ b/test-native.js @@ -1,13 +1,12 @@ (function () { "use strict"; - var forEachAsync = require('./forEachAsync').forEachAsync.create(Promise) - , context = {} - ; + /* globals Promise */ + var forEachAsync = require('./forEachAsync').forEachAsync.create(Promise); + var context = {}; forEachAsync([0, 500, 70, 200, 400, 100], function (element, i, arr) { - var p - ; + var p; // test that thisness is applied this[element] = i;