appolo-utils
Advanced tools
Comparing version 0.0.18 to 0.0.19
@@ -19,2 +19,26 @@ "use strict"; | ||
} | ||
static props(props, options = { concurrency: Infinity }) { | ||
const keys = Object.keys(props); | ||
const values = Object.values(props); | ||
return Promises.map(values, (item) => item, { concurrency: options.concurrency }) | ||
.then(resolved => { | ||
const res = {}; | ||
for (let i = 0, len = keys.length; i < len; i++) { | ||
res[keys[i]] = resolved[i]; | ||
} | ||
return res; | ||
}); | ||
} | ||
// public static propsMap<R, U>(iterable: Resolvable<Iterable<Resolvable<R>>>, mapper: (output: { [index: string]: Resolvable<U> }, item: R, index: number | string) => void, options: { concurrency: number } = {concurrency: Infinity}): Promise<{ [index: string]: U }> { | ||
// | ||
// let dto = {},index=0; | ||
// | ||
// for (let item of iterable[Symbol.iterator]()) { | ||
// mapper(dto, item,index) | ||
// index++; | ||
// } | ||
// | ||
// | ||
// return Promises.props(dto, {concurrency: options.concurrency}) | ||
// } | ||
static _mapWrapper(mapper, iterator, results, params) { | ||
@@ -21,0 +45,0 @@ let next = iterator.next(); |
@@ -9,3 +9,3 @@ type Resolvable<R> = R | PromiseLike<R> | ||
public static map<R, U>(iterable: Resolvable<Iterable<Resolvable<R>>>, mapper: IterateFunction<R, U>, options: { concurrency: number } = {concurrency: Infinity}) { | ||
public static map<R, U>(iterable: Resolvable<Iterable<Resolvable<R>>>, mapper: IterateFunction<R, U>, options: { concurrency: number } = {concurrency: Infinity}): Promise<U[]> { | ||
@@ -28,5 +28,33 @@ let concurrency = options.concurrency || Infinity; | ||
} | ||
public static props<T>(props: object & { [K in keyof T]: Resolvable<T[K]> }, options: { concurrency: number } = {concurrency: Infinity}): Promise<T> { | ||
const keys = Object.keys(props); | ||
const values = Object.values(props); | ||
return Promises.map(values, (item) => item, {concurrency: options.concurrency}) | ||
.then(resolved => { | ||
const res: { [K in keyof T]: T[K] } = {} as any; | ||
for (let i = 0, len = keys.length; i < len; i++) { | ||
res[keys[i]] = resolved[i]; | ||
} | ||
return res | ||
}) | ||
} | ||
// public static propsMap<R, U>(iterable: Resolvable<Iterable<Resolvable<R>>>, mapper: (output: { [index: string]: Resolvable<U> }, item: R, index: number | string) => void, options: { concurrency: number } = {concurrency: Infinity}): Promise<{ [index: string]: U }> { | ||
// | ||
// let dto = {},index=0; | ||
// | ||
// for (let item of iterable[Symbol.iterator]()) { | ||
// mapper(dto, item,index) | ||
// index++; | ||
// } | ||
// | ||
// | ||
// return Promises.props(dto, {concurrency: options.concurrency}) | ||
// } | ||
private static _mapWrapper<R, U>(mapper: IterateFunction<R, U>, iterator: IterableIterator<R>, results: any[], params: { index: number }) { | ||
@@ -48,3 +76,3 @@ | ||
public static filter<R, U>(iterable: Resolvable<Iterable<Resolvable<R>>>, filterer: IterateFunction<R, U>, options: { concurrency: number } = {concurrency: Infinity}) { | ||
public static filter<R, U>(iterable: Resolvable<Iterable<Resolvable<R>>>, filterer: IterateFunction<R, U>, options: { concurrency: number } = {concurrency: Infinity}): Promise<U[]> { | ||
let concurrency = options.concurrency || Infinity; | ||
@@ -51,0 +79,0 @@ |
@@ -17,3 +17,3 @@ { | ||
"main": "./index.js", | ||
"version": "0.0.18", | ||
"version": "0.0.19", | ||
"license": "MIT", | ||
@@ -20,0 +20,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
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
55059
1033