@opencreek/ext
Advanced tools
Comparing version 1.5.2 to 1.6.0--canary.10.4956bdf444030df5906eb957192f3ad7f0eed4f7.0
@@ -12,2 +12,3 @@ declare type PairSplit<T> = T extends [infer F, infer L] ? [F[], L[]] : never; | ||
dropWhile(predicate: (el: T) => boolean): T[]; | ||
filterAsync(predicate: (el: T, index: number, array: Array<T>) => Promise<boolean>): Promise<Array<T>>; | ||
filterNotNullish(): Array<NonNullable<T>>; | ||
@@ -20,2 +21,3 @@ findLast(predicate: (el: T) => boolean): T | undefined; | ||
intersect(...arrays: (readonly T[])[]): T[]; | ||
mapAsync<U>(transformer: (el: T, index: number, array: Array<T>) => Promise<U>): Promise<Array<U>>; | ||
mapNotNullish<O>(transformer: (el: T) => O): NonNullable<O>[]; | ||
@@ -68,2 +70,3 @@ maxBy(selector: (el: T) => string): T | undefined; | ||
dropWhile(predicate: (el: T) => boolean): T[]; | ||
filterAsync(predicate: (el: T, index: number, array: Array<T>) => Promise<boolean>): Promise<Array<T>>; | ||
filterNotNullish(): Array<NonNullable<T>>; | ||
@@ -76,2 +79,3 @@ findLast(predicate: (el: T) => boolean): T | undefined; | ||
intersect(...arrays: (readonly T[])[]): T[]; | ||
mapAsync<U>(transformer: (el: T, index: number, array: Array<T>) => Promise<U>): Promise<Array<U>>; | ||
mapNotNullish<O>(transformer: (el: T) => O): NonNullable<O>[]; | ||
@@ -78,0 +82,0 @@ maxBy(selector: (el: T) => string): T | undefined; |
@@ -21,4 +21,14 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const collections = __importStar(require("@opencreek/deno-std-collections")); | ||
const _1 = require("."); | ||
const extendPrototype_1 = require("./extendPrototype"); | ||
@@ -28,6 +38,19 @@ function filterNotNullish() { | ||
} | ||
function mapAsync(f) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return Promise.all(this.map(f)); | ||
}); | ||
} | ||
function filterAsync(f) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const includes = yield this.mapAsync(f); | ||
return this.filter((_, index) => includes[index]); | ||
}); | ||
} | ||
function extendArray(key) { | ||
(0, extendPrototype_1.extendProtoype)(Array, (0, extendPrototype_1.apply)(collections[key]), key); | ||
} | ||
(0, extendPrototype_1.extendProtoype)(Array, filterNotNullish, "filterNotNullish"); | ||
(0, _1.extendPrototypeWithName)(Array, { filterNotNullish }); | ||
(0, _1.extendPrototypeWithName)(Array, { filterAsync }); | ||
(0, _1.extendPrototypeWithName)(Array, { mapAsync }); | ||
extendArray("associateBy"); | ||
@@ -34,0 +57,0 @@ extendArray("associateWith"); |
export declare function extendProtoype(target: Function, func: Function, functionName: string): void; | ||
export declare function extendPrototypeWithName<T extends Record<string, Function>>(target: Function, wrap: T): void; | ||
declare type ThisFunction<F extends (...args: any) => any> = (this: FirstParameter<F>, ...args: SkipFirstParameter<F>) => ReturnType<F>; | ||
@@ -3,0 +4,0 @@ declare type FirstParameter<F extends (...args: any) => any> = Parameters<F> extends [ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.apply = exports.extendProtoype = void 0; | ||
exports.apply = exports.extendPrototypeWithName = exports.extendProtoype = void 0; | ||
/* eslint-disable @typescript-eslint/ban-types */ | ||
@@ -14,2 +14,7 @@ function extendProtoype(target, func, functionName) { | ||
exports.extendProtoype = extendProtoype; | ||
function extendPrototypeWithName(target, wrap) { | ||
const name = Object.keys(wrap)[0]; | ||
extendProtoype(target, wrap[name], name); | ||
} | ||
exports.extendPrototypeWithName = extendPrototypeWithName; | ||
function apply(f) { | ||
@@ -16,0 +21,0 @@ return function (...b) { |
{ | ||
"name": "@opencreek/ext", | ||
"version": "1.5.2", | ||
"version": "1.6.0--canary.10.4956bdf444030df5906eb957192f3ad7f0eed4f7.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
import * as collections from "@opencreek/deno-std-collections" | ||
import { extendPrototypeWithName } from "." | ||
import { apply, extendProtoype } from "./extendPrototype" | ||
@@ -10,2 +11,18 @@ | ||
async function mapAsync<T, U>( | ||
this: Array<T>, | ||
f: (e: T, index: number, array: Array<T>) => Promise<U> | ||
): Promise<Array<U>> { | ||
return Promise.all(this.map(f)) | ||
} | ||
async function filterAsync<T>( | ||
this: Array<T>, | ||
f: (e: T, index: number, array: Array<T>) => Promise<boolean> | ||
): Promise<Array<T>> { | ||
const includes = await this.mapAsync(f) | ||
return this.filter((_, index) => includes[index]) | ||
} | ||
function extendArray< | ||
@@ -24,3 +41,5 @@ KEY extends { | ||
extendProtoype(Array, filterNotNullish, "filterNotNullish") | ||
extendPrototypeWithName(Array, { filterNotNullish }) | ||
extendPrototypeWithName(Array, { filterAsync }) | ||
extendPrototypeWithName(Array, { mapAsync }) | ||
@@ -75,2 +94,3 @@ extendArray("associateBy") | ||
dropWhile(predicate: (el: T) => boolean): T[] | ||
filterAsync(predicate: (el: T, index: number, array: Array<T>) => Promise<boolean>): Promise<Array<T>> | ||
filterNotNullish(): Array<NonNullable<T>> | ||
@@ -85,2 +105,3 @@ findLast(predicate: (el: T) => boolean): T | undefined | ||
intersect(...arrays: (readonly T[])[]): T[] | ||
mapAsync<U>(transformer: (el: T, index: number, array: Array<T>) => Promise<U>): Promise<Array<U>> | ||
mapNotNullish<O>(transformer: (el: T) => O): NonNullable<O>[] | ||
@@ -136,2 +157,3 @@ maxBy(selector: (el: T) => string): T | undefined | ||
dropWhile(predicate: (el: T) => boolean): T[] | ||
filterAsync(predicate: (el: T, index: number, array: Array<T>) => Promise<boolean>): Promise<Array<T>> | ||
filterNotNullish(): Array<NonNullable<T>> | ||
@@ -146,2 +168,3 @@ findLast(predicate: (el: T) => boolean): T | undefined | ||
intersect(...arrays: (readonly T[])[]): T[] | ||
mapAsync<U>(transformer: (el: T, index: number, array: Array<T>) => Promise<U>): Promise<Array<U>> | ||
mapNotNullish<O>(transformer: (el: T) => O): NonNullable<O>[] | ||
@@ -148,0 +171,0 @@ maxBy(selector: (el: T) => string): T | undefined |
@@ -15,2 +15,11 @@ /* eslint-disable @typescript-eslint/ban-types */ | ||
export function extendPrototypeWithName<T extends Record<string, Function>>( | ||
target: Function, | ||
wrap: T | ||
): void { | ||
const name = Object.keys(wrap)[0] | ||
extendProtoype(target, wrap[name], name) | ||
} | ||
type ThisFunction<F extends (...args: any) => any> = ( | ||
@@ -17,0 +26,0 @@ this: FirstParameter<F>, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
48643
722
43
2