@canvas-js/utils
TypeScript icon, indicating that this package has built-in type declarations

0.10.0-beta.1 • Public • Published

@canvas-js/utils

API

assert

export function assert(condition: unknown, message?: string): asserts condition {
  if (!condition) {
    throw new Error(message ?? "assertion failed")
  }
}

signalInvalidType

export function signalInvalidType(type: never): never {
  console.error(type)
  throw new TypeError("internal error: invalid type")
}

mapEntries

export const mapEntries = <K extends string, S, T>(object: Record<K, S>, map: (entry: [key: K, value: S]) => T) =>
  Object.fromEntries(Object.entries<S>(object).map(([key, value]) => [key, map([key as K, value])])) as Record<K, T>

mapKeys

export const mapKeys = <K extends string, S, T>(object: Record<K, S>, map: (key: K) => T) =>
  Object.fromEntries(Object.entries<S>(object).map(([key, value]) => [key, map(key as K)])) as Record<K, T>

mapValues

export const mapValues = <K extends string, S, T>(object: Record<K, S>, map: (value: S) => T) =>
  Object.fromEntries(Object.entries<S>(object).map(([key, value]) => [key, map(value)])) as Record<K, T>

/@canvas-js/utils/

    Package Sidebar

    Install

    npm i @canvas-js/utils

    Weekly Downloads

    190

    Version

    0.10.0-beta.1

    License

    none

    Unpacked Size

    3.75 kB

    Total Files

    16

    Last publish

    Collaborators

    • rjwebb
    • joelg
    • raykyri