1.0.0 • Published 8 months ago

@canvas-js/utils v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

@canvas-js/utils

standard-readme compliant license NPM version TypeScript types

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 condition

Awaitable

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): JSType

deepEqual

export function deepEqual(a: JSValue, b: JSValue): boolean

mapEntries

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): JSValue

stripUndefined

/** Recursively remove every object entry with value `undefined` */
export function stripUndefined(value: JSValue, inPlace = false): JSValue

signalInvalidType

export function signalInvalidType(type: never): never

zip

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.

1.0.0

8 months ago

0.12.3-next.4

1 year ago

0.12.3-next.3

1 year ago

0.14.0-next.0

10 months ago

0.12.3-next.2

1 year ago

0.13.0-next.17

1 year ago

0.13.6

12 months ago

0.13.7

12 months ago

0.13.9

11 months ago

0.13.0

12 months ago

0.13.1

12 months ago

0.13.2

12 months ago

0.13.3

12 months ago

0.13.5

12 months ago

0.13.8-next.0

12 months ago

0.13.8-next.1

11 months ago

0.13.4-next.0

12 months ago

0.13.12

10 months ago

0.13.11

10 months ago

0.13.10

11 months ago

0.14.0-next.1

10 months ago

0.13.14

10 months ago

0.13.13

10 months ago

0.12.2

1 year ago

0.12.3

1 year ago

0.12.4

1 year ago

0.12.5

1 year ago

0.12.6

12 months ago

0.12.3-next.1

1 year ago

0.12.3-next.0

1 year ago

0.13.0-next.16

1 year ago

0.13.0-next.15

1 year ago

0.13.0-next.14

1 year ago

0.13.0-next.13

1 year ago

0.12.1

1 year ago

0.13.0-next.12

1 year ago

0.13.0-next.11

1 year ago

0.13.0-next.10

1 year ago

0.13.0-next.9

1 year ago

0.13.0-next.8

1 year ago

0.11.0

1 year ago

0.12.0

1 year ago

0.13.0-next.1

1 year ago

0.13.0-next.3

1 year ago

0.13.0-next.2

1 year ago

0.13.0-next.5

1 year ago

0.13.0-next.4

1 year ago

0.13.0-next.7

1 year ago

0.13.0-next.6

1 year ago

0.10.10

1 year ago

0.10.0

1 year ago

0.10.0-alpha.1

2 years ago

0.10.9

1 year ago

0.10.1

1 year ago

0.10.0-beta.2

1 year ago

0.10.2

1 year ago

0.10.0-beta.3

1 year ago

0.10.3

1 year ago

0.10.4

1 year ago

0.10.0-beta.1

2 years ago

0.10.5

1 year ago

0.10.6

1 year ago

0.10.7

1 year ago

0.10.0-beta.4

1 year ago

0.10.8

1 year ago

0.9.1

2 years ago

0.9.0

2 years ago

0.9.0-next.1

2 years ago