Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

p-map

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

p-map - npm Package Compare versions

Comparing version 5.0.0 to 5.1.0

36

index.d.ts

@@ -41,3 +41,3 @@ export interface Options {

const sites = [
getWebsiteFromUsername('https://sindresorhus'), //=> Promise
getWebsiteFromUsername('sindresorhus'), //=> Promise
'https://avajs.dev',

@@ -62,2 +62,34 @@ 'https://github.com'

options?: Options
): Promise<NewElement[]>;
): Promise<Array<Exclude<NewElement, typeof pMapSkip>>>;
/**
Return this value from a `mapper` function to skip including the value in the returned array.
@example
```
import pMap, {pMapSkip} from 'p-map';
import got from 'got';
const sites = [
getWebsiteFromUsername('sindresorhus'), //=> Promise
'https://avajs.dev',
'https://example.invalid',
'https://github.com'
];
const mapper = async site => {
try {
const {requestUrl} = await got.head(site);
return requestUrl;
} catch {
return pMapSkip
}
};
const result = await pMap(sites, mapper, {concurrency: 2});
console.log(result);
//=> ['https://sindresorhus.com/', 'https://avajs.dev/', 'https://github.com/']
```
*/
export const pMapSkip: unique symbol;

@@ -22,2 +22,3 @@ import AggregateError from 'aggregate-error';

const errors = [];
const skippedIndexes = [];
const iterator = iterable[Symbol.iterator]();

@@ -45,2 +46,6 @@ let isRejected = false;

} else {
for (const skippedIndex of skippedIndexes) {
result.splice(skippedIndex, 1);
}
resolve(result);

@@ -58,3 +63,14 @@ }

const element = await nextItem.value;
result[index] = await mapper(element, index);
if (isRejected) {
return;
}
const value = await mapper(element, index);
if (value === pMapSkip) {
skippedIndexes.push(index);
} else {
result[index] = value;
}
resolvingCount--;

@@ -84,1 +100,3 @@ next();

}
export const pMapSkip = Symbol('skip');

2

package.json
{
"name": "p-map",
"version": "5.0.0",
"version": "5.1.0",
"description": "Map over promises concurrently",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -22,3 +22,3 @@ # p-map

const sites = [
getWebsiteFromUsername('https://sindresorhus'), //=> Promise
getWebsiteFromUsername('sindresorhus'), //=> Promise
'https://avajs.dev',

@@ -76,2 +76,32 @@ 'https://github.com'

### pMapSkip
Return this value from a `mapper` function to skip including the value in the returned array.
```js
import pMap, {pMapSkip} from 'p-map';
import got from 'got';
const sites = [
getWebsiteFromUsername('sindresorhus'), //=> Promise
'https://avajs.dev',
'https://example.invalid',
'https://github.com'
];
const mapper = async site => {
try {
const {requestUrl} = await got.head(site);
return requestUrl;
} catch {
return pMapSkip
}
};
const result = await pMap(sites, mapper, {concurrency: 2});
console.log(result);
//=> ['https://sindresorhus.com/', 'https://avajs.dev/', 'https://github.com/']
```
## p-map for enterprise

@@ -78,0 +108,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc