async-each
Advanced tools
Comparing version 1.0.3 to 1.0.4
25
index.js
@@ -1,17 +0,17 @@ | ||
// async-each MIT license (by Paul Miller from https://paulmillr.com). | ||
(function(globals) { | ||
/*! async-each - MIT License (c) 2016 Paul Miller (paulmillr.com) */ | ||
(function (globals) { | ||
'use strict'; | ||
var each = function(items, next, callback) { | ||
var each = function (items, next, callback) { | ||
if (!Array.isArray(items)) throw new TypeError('each() expects array as first argument'); | ||
if (typeof next !== 'function') throw new TypeError('each() expects function as second argument'); | ||
if (typeof next !== 'function') | ||
throw new TypeError('each() expects function as second argument'); | ||
if (typeof callback !== 'function') callback = Function.prototype; // no-op | ||
if (items.length === 0) return callback(undefined, items); | ||
var transformed = new Array(items.length); | ||
var count = 0; | ||
var total = items.length; | ||
if (total === 0) return callback(undefined, items); | ||
var transformed = new Array(total); | ||
var returned = false; | ||
items.forEach(function(item, index) { | ||
next(item, function(error, transformedItem) { | ||
items.forEach(function (item, index) { | ||
next(item, function (error, transformedItem) { | ||
if (returned) return; | ||
@@ -23,4 +23,3 @@ if (error) { | ||
transformed[index] = transformedItem; | ||
count += 1; | ||
if (count === items.length) return callback(undefined, transformed); | ||
if (index === total) return callback(undefined, transformed); | ||
}); | ||
@@ -31,3 +30,3 @@ }); | ||
if (typeof define !== 'undefined' && define.amd) { | ||
define([], function() { | ||
define([], function () { | ||
return each; | ||
@@ -34,0 +33,0 @@ }); // RequireJS |
{ | ||
"name": "async-each", | ||
"description": "No-bullshit, ultra-simple, 35-lines-of-code async parallel forEach / map function for JavaScript.", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"license": "MIT", | ||
"keywords": [ | ||
"async", "forEach", "each", "map", | ||
"asynchronous", | ||
"iteration", "iterate", | ||
"loop", "parallel", | ||
"concurrent", "array", | ||
"flow", "control flow" | ||
"files": [ | ||
"index.js" | ||
], | ||
"files": ["index.js"], | ||
"homepage": "https://github.com/paulmillr/async-each/", | ||
"author": "Paul Miller (https://paulmillr.com/)", | ||
"repository": "git://github.com/paulmillr/async-each.git", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/paulmillr/async-each.git" | ||
}, | ||
"main": "index.js", | ||
"dependencies": {} | ||
"dependencies": {}, | ||
"keywords": [ | ||
"async", | ||
"forEach", | ||
"each", | ||
"map", | ||
"asynchronous", | ||
"iteration", | ||
"iterate", | ||
"loop", | ||
"parallel", | ||
"concurrent", | ||
"array", | ||
"flow", | ||
"control flow" | ||
], | ||
"funding": [ | ||
{ | ||
"type": "individual", | ||
"url": "https://paulmillr.com/funding/" | ||
} | ||
] | ||
} |
# async-each | ||
No-bullshit, ultra-simple, 35-lines-of-code async parallel forEach function for JavaScript. | ||
No-bullshit, ultra-simple, 40-lines-of-code async parallel forEach function for JavaScript. | ||
@@ -9,9 +9,9 @@ We don't need junky 30K async libs. Really. | ||
## Installation | ||
* Just include async-each before your scripts. | ||
* `npm install async-each` if you’re using node.js. | ||
## Usage | ||
* `each(array, iterator, callback);` — `Array`, `Function`, `(optional) Function` | ||
`npm install async-each` if you're using NPM. | ||
For browsers, just include async-each before your scripts and use global variable `asyncEach` | ||
* `each(array, iterator, callback)` — `Array`, `Function`, `(optional) Function` | ||
* `iterator(item, next)` receives current item and a callback that will mark the item as done. `next` callback receives optional `error, transformedItem` arguments. | ||
@@ -27,4 +27,3 @@ * `callback(error, transformedArray)` optionally receives first error and transformed result `Array`. | ||
// Alternatively in browser: | ||
asyncEach(list, fn, callback); | ||
asyncEach(list, fn, callback); // use global var in browser | ||
``` | ||
@@ -36,20 +35,4 @@ | ||
Copyright (c) 2016 Paul Miller [(paulmillr.com)](http://paulmillr.com) | ||
Copyright (c) 2016 Paul Miller [(paulmillr.com)](https://paulmillr.com) | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the “Software”), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
See [LICENSE](https://github.com/paulmillr/async-each/blob/master/LICENSE) file. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
4280
4
0
36