@supercharge/collections
Advanced tools
Comparing version 4.0.1 to 4.1.0
@@ -210,2 +210,12 @@ export declare class Collection { | ||
/** | ||
* A variant of the `filter` method running the (async) testing | ||
* function only if the given `condition` is `true`. | ||
* | ||
* @param {Function} callback | ||
* @param {Boolean} condition | ||
* | ||
* @returns {Array} | ||
*/ | ||
mapIf(callback: Function, condition: boolean): Promise<any[]>; | ||
/** | ||
* Returns the max value in the collection. | ||
@@ -212,0 +222,0 @@ * |
@@ -307,2 +307,16 @@ 'use strict'; | ||
/** | ||
* A variant of the `filter` method running the (async) testing | ||
* function only if the given `condition` is `true`. | ||
* | ||
* @param {Function} callback | ||
* @param {Boolean} condition | ||
* | ||
* @returns {Array} | ||
*/ | ||
async mapIf(callback, condition) { | ||
return condition | ||
? this.map(callback) | ||
: this.items; | ||
} | ||
/** | ||
* Returns the max value in the collection. | ||
@@ -309,0 +323,0 @@ * |
@@ -99,3 +99,3 @@ import { QueueItem } from './contracts'; | ||
/** | ||
* Asynchronous version of `Array#every()`, running the (async) testing | ||
* Asynchronous version of `Array#every()`, running the async testing | ||
* function in sequence. Returns `true` if all items in the collection | ||
@@ -111,3 +111,3 @@ * pass the check implemented by the `callback`, otherwise `false`. | ||
/** | ||
* Asynchronous version of Array#filter(), running the (async) testing | ||
* Asynchronous version of Array#filter(), running the async testing | ||
* function in sequence. The `callback` should return `true` | ||
@@ -123,3 +123,3 @@ * if an item should be included in the resulting collection. | ||
/** | ||
* A variant of the `filter` method running the (async) testing | ||
* A variant of the `filter` method running the async testing | ||
* function only if the given `condition` is `true`. | ||
@@ -135,3 +135,3 @@ * | ||
/** | ||
* Asynchronous version of Array#find(), running the (async) testing | ||
* Asynchronous version of Array#find(), running the async testing | ||
* function in sequence. Returns the first item in the collection | ||
@@ -271,2 +271,12 @@ * satisfying the given `callback`, `undefined` otherwise. | ||
/** | ||
* A variant of the `map` method running the async `action` | ||
* function only if the given `condition` is `true`. | ||
* | ||
* @param {Function} callback | ||
* | ||
* @returns {Array} | ||
*/ | ||
mapIf<R>(condition: boolean, action: (value: T, index: number, items: T[]) => Promise<R>): PendingAsyncCollection<R>; | ||
mapIf<R>(condition: boolean, action: (value: T, index: number, items: T[]) => R): PendingAsyncCollection<R>; | ||
/** | ||
* Returns the max value in the collection. | ||
@@ -388,3 +398,3 @@ * | ||
/** | ||
* Asynchronous version of `Array#some()`, running the (async) testing function | ||
* Asynchronous version of `Array#some()`, running the async testing function | ||
* in sequence. Returns `true` if at least one element in the collection | ||
@@ -391,0 +401,0 @@ * passes the check implemented by the `callback`, otherwise `false`. |
@@ -238,2 +238,5 @@ 'use strict'; | ||
} | ||
mapIf(condition, action) { | ||
return this.enqueue('mapIf', action, condition); | ||
} | ||
/** | ||
@@ -240,0 +243,0 @@ * Returns the max value in the collection. |
{ | ||
"name": "@supercharge/collections", | ||
"description": "async/await-ready array methods for JavaScript and Node.js", | ||
"version": "4.0.1", | ||
"version": "4.1.0", | ||
"author": "Marcus Pöhls <marcus@superchargejs.com>", | ||
@@ -6,0 +6,0 @@ "bugs": { |
163336
5332