Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Perrotte <mike@npmjs.com>2020-01-31 23:59:21 +0300
committerisaacs <i@izs.me>2020-05-08 04:11:51 +0300
commit56e1f868e8634a4bf0f7a7186a68a6f3de9cfb2a (patch)
treef05cdcb56d66480641b6c8f8bb823bc10c6842df /node_modules/p-map
parent8f6b6204f9cdbfc8e2a27a1c3b3f1591ac7e0d60 (diff)
npm-pick-manifest@6.0.0
Diffstat (limited to 'node_modules/p-map')
-rw-r--r--node_modules/p-map/index.d.ts65
-rw-r--r--node_modules/p-map/index.js81
-rw-r--r--node_modules/p-map/license9
-rw-r--r--node_modules/p-map/package.json84
-rw-r--r--node_modules/p-map/readme.md99
5 files changed, 338 insertions, 0 deletions
diff --git a/node_modules/p-map/index.d.ts b/node_modules/p-map/index.d.ts
new file mode 100644
index 000000000..8f796295d
--- /dev/null
+++ b/node_modules/p-map/index.d.ts
@@ -0,0 +1,65 @@
+declare namespace pMap {
+ interface Options {
+ /**
+ Number of concurrently pending promises returned by `mapper`.
+
+ @default Infinity
+ */
+ readonly concurrency?: number;
+
+ /**
+ When set to `false`, instead of stopping when a promise rejects, it will wait for all the promises to settle and then reject with an [aggregated error](https://github.com/sindresorhus/aggregate-error) containing all the errors from the rejected promises.
+
+ @default true
+ */
+ readonly stopOnError?: boolean;
+ }
+
+ /**
+ Function which is called for every item in `input`. Expected to return a `Promise` or value.
+
+ @param element - Iterated element.
+ @param index - Index of the element in the source array.
+ */
+ type Mapper<Element = any, NewElement = any> = (
+ element: Element,
+ index: number
+ ) => NewElement | Promise<NewElement>;
+}
+
+/**
+@param input - Iterated over concurrently in the `mapper` function.
+@param mapper - Function which is called for every item in `input`. Expected to return a `Promise` or value.
+@returns A `Promise` that is fulfilled when all promises in `input` and ones returned from `mapper` are fulfilled, or rejects if any of the promises reject. The fulfilled value is an `Array` of the fulfilled values returned from `mapper` in `input` order.
+
+@example
+```
+import pMap = require('p-map');
+import got = require('got');
+
+const sites = [
+ getWebsiteFromUsername('https://sindresorhus'), //=> Promise
+ 'https://ava.li',
+ 'https://github.com'
+];
+
+(async () => {
+ const mapper = async site => {
+ const {requestUrl} = await got.head(site);
+ return requestUrl;
+ };
+
+ const result = await pMap(sites, mapper, {concurrency: 2});
+
+ console.log(result);
+ //=> ['https://sindresorhus.com/', 'https://ava.li/', 'https://github.com/']
+})();
+```
+*/
+declare function pMap<Element, NewElement>(
+ input: Iterable<Element>,
+ mapper: pMap.Mapper<Element, NewElement>,
+ options?: pMap.Options
+): Promise<NewElement[]>;
+
+export = pMap;
diff --git a/node_modules/p-map/index.js b/node_modules/p-map/index.js
new file mode 100644
index 000000000..5a8aeb256
--- /dev/null
+++ b/node_modules/p-map/index.js
@@ -0,0 +1,81 @@
+'use strict';
+const AggregateError = require('aggregate-error');
+
+module.exports = async (
+ iterable,
+ mapper,
+ {
+ concurrency = Infinity,
+ stopOnError = true
+ } = {}
+) => {
+ return new Promise((resolve, reject) => {
+ if (typeof mapper !== 'function') {
+ throw new TypeError('Mapper function is required');
+ }
+
+ if (!(typeof concurrency === 'number' && concurrency >= 1)) {
+ throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${concurrency}\` (${typeof concurrency})`);
+ }
+
+ const ret = [];
+ const errors = [];
+ const iterator = iterable[Symbol.iterator]();
+ let isRejected = false;
+ let isIterableDone = false;
+ let resolvingCount = 0;
+ let currentIndex = 0;
+
+ const next = () => {
+ if (isRejected) {
+ return;
+ }
+
+ const nextItem = iterator.next();
+ const i = currentIndex;
+ currentIndex++;
+
+ if (nextItem.done) {
+ isIterableDone = true;
+
+ if (resolvingCount === 0) {
+ if (!stopOnError && errors.length !== 0) {
+ reject(new AggregateError(errors));
+ } else {
+ resolve(ret);
+ }
+ }
+
+ return;
+ }
+
+ resolvingCount++;
+
+ (async () => {
+ try {
+ const element = await nextItem.value;
+ ret[i] = await mapper(element, i);
+ resolvingCount--;
+ next();
+ } catch (error) {
+ if (stopOnError) {
+ isRejected = true;
+ reject(error);
+ } else {
+ errors.push(error);
+ resolvingCount--;
+ next();
+ }
+ }
+ })();
+ };
+
+ for (let i = 0; i < concurrency; i++) {
+ next();
+
+ if (isIterableDone) {
+ break;
+ }
+ }
+ });
+};
diff --git a/node_modules/p-map/license b/node_modules/p-map/license
new file mode 100644
index 000000000..e7af2f771
--- /dev/null
+++ b/node_modules/p-map/license
@@ -0,0 +1,9 @@
+MIT License
+
+Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.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.
diff --git a/node_modules/p-map/package.json b/node_modules/p-map/package.json
new file mode 100644
index 000000000..21aff08b2
--- /dev/null
+++ b/node_modules/p-map/package.json
@@ -0,0 +1,84 @@
+{
+ "_from": "p-map@^3.0.0",
+ "_id": "p-map@3.0.0",
+ "_inBundle": false,
+ "_integrity": "sha512-d3qXVTF/s+W+CdJ5A29wywV2n8CQQYahlgz2bFiA+4eVNJbHJodPZ+/gXwPGh0bOqA+j8S+6+ckmvLGPk1QpxQ==",
+ "_location": "/p-map",
+ "_phantomChildren": {},
+ "_requested": {
+ "type": "range",
+ "registry": true,
+ "raw": "p-map@^3.0.0",
+ "name": "p-map",
+ "escapedName": "p-map",
+ "rawSpec": "^3.0.0",
+ "saveSpec": null,
+ "fetchSpec": "^3.0.0"
+ },
+ "_requiredBy": [
+ "/npm-registry-fetch/cacache"
+ ],
+ "_resolved": "https://registry.npmjs.org/p-map/-/p-map-3.0.0.tgz",
+ "_shasum": "d704d9af8a2ba684e2600d9a215983d4141a979d",
+ "_spec": "p-map@^3.0.0",
+ "_where": "/Users/mperrotte/npminc/cli/node_modules/npm-registry-fetch/node_modules/cacache",
+ "author": {
+ "name": "Sindre Sorhus",
+ "email": "sindresorhus@gmail.com",
+ "url": "sindresorhus.com"
+ },
+ "bugs": {
+ "url": "https://github.com/sindresorhus/p-map/issues"
+ },
+ "bundleDependencies": false,
+ "dependencies": {
+ "aggregate-error": "^3.0.0"
+ },
+ "deprecated": false,
+ "description": "Map over promises concurrently",
+ "devDependencies": {
+ "ava": "^2.2.0",
+ "delay": "^4.1.0",
+ "in-range": "^2.0.0",
+ "random-int": "^2.0.0",
+ "time-span": "^3.1.0",
+ "tsd": "^0.7.2",
+ "xo": "^0.24.0"
+ },
+ "engines": {
+ "node": ">=8"
+ },
+ "files": [
+ "index.js",
+ "index.d.ts"
+ ],
+ "homepage": "https://github.com/sindresorhus/p-map#readme",
+ "keywords": [
+ "promise",
+ "map",
+ "resolved",
+ "wait",
+ "collection",
+ "iterable",
+ "iterator",
+ "race",
+ "fulfilled",
+ "async",
+ "await",
+ "promises",
+ "concurrently",
+ "concurrency",
+ "parallel",
+ "bluebird"
+ ],
+ "license": "MIT",
+ "name": "p-map",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/sindresorhus/p-map.git"
+ },
+ "scripts": {
+ "test": "xo && ava && tsd"
+ },
+ "version": "3.0.0"
+}
diff --git a/node_modules/p-map/readme.md b/node_modules/p-map/readme.md
new file mode 100644
index 000000000..4941cb773
--- /dev/null
+++ b/node_modules/p-map/readme.md
@@ -0,0 +1,99 @@
+# p-map [![Build Status](https://travis-ci.org/sindresorhus/p-map.svg?branch=master)](https://travis-ci.org/sindresorhus/p-map)
+
+> Map over promises concurrently
+
+Useful when you need to run promise-returning & async functions multiple times with different inputs concurrently.
+
+
+## Install
+
+```
+$ npm install p-map
+```
+
+
+## Usage
+
+```js
+const pMap = require('p-map');
+const got = require('got');
+
+const sites = [
+ getWebsiteFromUsername('https://sindresorhus'), //=> Promise
+ 'https://ava.li',
+ 'https://github.com'
+];
+
+(async () => {
+ const mapper = async site => {
+ const {requestUrl} = await got.head(site);
+ return requestUrl;
+ };
+
+ const result = await pMap(sites, mapper, {concurrency: 2});
+
+ console.log(result);
+ //=> ['https://sindresorhus.com/', 'https://ava.li/', 'https://github.com/']
+})();
+```
+
+## API
+
+### pMap(input, mapper, options?)
+
+Returns a `Promise` that is fulfilled when all promises in `input` and ones returned from `mapper` are fulfilled, or rejects if any of the promises reject. The fulfilled value is an `Array` of the fulfilled values returned from `mapper` in `input` order.
+
+#### input
+
+Type: `Iterable<Promise | unknown>`
+
+Iterated over concurrently in the `mapper` function.
+
+#### mapper(element, index)
+
+Type: `Function`
+
+Expected to return a `Promise` or value.
+
+#### options
+
+Type: `object`
+
+##### concurrency
+
+Type: `number`<br>
+Default: `Infinity`<br>
+Minimum: `1`
+
+Number of concurrently pending promises returned by `mapper`.
+
+##### stopOnError
+
+Type: `boolean`<br>
+Default: `true`
+
+When set to `false`, instead of stopping when a promise rejects, it will wait for all the promises to settle and then reject with an [aggregated error](https://github.com/sindresorhus/aggregate-error) containing all the errors from the rejected promises.
+
+
+## Related
+
+- [p-all](https://github.com/sindresorhus/p-all) - Run promise-returning & async functions concurrently with optional limited concurrency
+- [p-filter](https://github.com/sindresorhus/p-filter) - Filter promises concurrently
+- [p-times](https://github.com/sindresorhus/p-times) - Run promise-returning & async functions a specific number of times concurrently
+- [p-props](https://github.com/sindresorhus/p-props) - Like `Promise.all()` but for `Map` and `Object`
+- [p-map-series](https://github.com/sindresorhus/p-map-series) - Map over promises serially
+- [p-queue](https://github.com/sindresorhus/p-queue) - Promise queue with concurrency control
+- [Moreā€¦](https://github.com/sindresorhus/promise-fun)
+
+
+---
+
+<div align="center">
+ <b>
+ <a href="https://tidelift.com/subscription/pkg/npm-p-map?utm_source=npm-p-map&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
+ </b>
+ <br>
+ <sub>
+ Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
+ </sub>
+</div>