Options
All
  • Public
  • Public/Protected
  • All
Menu

General utilities, without runtime dependencies on other parts of the system.

Index

Variables

Const Heap

Heap: typeof Heap = ...

Functions

Const Throw

  • Throw(s: string | Error): never
  • Function that throws its argument.

    Parameters

    • s: string | Error

      a string or an Error.

    Returns never

asBoolean

  • asBoolean(a: any): boolean

asMonetary

asObject

  • asObject(a: any): {}

Const assertNever

  • assertNever(x: never, msg?: string): never
  • Assert that the call in the argument cannot return.

    Parameters

    • x: never
    • msg: string = ...

    Returns never

Const assertRow

  • assertRow<T>(row: RowType<"incomeStream" | "person" | "scenario" | "asset" | "liability" | "income" | "expense" | "incomeTax" | "text">, type: T): RowType<T>
  • Check that the supplied {@link Row} is of the desired Type, returning it as that type, or throwing an exception if it is not.

    Type parameters

    • T: "incomeStream" | "person" | "scenario" | "asset" | "liability" | "income" | "expense" | "incomeTax" | "text"

    Parameters

    • row: RowType<"incomeStream" | "person" | "scenario" | "asset" | "liability" | "income" | "expense" | "incomeTax" | "text">

      The {@link Row} to check

    • type: T

    Returns RowType<T>

Const checkRow

  • checkRow<T>(row: RowType<"incomeStream" | "person" | "scenario" | "asset" | "liability" | "income" | "expense" | "incomeTax" | "text">, type: T): row is RowType<T>
  • Check that the supplied {@link Row} is of the specified Type

    Type parameters

    • T: "incomeStream" | "person" | "scenario" | "asset" | "liability" | "income" | "expense" | "incomeTax" | "text"

    Parameters

    • row: RowType<"incomeStream" | "person" | "scenario" | "asset" | "liability" | "income" | "expense" | "incomeTax" | "text">

      The {@link Row} to check

    • type: T

      the Type the row should be.

    Returns row is RowType<T>

Const classChecks

  • classChecks<T>(cls: new (...args: any[]) => T, coerce?: (a: any) => T): [(a: any) => a is T, (a: any) => T, (a: any) => T]
  • Construct a family of type functions: a type guard, a coersion, and a checked cast.

    • The type guard ("is") tests membership and lets the compiler know the type. Same as an instanceof check, but can be passed as a function.
    • The coercion ("to") checks to see if it is already of the type. If not, and a coercion function was supplied, the suplied coercion function will be applied, and the test retried with a checked cast.
    • The checked cast ("as") checks the object, returning it as being the right type, or throwing an exception if not.

    Type parameters

    • T

    Parameters

    • cls: new (...args: any[]) => T

      A class constructor

        • new (...args: any[]): T
        • Parameters

          • Rest ...args: any[]

          Returns T

    • Optional coerce: (a: any) => T

      an optional coercion function to be tried in the to* (coercion) variant

        • (a: any): T
        • Parameters

          • a: any

          Returns T

    Returns [(a: any) => a is T, (a: any) => T, (a: any) => T]

Const fmt_pct

  • fmt_pct(d: number, frac?: 0 | 1 | 3 | 2 | 4): string
  • Format a number as a percentage.

    Parameters

    • d: number

      Format a number as

    • frac: 0 | 1 | 3 | 2 | 4 = 3

      0 or 2 (default = 2) positions for cents

    Returns string

Const fmt_usd

  • fmt_usd(d: number, frac?: number): string
  • Format a number as US currency.

    Parameters

    • d: number

      a number as US currency

    • frac: number = ...

      0 or 2 (default = 2) positions for cents

    Returns string

Const heapgen

  • Given a Heap, give a generator to the (sorted) values in the heap.

    Type parameters

    • T

    Parameters

    • heap: Heap<T>

    Returns EnhancedGenerator<T, void, unknown>

Const identity

  • identity<T>(a: T): T
  • Simple type-aware identity function.

    Type parameters

    • T

    Parameters

    • a: T

    Returns T

    a

Const indexByName

  • Produce an index to a list of {@link Named objects.

    Type parameters

    Parameters

    • list: T[]

      A list of Named objects

    Returns NamedIndex<T>

    An index of the objects by name.

Const isBoolean

  • isBoolean(a: any): a is boolean

Const isFunction

  • isFunction(f: any): f is Function

Const isMonetary

Const isObject

  • isObject(o: any): o is {}

Const makeSummer

  • makeSummer<T, V>(f: (item: T) => V, v?: (n: V) => V): (l: T[]) => V
  • Higher-order function, that creates summing functions.

    Type parameters

    • T

    • V: number

    Parameters

    • f: (item: T) => V

      a function that takes an item and returns a number.

        • (item: T): V
        • Parameters

          • item: T

          Returns V

    • Optional v: (n: V) => V

      a function that validates that the result is of type V.

        • (n: V): V
        • Parameters

          • n: V

          Returns V

    Returns (l: T[]) => V

    a function that takes a list of items and returns the sum of the values returned by applying f.

      • (l: T[]): V
      • Parameters

        • l: T[]

        Returns V

Const monetaryValue

toBoolean

  • toBoolean(a: any): boolean

toMonetary

toObject

  • toObject(a: any): {}

Const total

Const typeChecks

  • typeChecks<T>(is: (a: any) => a is T, isNot: string, coerce?: (a: any) => undefined | T): [(a: any) => T, (a: any) => T]
  • Construct a family of type functions: a type guard, a coersion, and a checked cast.

    • The type guard ("is") tests membership and lets the compiler know the type. Same as an instanceof check, but can be passed as a function.
    • The coercion ("to") checks to see if it is already of the type. If not, and a coercion function was supplied, the suplied coercion function will be applied, and the test retried with a checked cast.
    • The checked cast ("as") checks the object, returning it as being the right type, or throwing an exception if not.

    Type parameters

    • T

    Parameters

    • is: (a: any) => a is T

      A type guard.

        • (a: any): a is T
        • Parameters

          • a: any

          Returns a is T

    • isNot: string

      A string for error messages, when the type guard fails

    • Optional coerce: (a: any) => undefined | T

      an optional coercion function to be tried in the to* (coercion) variant

        • (a: any): undefined | T
        • Parameters

          • a: any

          Returns undefined | T

    Returns [(a: any) => T, (a: any) => T]

Const uniq

  • uniq<T>(l: T[]): T[]
  • Returns the unique values, as compared by ===

    Type parameters

    • T

    Parameters

    • l: T[]

      a list of strings or other values to be compared by ===

    Returns T[]

Generated using TypeDoc