UNPKG

@focuson/utils

Version:

Common utilities for the @focuson project

60 lines (59 loc) 3.85 kB
export interface HasDateFn { dateFn: DateFn; } export type DateFn = () => string; export declare const testDateFn: DateFn; export declare const defaultDateFn: DateFn; export interface HasName { name: string; } export interface CopyDetails { from?: string; to?: string; } export interface RequiredCopyDetails { from: string; to: string; } export declare function checkIsFunction(functionToCheck: any): void; export declare function ints(n: number): number[]; export declare const mapPathPlusInts: (path: number[], count: number) => <T>(fn: (p: number[]) => T) => T[]; export declare const apply: <T, T1>(t: T, fn: (t: T) => T1) => T1; export declare const applyOrDefault: <T, T1>(t: T, fn: (t: T) => T1, def: T1) => T1; export declare const useOrDefault: <T>(def: T) => (t: T) => T; export declare const or: <T>(defaultT: () => T) => (t: T) => T; export declare function copyWithFieldSet<T, K extends keyof T>(t: T, k: K, v: T[K]): T; export declare function safeObject<T>(t: NameAnd<T> | undefined): NameAnd<T>; export declare function mapObject<T, T1>(t: NameAnd<T>, fn: (t: T) => T1): NameAnd<T1>; export declare function filterMapObject<T, T1>(t: NameAnd<T>, filter: ([name, t]: [string, T]) => boolean, fn: (t: T) => T1): NameAnd<T1>; export declare function filterObject<T>(t: NameAnd<T>, filter: ([name, t]: [string, T]) => boolean): NameAnd<T>; export declare function safeArray<T>(ts: T[] | undefined, errorMessage?: string): T[]; export declare function toArray<T>(ts: T | T[] | undefined): T[]; export declare function toArrayOrUndefined<T>(ts: T | T[] | undefined): T[] | undefined; export declare function safeString(s: string | undefined | number): string; export declare function safeNumber(s: number | undefined, defaultValue?: number): number; export declare function numberOrUndefined(s: any): number | undefined; export declare function safePick(s: string[] | undefined, i: number): string; export declare function asMultilineJavaString(ss: string[], indent?: string): string[]; export declare function beforeSeparator(separator: string, string: string): string; export declare function beforeAfterSeparator(separator: string, string: string): [string, string]; export declare function insertBefore(separator: string, insert: string, s: string): string; export declare function arraysEqual<T>(a: T[] | undefined, b: T[] | undefined): boolean; export declare function areAllDefined<T>(arr: (T | undefined)[] | undefined): arr is T[]; export interface NameAnd<T> { [name: string]: T; } export declare function sortedEntries<T>(a: NameAnd<T> | undefined): [string, T][]; export declare function unsortedEntries<T>(a: NameAnd<T> | undefined): [string, T][]; export declare function findJoiner(name: string, joiners: undefined | string | string[]): string; export declare function anyIntoPrimitive(raw: any, joiner: string): string | number | boolean; export declare function makeIntoString(name: string, raw: any, joiners: undefined | string | string[]): string; export declare function unique<T>(ts: T[] | undefined, tagFn: (t: T) => string): T[]; export declare function resultOrErrorString<T>(fn: () => T): T | string; export declare const errorMonad: <S extends unknown>(s: S, debug: boolean, onError: (s: S, e: any) => S, ...fns: [string, (s: S) => S][]) => S; export declare const errorPromiseMonad: <S extends unknown>(onError: (s: S, e: any) => S) => (s: S, debug: boolean, ...fns: [string, (s: S) => Promise<S>][]) => Promise<S>; export declare function safeFlatten(s: string[][] | undefined): string[]; export declare const disabledFrom: (s?: string[][]) => boolean; export type DateCheck = '>' | '<' | '<=' | '>='; export declare function checkDates(d1: string | undefined, d2: string | undefined, dateCheck: DateCheck): boolean; export declare function requireBypassingReactCheck(s: string): any;