import isFunction from "lodash-es/isFunction"; import isNumber from "lodash-es/isNumber"; import isString from "lodash-es/isString"; export { isFunction, isNumber, isString }; /** * Checks if a value is neither `null` nor `undefined`. */ export declare function isNotNullish(value: ValueType): value is Exclude; /** * Checks if a value is either `null` or `undefined`. */ export declare function isNullish(value: unknown): value is null | undefined; export declare function getFromRecordOrNull(record: Record | null | undefined, key: RecordKey | undefined | null): NonNullable[RecordKey]> | null; export declare function isPrimitive(value: unknown): value is string | number | boolean; type StructureRecord = { [MemberType in UnionType as MemberType["type"]]: ResultType | ((value: MemberType) => ResultType); }; type StructureRecordBareString = { [MemberType in UnionType]: ResultType | ((value: MemberType) => ResultType); }; type StructureRecordGeneric, ResultType, KeyType extends keyof UnionType> = { [MemberType in UnionType as MemberType[KeyType]]: ResultType | ((value: MemberType) => ResultType); }; /** * @returns A function which can be used to create an exhaustive switch over all * types of a discriminated union, based on a given key, or over all members of * a bare string union. * * When no key is provided, it defaults to using "type" as the discriminant. * When the value is a bare string union, the value is its own discriminant. * * Examples: * * With default "type" discriminant: * ``` * type OneOrTwo = { type: "one", numberValue: number } | * { type: "two", stringValue: string } * * let oneOrTwo = ... * let result = exhaustiveSwitch(oneOrTwo)({ * one: (op) => `${op.numberValue + 1}`, // Typescript knows numberValue is a number * two: (op) => op.stringValue + "hello", // Typescript knows stringValue is a string * }) // type of result is inferred to be string * ``` * * With custom discriminant key: * ``` * type OneOrTwo = { variant: "one", numberValue: number } | * { variant: "two", stringValue: string } * * let oneOrTwo = ... * let result = exhaustiveSwitch(oneOrTwo, "variant")({ * one: (op) => `${op.numberValue + 1}`, // Typescript knows numberValue is a number * two: (op) => op.stringValue + "hello", // Typescript knows stringValue is a string * }) // type of result is inferred to be string * ``` * * With a bare string union: * ``` * type OneOrTwo = "one" | "two" * * let oneOrTwo = ... * let result = exhaustiveSwitch(oneOrTwo)({ * one: 1, // cases can be plain values... * two: () => 1 + 1, // ...or functions, evaluated lazily * }) // type of result is inferred to be number * ``` * * Typescript will error if you forget a case, or if you assume the wrong type * for a case value. The switch also returns the value you return from the * function mapping, so it works well for "extension" methods where you want to * map over all discriminated union cases and do a different thing for each. * * Works well for many of our types, like ComponentActionType, Action, etc */ export declare function exhaustiveSwitch(value: UnionType): (cases: StructureRecordBareString) => ResultType; export declare function exhaustiveSwitch(value: UnionType): (cases: StructureRecord) => ResultType; export declare function exhaustiveSwitch, KeyType extends keyof UnionType>(value: UnionType, key: KeyType): (cases: StructureRecordGeneric) => ResultType; type EmptyObject = { [KeyType in keyof ValueType]?: never; }; type EmptyObjectOf = EmptyObject extends ValueType ? EmptyObject : never; /** * The same as `isEmpty` from lodash, but with a few additional overloads for * stronger type-checking on empty arrays. */ export declare function isEmpty(value: string): value is ""; export declare function isEmpty(value: ValueType | null | undefined): value is (ValueType & []) | null | undefined; export declare function isEmpty>(value: ValueType | null | undefined): value is (ValueType & { length: 0; }) | null | undefined; export declare function isEmpty(value: Map | Set | ArrayLike | null | undefined): boolean; export declare function isEmpty(value: object): boolean; export declare function isEmpty(value: ValueType | null | undefined): value is EmptyObjectOf | null | undefined; export declare function isEmpty(value?: any): boolean; export declare function noop(): void; export declare function preventDefault(event: { preventDefault(): void; }): void; /** * Copyright (c) 2019 Alexander Reardon * https://github.com/alexreardon/tiny-warning/blob/master/src/index.js */ export declare function warning(condition: unknown, message: string | (() => string), options?: { severity: "log" | "warn" | "error"; }): void; /** * * Copyright (c) 2019 Alexander Reardon * https://github.com/alexreardon/tiny-warning/blob/master/src/index.js */ export declare function invariant(condition: unknown, message: string | (() => string), opts?: { stripErrorMessage: unknown; }): asserts condition; export declare const mergeReplacingObjects: (first: Object, second: Object) => void; export declare const mergeReplacingArrays: (first: Object, second: Object) => void; export declare const deepCloneAndMergeReplacingArrays: (source: ValueType, ...toMerge: Object[]) => ValueType; /** * hasOwnProperty with a type assertion. If this returns true, typescript knows that `obj` * has a property called `prop` from that point forward * https://fettblog.eu/typescript-hasownproperty/ */ export declare function hasOwnProperty(obj: ObjectType, prop: KeyType): obj is ObjectType & Record; /** * Given a string | number param, converts it to a string, unless it's nullish * in which case it just returns it. Useful for times when you have string | number * | nullish types, like when selecting the current value of a CSS property in a right * bar modifier */ export declare function coerceNumberToString(value: string | number): string; export declare function coerceNumberToString(value: string | number | null | undefined): string | null | undefined; export declare function coerceNumberToString(value: string | number | undefined): string | undefined; export declare function coerceNumberToString(value: string | number | null): string | null; /** * Formats a file size in bytes to a human readable string with appropriate * units. Rounds to 0 decimal places unless otherwise specified and uses * standard binary units (KB, MB, etc). */ export declare function formatFileSize(byteCount: number, decimalPlaces?: number): string; export declare const sleep: (ms: number) => Promise; export declare function sleepWithSignal({ delayMs, signal, }: { delayMs: number; signal: AbortSignal | null; }): Promise; export declare function errorMessage(error: unknown): string;