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 = ...

Const Sort

Sort: { byRate: <T, I>(a: I, b: I) => 1 | 0 | -1; byValue: <T, I>(a: I, b: I) => 1 | 0 | -1 } = ...

Collection of sort functions.

Type declaration

  • byRate: <T, I>(a: I, b: I) => 1 | 0 | -1
  • byValue: <T, I>(a: I, b: I) => 1 | 0 | -1

Const comparator

comparator: typeof comparator = ...

Functions

Const Throw

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

    Parameters

    • s: string | Error

      a string or an Error.

    Returns never

asMonetary

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<"scenario" | "incomeStream" | "asset" | "liability" | "income" | "expense" | "incomeTax" | "person" | "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: "scenario" | "incomeStream" | "asset" | "liability" | "income" | "expense" | "incomeTax" | "person" | "text"

    Parameters

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

      The {@link Row} to check

    • type: T

    Returns RowType<T>

Const checkRow

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

    Type parameters

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

    Parameters

    • row: RowType<"scenario" | "incomeStream" | "asset" | "liability" | "income" | "expense" | "incomeTax" | "person" | "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_usd

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

    Parameters

    • d: number

      Format 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 isFunction

  • isFunction(f: any): f is Function

Const isMonetary

Const makeSort

  • makeSort<T>(cmp?: SortFn<T>): <I>(l: Iterable<I>) => I[]
  • A higher-order function that returs a sort function.

    Type parameters

    • T

    Parameters

    • cmp: SortFn<T> = ...

      a comparator

    Returns <I>(l: Iterable<I>) => I[]

    a sort function that sorts a list according to cmp

      • <I>(l: Iterable<I>): I[]
      • Type parameters

        • I

        Parameters

        • l: Iterable<I>

        Returns I[]

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

Const naturalCMP

  • naturalCMP<T>(a: T, b: T): 0 | 1 | -1
  • A comparator that sorts according to the "natural" order. First by type, then by string or numerical ordering if a string, number, boolean, or symbol.

    Type parameters

    • T

    Parameters

    • a: T
    • b: T

    Returns 0 | 1 | -1

Const naturalSort

  • naturalSort<I>(l: Iterable<I>): I[]
  • A function that sorts according to natural order. See naturalCMP.

    Type parameters

    • I: unknown

    Parameters

    • l: Iterable<I>

    Returns I[]

    a copy of list in sorted order.

Const nullCMP

  • nullCMP<T>(a: T, b: T): 0 | 1 | -1
  • A comparator that does not alter the sort order. It regards everything as equal, and thus Javascript's stable sort leaves the ordering unchanged.

    Type parameters

    • T

    Parameters

    • a: T
    • b: T

    Returns 0 | 1 | -1

    0

Const row

  • row(...args: any[]): string
  • Format a row of values in a Markdown table.

    Parameters

    • Rest ...args: any[]

      Array of values for the cells in the row

    Returns string

    a markdown-formatted string

toMonetary

Const total

Const typeChecks

  • typeChecks<T>(is: (a: any) => a is T, isNot: string, coerce?: (a: any) => 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) => T

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

        • (a: any): T
        • Parameters

          • a: any

          Returns 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