This repo is for utility methods and types related to JavaScript programming in general.
Anything that is only used by a single package should go in that package's src/utils.ts file; and anything that is related to a specific feature or domain should go in its own utility package.
export function assert(condition: unknown, message?: string): asserts condition
export type Awaitable<T> = T | Promise<T>
export type JSONValue =
| null
| boolean
| number
| string
| JSONArray
| JSONObject
export interface JSONArray extends Array<JSONValue> {}
export interface JSONObject {
[key: string]: JSONValue
}
export type JSValue =
| undefined
| null
| boolean
| number
| string
| Uint8Array
| JSArray
| JSObject
export interface JSArray extends Array<JSValue> {}
export interface JSObject {
[key: string]: JSValue
}
export function isArray(value: JSValue): value is JSArray
export function isObject(value: JSValue): value is JSObject
export type JSType =
| "undefined"
| "null"
| "boolean"
| "number"
| "string"
| "Uint8Array"
| "Array"
| "Object"
export function typeOf(value: JSValue): JSType
export function deepEqual(a: JSValue, b: JSValue): boolean
export function mapEntries<K extends string, S, T>(
object: Record<K, S>,
map: (entry: [key: K, value: S]) => T,
): Record<K, T>
export function mapKeys<K extends string, S, T>(
object: Record<K, S>,
map: (key: K) => T,
): Record<K, T>
export function mapValues<K extends string, S, T>(
object: Record<K, S>,
map: (value: S) => T,
): Record<K, T>
/** Recursively replace every `undefined` with `null` in ararys and objects */
export function replaceUndefined(value: JSValue, inPlace = false): JSValue
/** Recursively remove every object entry with value `undefined` */
export function stripUndefined(value: JSValue, inPlace = false): JSValue
export function signalInvalidType(type: never): never
export type Zip<E> = E extends Iterable<any>[]
? { [k in keyof E]: E[k] extends Iterable<infer T> ? T : E[k] }
: never
export function zip<E extends Iterable<any>[]>(
...args: E
): Iterable<[...Zip<E>, number]>
MIT © Canvas Technologies, Inc.