@canvas-js/utils v1.0.0
@canvas-js/utils
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.
Table of contents
API
assert
export function assert(condition: unknown, message?: string): asserts conditionAwaitable
export type Awaitable<T> = T | Promise<T>JSONValue
export type JSONValue =
| null
| boolean
| number
| string
| JSONArray
| JSONObject
export interface JSONArray extends Array<JSONValue> {}
export interface JSONObject {
[key: string]: JSONValue
}JSValue
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): JSTypedeepEqual
export function deepEqual(a: JSValue, b: JSValue): booleanmapEntries
export function mapEntries<K extends string, S, T>(
object: Record<K, S>,
map: (entry: [key: K, value: S]) => T,
): Record<K, T>mapKeys
export function mapKeys<K extends string, S, T>(
object: Record<K, S>,
map: (key: K) => T,
): Record<K, T>mapValues
export function mapValues<K extends string, S, T>(
object: Record<K, S>,
map: (value: S) => T,
): Record<K, T>replaceUndefined
/** Recursively replace every `undefined` with `null` in ararys and objects */
export function replaceUndefined(value: JSValue, inPlace = false): JSValuestripUndefined
/** Recursively remove every object entry with value `undefined` */
export function stripUndefined(value: JSValue, inPlace = false): JSValuesignalInvalidType
export function signalInvalidType(type: never): neverzip
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]>License
MIT © Canvas Technologies, Inc.
8 months ago
1 year ago
1 year ago
10 months ago
1 year ago
1 year ago
12 months ago
12 months ago
11 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
11 months ago
12 months ago
10 months ago
10 months ago
11 months ago
10 months ago
10 months ago
10 months ago
1 year ago
1 year ago
1 year ago
1 year ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago