UNPKG

yewtils

Version:

193 lines (184 loc) 6.33 kB
declare const cacheStringFunction: <T extends (str: string) => string>(fn: T) => T; /** * convert a string to kebab case e.g "hello-world" * toKababCase will convert: snake_case, PascalCase and camelCase (or a mixture of all three) to lowercased kabab case * @param value string * @returns string */ declare function toKebabCase(value: string): string; /** * convert a string to camel case e.g "helloWorld" * toKababCase will convert: snake_case, PascalCase and kabab-case (or a mixture of all three) to lowercased kabab case * @param value string * @returns string */ declare function toCamelCase(value: string): string; /** * convert a string to pascal case e.g "HelloWorld" * toKababCase will convert: snake_case, PascalCase and kabab-case (or a mixture of all three) to lowercased kabab case * @param value string * @returns string */ declare function toPascalCase(value: string): string; /** * predictibly hashes a string to a hex value (NOT TO BE USED FOR PW OR SECRETS) * @param str * @returns hashed string */ declare const createHash: (str: string) => string; /** * define a configureable non-iterable property on an object, * good for adding internal values to an object that doesn't need to be exposed via typescript */ declare const defineProperty: (obj: object, key: string | symbol, value: any) => void; /** * alias of Object.prototype.hasOwnProperty */ declare const hasOwnProperty: (val: object, key: string | symbol) => key is never; /** * alias of Object.assign */ declare const extend: { <T extends {}, U>(target: T, source: U): T & U; <T_1 extends {}, U_1, V>(target: T_1, source1: U_1, source2: V): T_1 & U_1 & V; <T_2 extends {}, U_2, V_1, W>(target: T_2, source1: U_2, source2: V_1, source3: W): T_2 & U_2 & V_1 & W; (target: object, ...sources: any[]): any; }; declare const toTypeString: (value: unknown) => string; /** * coerce value to number, if coerced value is NaN then return original value */ declare const toNumber: <T>(val: T) => number | T; declare const toRawType: (value: unknown) => string; /** * an empty readonly object */ declare const EMPTY_OBJ: { readonly [key: string]: any; }; declare function emptyObject<T extends object>(): T; /** * an empty readonly array */ declare const EMPTY_ARR: readonly any[]; declare function emptyArray<T>(): T[]; /** * function that does nothing */ declare const NO_OP: () => void; /** * Always return false. */ declare const NO: () => false; /** * remove item from an array */ declare const remove: <T>(arr: T[], el: T) => void; declare const hasChanged: <T>(value: T, oldValue: T) => boolean; /** * invoke functions stored in an array with the passed argument */ declare const invokeArrayFns: <T extends (...arg: Parameters<T>) => void>(fns: T[], ...arg: Parameters<T>) => void; /** * Get last item * * @category Array */ declare function last(array: readonly []): undefined; declare function last<T>(array: readonly T[]): T; /** * Get nth item of Array. Negative for backward * * @category Array */ declare function at(array: readonly [], index: number): undefined; declare function at<T>(array: readonly T[], index: number): T; /** * Genrate a range array of numbers. The `stop` is exclusive. * * @category Array */ declare function range(stop: number): number[]; declare function range(start: number, stop: number, step?: number): number[]; /** * Move element in an Array * * @category Array * @param arr * @param from * @param to */ declare function move<T>(arr: T[], from: number, to: number): T[]; declare function guard<T>(_value: any, isMatched: boolean): _value is T; /** * Type guard to filter out null-ish values * * @category Guards * @example array.filter(notNullish) */ declare function notNullish<T>(v: T | null | undefined): v is NonNullable<T>; /** * Type guard to filter out null values * * @category Guards * @example array.filter(noNull) */ declare function noNull<T>(v: T | null): v is Exclude<T, null>; /** * Type guard to filter out null-ish values * * @category Guards * @example array.filter(notUndefined) */ declare function notUndefined<T>(v: T): v is Exclude<T, undefined>; /** * Type guard to filter out falsy values * * @category Guards * @example array.filter(isTruthy) */ declare function isTruthy<T>(v: T): v is NonNullable<T>; declare function assert(condition: boolean, message: string): asserts condition; declare const isArray: (arg: any) => arg is any[]; declare const isMap: (val: unknown) => val is Map<any, any>; declare const isSet: (val: unknown) => val is Set<any>; declare const isDate: (val: unknown) => val is Date; declare const isFunction: (val: unknown) => val is Function; declare const isString: (val: unknown) => val is string; declare const isSymbol: (val: unknown) => val is symbol; declare const isObject: (val: unknown) => val is Record<any, any>; declare const isPromise: <T = any>(val: unknown) => val is Promise<T>; declare const isPlainObject: (val: unknown) => val is object; declare const isIntegerKey: (key: unknown) => boolean; declare type Maybe<T> = T | undefined; /** * Promise, or maybe not */ declare type Awaitable<T> = T | PromiseLike<T>; /** * Null or whatever */ declare type Nullable<T> = T | null | undefined; /** * Array, or not yet */ declare type Arrayable<T> = T | Array<T>; /** * Function */ declare type Fn<T = void> = () => T; /** * Constructor */ declare type Constructor<T = void> = new (...args: any[]) => T; /** * Infers the element type of an array */ declare type ElementOf<T> = T extends (infer E)[] ? E : never; /** * Promised `setTimeout` * * @category Promise */ declare function sleep(ms: number, callback?: Fn<any>): Promise<void>; export { Arrayable, Awaitable, Constructor, EMPTY_ARR, EMPTY_OBJ, ElementOf, Fn, Maybe, NO, NO_OP, Nullable, assert, at, cacheStringFunction, createHash, defineProperty, emptyArray, emptyObject, extend, guard, hasChanged, hasOwnProperty, invokeArrayFns, isArray, isDate, isFunction, isIntegerKey, isMap, isObject, isPlainObject, isPromise, isSet, isString, isSymbol, isTruthy, last, move, noNull, notNullish, notUndefined, range, remove, sleep, toCamelCase, toKebabCase, toNumber, toPascalCase, toRawType, toTypeString };