Options
All
  • Public
  • Public/Protected
  • All
Menu

typed-data-table

Index

Type aliases

AggregationFuncMap

AggregationFuncMap<T>: {}

Type parameters

  • T

Type declaration

  • [K: string]: (args: T[]) => any
      • (args: T[]): any
      • Parameters

        • args: T[]

        Returns any

JoinDataArgs

JoinDataArgs<LeftRowType, RightRowType, IdType, OutputType>: { leftData: LeftRowType[]; rightData: RightRowType[]; leftId: any; rightId: any } & ({ joinType: "inner"; merge: any } | { joinType: "left"; merge: any } | { joinType: "right"; merge: any } | { joinType: "outer"; merge: any })

Type parameters

  • LeftRowType

  • RightRowType

  • IdType

  • OutputType

Functions

addColumn

  • addColumn<RowType, ColName, ColType>(data: RowType[], column: ColName, func: (row: RowType) => ColType): (RowType & Record<ColName, ColType>)[]
  • Adds a new top-level field to all objects in the provided data list updating the output type appropriately to contain the newly provided field. Though named addColumn, this can be used for arbitrary object transformation.

    Type parameters

    • RowType

    • ColName: string

    • ColType

    Parameters

    • data: RowType[]

      The list of input objects

    • column: ColName

      the name of the column field to add

    • func: (row: RowType) => ColType

      the function which, given an object, produces the value for the new column

        • (row: RowType): ColType
        • Parameters

          • row: RowType

          Returns ColType

    Returns (RowType & Record<ColName, ColType>)[]

    A new list of objects that contain the newly calcualted column field

addColumnAsync

  • addColumnAsync<RowType, ColName, ColType>(data: RowType[], column: ColName, func: (row: RowType) => Promise<ColType>, concurrency?: number): Promise<(RowType & Record<ColName, ColType>)[]>
  • Identical to addColumn, but calculates the new column asynchronously.

    Type parameters

    • RowType

    • ColName: string

    • ColType

    Parameters

    • data: RowType[]

      The list of input objects

    • column: ColName

      the name of the column field to add

    • func: (row: RowType) => Promise<ColType>

      the function which, given an object, returns a Promise for the value for the new column

        • (row: RowType): Promise<ColType>
        • Parameters

          • row: RowType

          Returns Promise<ColType>

    • concurrency: number = 10

      the max number of Promises to issue at once

    Returns Promise<(RowType & Record<ColName, ColType>)[]>

    A Promise for a new list of objects that contain the newly calcualted column field

aggregate

  • aggregate<KeyType, RowType, AggregatedType>(data: Map<KeyType, RowType[]>, aggFunc: (rows: RowType[]) => AggregatedType): Map<KeyType, AggregatedType>
  • Aggregates a MultiMap as produced by makeMultiMap using aggFunc over every value list to produce a new transformed Map

    Type parameters

    • KeyType

    • RowType

    • AggregatedType

    Parameters

    • data: Map<KeyType, RowType[]>

      The input MultiMap

    • aggFunc: (rows: RowType[]) => AggregatedType

      A function aggregate a list of MultiMap values into a new aggregated type

        • (rows: RowType[]): AggregatedType
        • Parameters

          • rows: RowType[]

          Returns AggregatedType

    Returns Map<KeyType, AggregatedType>

    The aggregated Map from data KeyType to aggFunc output type

aggregateByColumn

  • aggregateByColumn<KeyType, RowType, AggFuncsMapType>(data: Map<KeyType, RowType[]>, aggregations: AggFuncsMapType): Map<KeyType, ExtractObjectFuncResults<AggFuncsMapType>>
  • Aggregates a MultiMap as produced by makeMultiMap across multiple fields at once

    Type parameters

    Parameters

    • data: Map<KeyType, RowType[]>

      The data

    • aggregations: AggFuncsMapType

      an object of column => aggregation function for a list of values from that column

    Returns Map<KeyType, ExtractObjectFuncResults<AggFuncsMapType>>

    A Multimap with the same keys and the outputs for each column in aggregations

deleteColumn

  • deleteColumn<RowType, ColName>(data: RowType[], column: ColName, inplace?: boolean): Omit<RowType, ColName>[]
  • Deletes a field from a list of objects of RowType, updating the result type appropriately.

    Type parameters

    • RowType

    • ColName: string | number | symbol

    Parameters

    • data: RowType[]

      The list of input objects

    • column: ColName

      The name of the field to remove

    • Optional inplace: boolean

      Whether to modify the rows inplace or copy first

    Returns Omit<RowType, ColName>[]

    A new list of objects without the provided field

filterNulls

  • filterNulls<T>(data: T[]): NonNullable<T>[]
  • Filters out null and undefined values from a list, typing the result so typescript knows the output is NonNullable

    Type parameters

    • T

    Parameters

    • data: T[]

    Returns NonNullable<T>[]

firstUniqueRowBy

  • firstUniqueRowBy<RowType>(data: RowType[], keyFunc: (row: RowType) => any): RowType[]
  • Iterates through the provided data and selects the first element that matches each key

    Type parameters

    • RowType

    Parameters

    • data: RowType[]

      a list of objects to process

    • keyFunc: (row: RowType) => any

      a function for computed each object's key

        • (row: RowType): any
        • Parameters

          • row: RowType

          Returns any

    Returns RowType[]

    a new list with only the first element matching each key

joinData

  • joinData<LeftRowType, RightRowType, IdType, OutputType>(args: JoinDataArgs<LeftRowType, RightRowType, IdType, OutputType>): OutputType[]
  • Joins two lists of objects together on an id field extracted via the provided leftId and rightId arguments. This supports inner, left, right, and outer joins via the joinType arg. You must provide a merge function which takes the left and right row as input and returns the newly merged row.

    Type parameters

    • LeftRowType

    • RightRowType

    • IdType

    • OutputType

    Parameters

    • args: JoinDataArgs<LeftRowType, RightRowType, IdType, OutputType>

    Returns OutputType[]

makeMultiMap

  • makeMultiMap<Row, Key, OutRow>(data: Row[], keyFunc: (row: Row) => Key, valueFunc?: (row: Row) => OutRow): Map<Key, OutRow[]>
  • Groups a list of objects into an Map keyed by the provided keyFunc with values being sub-lists of the input data.

    Type parameters

    • Row

    • Key

    • OutRow = Row

    Parameters

    • data: Row[]

      The list of objects to transform

    • keyFunc: (row: Row) => Key

      The function to use to extract the keys for the output Map

        • (row: Row): Key
        • Parameters

          • row: Row

          Returns Key

    • Optional valueFunc: (row: Row) => OutRow

      (Optional) a value function to transform the objects for the value list

        • (row: Row): OutRow
        • Parameters

          • row: Row

          Returns OutRow

    Returns Map<Key, OutRow[]>

    a Map from key to list of objects

makeSingleMap

  • makeSingleMap<Row, Key, OutRow>(data: Row[], keyFunc: (row: Row) => Key, valueFunc?: (row: Row) => OutRow, valueComparer?: (rowOne: OutRow, rowTwo: OutRow) => number): Map<Key, OutRow>
  • Transforms a list of objects into a Map of key to object. By default this will select the first object in the list for each unique key, unless valueComparer is provided.

    Type parameters

    • Row

    • Key

    • OutRow = Row

    Parameters

    • data: Row[]

      The list of objects to transform

    • keyFunc: (row: Row) => Key

      Function for extracting the key for the Map

        • (row: Row): Key
        • Parameters

          • row: Row

          Returns Key

    • Optional valueFunc: (row: Row) => OutRow

      (Optional) a function to transform the Map values

        • (row: Row): OutRow
        • Parameters

          • row: Row

          Returns OutRow

    • Optional valueComparer: (rowOne: OutRow, rowTwo: OutRow) => number

      (Optional) a comparer to use to select the best object for each matching key. Should return a value > 0 if the first arg is better to keep over the second.

        • (rowOne: OutRow, rowTwo: OutRow): number
        • Parameters

          • rowOne: OutRow
          • rowTwo: OutRow

          Returns number

    Returns Map<Key, OutRow>

    a Map from key to object, picking the best or first object in the data list for each unique key

Const max

  • max(items: number[]): number

Const maxIndex

  • maxIndex(items: number[]): null | number
  • Finds the first index of the minimum value in the provide numeric list

    Parameters

    • items: number[]

    Returns null | number

Const mean

  • mean(items: number[]): number

Const min

  • min(items: number[]): number

Const minIndex

  • minIndex(items: number[]): null | number
  • Finds the first index of the minimum value in the provide numeric list

    Parameters

    • items: number[]

    Returns null | number

Const product

  • product(items: number[]): number

Const standardDeviation

  • standardDeviation(items: number[]): number

Const sum

  • sum(items: number[]): number

transformAsync

  • transformAsync<InRowType, OutRowType>(data: InRowType[], func: (row: InRowType) => Promise<OutRowType>, concurrency?: number): Promise<OutRowType[]>
  • Transforms data one at a time from InRowType to OutRowType asynchronously. This implementation uses an ES6 promise pool to issue concurrent promises up to the specified concurrency limit. This is useful when issuing external service calls.

    Type parameters

    • InRowType

    • OutRowType

    Parameters

    • data: InRowType[]

      a list of data elements to transform

    • func: (row: InRowType) => Promise<OutRowType>

      the (async) transformation function

        • (row: InRowType): Promise<OutRowType>
        • Parameters

          • row: InRowType

          Returns Promise<OutRowType>

    • concurrency: number = 10

      the max number of promises to issue at one time (default 10)

    Returns Promise<OutRowType[]>

    a list of transformed elements

transformBatchAsync

  • transformBatchAsync<InRowType, OutRowType>(data: InRowType[], func: (row: InRowType[]) => Promise<OutRowType[]>, batchSize?: number, concurrency?: number): Promise<OutRowType[]>
  • Transforms data in batches from InRowType to OutRowType asynchronously. The provided transformation function takes in a single batch (list of inputs) and should return a list of transformed outputs. This implementation uses an ES6 promise pool to issue concurrent promises up to the specified concurrency limit. This is useful when issuing external service calls.

    Type parameters

    • InRowType

    • OutRowType

    Parameters

    • data: InRowType[]

      a list of data elements to transform

    • func: (row: InRowType[]) => Promise<OutRowType[]>

      the (async) transformation function

        • (row: InRowType[]): Promise<OutRowType[]>
        • Parameters

          • row: InRowType[]

          Returns Promise<OutRowType[]>

    • batchSize: number = 20

      the size of each batch

    • concurrency: number = 5

      the max number of promises to issue at one time (default 5)

    Returns Promise<OutRowType[]>

    a list of transformed elements

Const variance

  • variance(items: number[]): number

Generated using TypeDoc