UNPKG

@altostra/core

Version:

Core library for shared types and logic

65 lines (64 loc) 4.03 kB
import type { Maybe } from "../common/Maybe"; import type { Key as RecordKey } from "../common/Types"; export declare function getFromEnvironment<T extends string>(names: T[], defaults?: Partial<Record<T, string>>): Record<T, string>; export declare function sanitizeId(value: string): string; interface PointInSpace { x: number; y: number; z: number; } /** * v1.2 */ export type { RecordKey }; export declare function notNull<T>(x: T | null | undefined): x is T; export declare function id<T>(x: T): T; export declare function exists<T>(x: Maybe<T> | null): x is T; export declare function isNonEmptyArray<T>(xs?: T[]): xs is [T, ...T[]]; export declare function isEmptyArray<T>(xs: T[]): boolean; export declare function assign<K extends RecordKey, T>(record: Record<K, T>, key: K, x: T): Record<K, T>; export declare function toLowerCase(s: string): string; export declare function length<T>(xs: T[]): number; export declare function head<T>(xs: T[]): T; export declare function last<T>(xs: T[]): T; export declare function fst<T, _>([x, _]: [T, _]): T; export declare function snd<_, T>([_, x]: [_, T]): T; export declare function concat<T>(...xss: T[][]): T[]; export declare function flatten<T>(xs: T[][]): T[]; export declare function map<S, T>(f: (x: S) => T, xs: S[]): T[]; export declare function map_<S, T>(f: (x: S) => T): (xs: S[]) => T[]; export declare function mapIf<S>(p: (x: S) => boolean): (f: (x: S) => S, xs: S[]) => S[]; export declare function offsetPoint(offset: PointInSpace): (point: PointInSpace) => PointInSpace; export declare const values: <K extends RecordKey, T>(rs: Record<K, T>) => T[]; export declare function keys<K extends RecordKey, T>(rs: Record<K, T>): K[]; export declare function toPairs<K extends RecordKey, T>(rs: Record<K, T>): [K, T][]; export declare function merge<K extends RecordKey, T>(a: Record<K, T>, b: Record<K, T>): Record<K, T>; export declare function reduceRecord<K extends RecordKey, S, T>(f: (acc: T, x: S, k: K) => T, init: T, rs: Record<K, S>): T; export declare function mapRecord<K extends RecordKey, S, T>(f: (x: S, k: K) => T, rs: Record<K, S>): Record<K, T>; /** * Until we get proper transducers, use this. */ export declare function filterMapRecord<K extends RecordKey, U, S extends U, T>(p: (x: U, k: K) => x is S, f: (x: S, k: K) => T): (rs: Record<K, U>) => Record<K, T>; export declare function filterRecord<K extends RecordKey, T>(p: (x: T, k: K) => boolean): (rx: Record<K, T>) => Record<K, T>; /** * Narrows a record's values from union type to a sub-type. */ export declare function narrowRecord<K extends RecordKey, U, T extends U>(p: (x: U) => x is T): (rs: Record<K, U>) => Record<K, T>; export declare function flatMap<S, T>(f: (x: S) => T[], xs: S[]): T[]; export declare function flatMapP<S, T>(f: (x: S) => Promise<T[]>, xs: S[]): Promise<T[]>; export declare function filter<T>(p: (x: T) => boolean, xs: T[]): T[]; export declare function filterType<U, T extends U>(p: (x: U) => x is T, xs: U[]): T[]; export declare function mapFilter<S, T>(f: (x: S) => T | null, xs: S[]): T[]; export declare function forEach<T>(f: (x: T) => void, xs: T[]): T[]; export declare function reduce<S, T>(f: (a: T, x: S) => T, init: T, xs: S[]): T; export declare function hasEntry<K extends RecordKey, T>(name: K, record: Record<K, T>): boolean; export declare function zipRecord<K extends RecordKey, T>(keys: K[], values: T[]): Record<K, T>; export declare function propEq<S extends object>(prop: keyof S, expected: any): (s: S) => boolean; export declare function pickBy<S extends object>(p: (x: any, k: keyof S) => boolean, s: S): S; /** * Be aware that this function overrides repeating keys. */ export declare function smashRecords<K extends RecordKey, S, T>(f: (x: S) => Record<K, T>, init: Record<K, T>, xs: S[]): Record<K, T>; export declare function logAndGetRejection<T>(msg: string, err: Error): Promise<T>; export declare function toCamelCase(x: string): string; export declare function toAlphanumUuid(s: RecordKey): string;