UNPKG

marko

Version:

Optimized runtime for Marko templates.

51 lines (50 loc) • 3.77 kB
export type Many<T> = [T, T, ...T[]]; export type OneMany<T> = T | Many<T>; export type Opt<T> = undefined | OneMany<T>; export type Compare<T> = (a: T, b: T) => number; declare const kSorted: unique symbol; export type SortedMany<T> = Many<T> & { readonly [kSorted]: true; }; export type SortedOneMany<T> = T | SortedMany<T>; export type SortedOpt<T> = undefined | SortedOneMany<T>; export declare class Sorted<T> { compare: Compare<T>; constructor(compare: Compare<T>); add<U extends NonNullable<T>>(data: SortedOpt<U>, item: U): SortedOneMany<U>; union<U extends NonNullable<T>>(a: SortedOpt<U>, b: SortedOpt<U>): SortedOpt<U>; filter<U extends NonNullable<T>>(data: SortedOpt<U>, cb: (item: U) => boolean): SortedOpt<U>; leadingRun<U extends NonNullable<T>, K>(data: SortedOpt<U>, key: (item: U) => K, compareKeys: Compare<K>, bound: K): SortedOpt<U>; range<U extends NonNullable<T>, K>(data: SortedOpt<U>, key: (item: U) => K, compareKeys: Compare<K>, bound: K): SortedOpt<U>; forEachRun<U extends NonNullable<T>, K>(data: SortedOpt<U>, key: (item: U) => K, compareKeys: Compare<K>, fn: (key: K, run: SortedOneMany<U>) => void): void; reduceRuns<U extends NonNullable<T>, K, R>(data: SortedOpt<U>, key: (item: U) => K, compareKeys: Compare<K>, fn: (acc: R, key: K, run: SortedOneMany<U>) => R, initial: R): R; find<U extends NonNullable<T>>(data: SortedOpt<U>, item: U): U | undefined; has<U extends NonNullable<T>>(data: SortedOpt<U>, item: U): boolean; findIndex<U extends NonNullable<T>>(data: SortedOpt<U>, item: U): number; intersects<U extends NonNullable<T>>(a: SortedOpt<U>, b: SortedOpt<U>): boolean; difference<U extends NonNullable<T>>(a: SortedOpt<U>, b: SortedOpt<U>): SortedOpt<U>; isSuperset<U extends NonNullable<T>>(superset: SortedOpt<U>, subset: SortedOpt<U>): boolean; } export declare function push<T>(data: Opt<T>, item: T): OneMany<T>; export declare function concat<T>(a: Opt<T>, b: Opt<T>): Opt<T>; export declare function size<T>(data: Opt<T>): number; export declare function filter<T>(data: Opt<T>, cb: (item: T) => boolean): Opt<T>; export declare function forEach<T>(data: Opt<T>, cb: (item: T, index: number) => void): void; export declare function fromIter<T>(data: Iterable<T>): T | Many<T> | undefined; export declare function find<T>(data: Opt<T>, cb: (item: T, index: number) => boolean): Opt<T>; export declare function some<T>(data: Opt<T>, cb: (item: T, index: number) => boolean): boolean; export declare function every<T>(data: Opt<T>, cb: (item: T, index: number) => boolean): boolean; export declare function reduce<T, R>(data: Opt<T>, cb: (acc: R | undefined, item: T, index: number) => R | undefined): R | undefined; export declare function reduce<T, R>(data: Opt<T>, cb: (acc: R, item: T, index: number) => R, initial: R): R; export declare function reduceWhile<T, R>(data: Opt<T>, cb: (acc: R, item: T) => R | undefined, initial: R): R | undefined; export declare function toArray<T, R>(data: Opt<T>, cb: (item: T, index: number) => R): R[]; export declare function toSet<T>(data: Opt<T>): Set<T>; export declare function mapToString<T>(data: Opt<T>, sep: string, cb: (item: T, index: number) => string): string; export declare function findSorted<T>(compare: Compare<T>, data: T[], item: T): T | undefined; export declare function findIndexSorted<T>(compare: Compare<T>, data: T[], item: T): number; export declare function addSorted<T, U extends T[]>(compare: Compare<T>, data: U, item: T): U; export declare function at<T>(data: Opt<T>, index: number): T | undefined; export declare function first<T>(data: OneMany<T>): T; export declare function last<T>(data: OneMany<T>): T; export declare function rest<T>(data: OneMany<T>): Opt<T>; export {};