Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Table<RowType>

A type-safe data structure for working with tabular data. It provides a fluent syntax to make adding columns and transformations as consise as possible.

Type parameters

  • RowType

Hierarchy

  • Table

Index

Constructors

constructor

  • new Table<RowType>(data: Table<RowType> | RowType[]): Table<RowType>
  • Type parameters

    • RowType

    Parameters

    • data: Table<RowType> | RowType[]

    Returns Table<RowType>

Properties

data

data: RowType[]

Stores the underlying data for the table

Methods

append

  • append(...rows: RowType[]): Table<RowType>
  • Append additional rows to this table

    Parameters

    • Rest ...rows: RowType[]

    Returns Table<RowType>

    a new Table with the appended rows

appendInPlace

  • appendInPlace(...rows: RowType[]): Table<RowType>
  • Append additional rows to this table in place

    Parameters

    • Rest ...rows: RowType[]

    Returns Table<RowType>

    the existing table with the rows appeneded

filterNulls

  • filterNulls(): Table<NonNullable<RowType>>
  • Filters out null and undefined rows from a table

    Returns Table<NonNullable<RowType>>

    a new Table with nulls and undefined filtered out

firstUniqueRowBy

  • firstUniqueRowBy(keyFunc: (row: RowType) => any): Table<RowType>
  • Fetch the first row for each value of keyFunc

    Parameters

    • keyFunc: (row: RowType) => any
        • (row: RowType): any
        • Parameters

          • row: RowType

          Returns any

    Returns Table<RowType>

groupBy

  • groupBy<K>(keyFunc: (row: RowType) => K): Grouping<K, RowType>
  • Group data in the table by the provided keyFunc creating a Grouping object.

    Type parameters

    • K

    Parameters

    • keyFunc: (row: RowType) => K
        • (row: RowType): K
        • Parameters

          • row: RowType

          Returns K

    Returns Grouping<K, RowType>

innerJoin

  • innerJoin<RightRowType, IdType, OutputType>(data: RightRowType[] | Table<RightRowType>, leftId: (row: RowType) => IdType, rightId: (row: RightRowType) => IdType, merge: (left: RowType, right: RightRowType) => OutputType): Table<OutputType>
  • Type parameters

    • RightRowType

    • IdType

    • OutputType

    Parameters

    • data: RightRowType[] | Table<RightRowType>
    • leftId: (row: RowType) => IdType
        • (row: RowType): IdType
        • Parameters

          • row: RowType

          Returns IdType

    • rightId: (row: RightRowType) => IdType
        • (row: RightRowType): IdType
        • Parameters

          • row: RightRowType

          Returns IdType

    • merge: (left: RowType, right: RightRowType) => OutputType
        • (left: RowType, right: RightRowType): OutputType
        • Parameters

          • left: RowType
          • right: RightRowType

          Returns OutputType

    Returns Table<OutputType>

leftJoin

  • leftJoin<RightRowType, IdType, OutputType>(data: RightRowType[] | Table<RightRowType>, leftId: (row: RowType) => IdType, rightId: (row: RightRowType) => IdType, merge: (left: RowType, right?: RightRowType) => OutputType): Table<OutputType>
  • Type parameters

    • RightRowType

    • IdType

    • OutputType

    Parameters

    • data: RightRowType[] | Table<RightRowType>
    • leftId: (row: RowType) => IdType
        • (row: RowType): IdType
        • Parameters

          • row: RowType

          Returns IdType

    • rightId: (row: RightRowType) => IdType
        • (row: RightRowType): IdType
        • Parameters

          • row: RightRowType

          Returns IdType

    • merge: (left: RowType, right?: RightRowType) => OutputType
        • (left: RowType, right?: RightRowType): OutputType
        • Parameters

          • left: RowType
          • Optional right: RightRowType

          Returns OutputType

    Returns Table<OutputType>

outerJoin

  • outerJoin<RightRowType, IdType, OutputType>(data: RightRowType[] | Table<RightRowType>, leftId: (row: RowType) => IdType, rightId: (row: RightRowType) => IdType, merge: (left: undefined | RowType, right: undefined | RightRowType) => OutputType): Table<OutputType>
  • Type parameters

    • RightRowType

    • IdType

    • OutputType

    Parameters

    • data: RightRowType[] | Table<RightRowType>
    • leftId: (row: RowType) => IdType
        • (row: RowType): IdType
        • Parameters

          • row: RowType

          Returns IdType

    • rightId: (row: RightRowType) => IdType
        • (row: RightRowType): IdType
        • Parameters

          • row: RightRowType

          Returns IdType

    • merge: (left: undefined | RowType, right: undefined | RightRowType) => OutputType
        • (left: undefined | RowType, right: undefined | RightRowType): OutputType
        • Parameters

          • left: undefined | RowType
          • right: undefined | RightRowType

          Returns OutputType

    Returns Table<OutputType>

renameColumn

  • renameColumn<OldColName, NewColName>(oldName: OldColName, newName: NewColName): Table<Omit<RowType & Record<NewColName, RowType[OldColName]>, OldColName>>
  • Renames a column

    Type parameters

    • OldColName: string | number | symbol

    • NewColName: string

    Parameters

    • oldName: OldColName
    • newName: NewColName

    Returns Table<Omit<RowType & Record<NewColName, RowType[OldColName]>, OldColName>>

    a new Table with the column renamed

rightJoin

  • rightJoin<RightRowType, IdType, OutputType>(data: RightRowType[] | Table<RightRowType>, leftId: (row: RowType) => IdType, rightId: (row: RightRowType) => IdType, merge: (left: undefined | RowType, right: RightRowType) => OutputType): Table<OutputType>
  • Type parameters

    • RightRowType

    • IdType

    • OutputType

    Parameters

    • data: RightRowType[] | Table<RightRowType>
    • leftId: (row: RowType) => IdType
        • (row: RowType): IdType
        • Parameters

          • row: RowType

          Returns IdType

    • rightId: (row: RightRowType) => IdType
        • (row: RightRowType): IdType
        • Parameters

          • row: RightRowType

          Returns IdType

    • merge: (left: undefined | RowType, right: RightRowType) => OutputType
        • (left: undefined | RowType, right: RightRowType): OutputType
        • Parameters

          • left: undefined | RowType
          • right: RightRowType

          Returns OutputType

    Returns Table<OutputType>

sideEffect

  • sideEffect(func: (data: RowType[]) => void): Table<RowType>
  • Performs a side-effect function with the data. This is useful for recording something about intermediate state without breaking out of the type-safe builder pattern.

    Parameters

    • func: (data: RowType[]) => void
        • (data: RowType[]): void
        • Parameters

          • data: RowType[]

          Returns void

    Returns Table<RowType>

toMultiMap

  • toMultiMap<K>(keyFunc: (row: RowType) => K): Map<K, RowType[]>
  • Type parameters

    • K

    Parameters

    • keyFunc: (row: RowType) => K
        • (row: RowType): K
        • Parameters

          • row: RowType

          Returns K

    Returns Map<K, RowType[]>

toSingleMap

  • toSingleMap<K>(keyFunc: (row: RowType) => K): Map<K, RowType>
  • Type parameters

    • K

    Parameters

    • keyFunc: (row: RowType) => K
        • (row: RowType): K
        • Parameters

          • row: RowType

          Returns K

    Returns Map<K, RowType>

transform

  • transform<OutRowType>(func: (row: RowType) => OutRowType): Table<OutRowType>
  • Transforms a table row-by-row, producing a new Table of the output

    Type parameters

    • OutRowType

    Parameters

    • func: (row: RowType) => OutRowType
        • (row: RowType): OutRowType
        • Parameters

          • row: RowType

          Returns OutRowType

    Returns Table<OutRowType>

transformAsync

  • transformAsync<OutRowType>(func: (row: RowType) => Promise<OutRowType>, concurrency?: number): Promise<Table<OutRowType>>
  • Transforms a table row-by-row asynchronously, producing a new Table of the output

    Type parameters

    • OutRowType

    Parameters

    • func: (row: RowType) => Promise<OutRowType>
        • (row: RowType): Promise<OutRowType>
        • Parameters

          • row: RowType

          Returns Promise<OutRowType>

    • concurrency: number = 10

    Returns Promise<Table<OutRowType>>

transformBatchAsync

  • transformBatchAsync<OutRowType>(func: (row: RowType[]) => Promise<OutRowType[]>, batchSize?: number, concurrency?: number): Promise<Table<OutRowType>>
  • Transforms a table in batches asyncrhonously, producing a new Table of the output

    Type parameters

    • OutRowType

    Parameters

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

          • row: RowType[]

          Returns Promise<OutRowType[]>

    • batchSize: number = 20
    • concurrency: number = 5

    Returns Promise<Table<OutRowType>>

where

  • where(condition: (row: RowType) => boolean): Table<RowType>
  • Filter a table to rows matching the specified condition

    Parameters

    • condition: (row: RowType) => boolean
        • (row: RowType): boolean
        • Parameters

          • row: RowType

          Returns boolean

    Returns Table<RowType>

withAsyncColumn

  • withAsyncColumn<ColName, ColType>(column: ColName, func: (row: RowType) => Promise<ColType>, concurrency?: number): Promise<Table<RowType & Record<ColName, ColType>>>
  • Like {@link Table#addColumn}, but async

    Type parameters

    • ColName: string

    • ColType

    Parameters

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

          • row: RowType

          Returns Promise<ColType>

    • Optional concurrency: number

      max number of Promises running at any one time

    Returns Promise<Table<RowType & Record<ColName, ColType>>>

withColumn

  • withColumn<ColName, ColType>(column: ColName, func: (row: RowType) => ColType): Table<RowType & Record<ColName, ColType>>
  • Adds a new calculated column to the table

    Type parameters

    • ColName: string

    • ColType

    Parameters

    • column: ColName

      the name of the column

    • func: (row: RowType) => ColType

      the function to compute the column

        • (row: RowType): ColType
        • Parameters

          • row: RowType

          Returns ColType

    Returns Table<RowType & Record<ColName, ColType>>

    A new table with the provided column

withoutColumn

  • withoutColumn<ColName>(column: ColName, inplace?: boolean): Table<Omit<RowType, ColName>>
  • Deletes the specified column from the Table

    Type parameters

    • ColName: string | number | symbol

    Parameters

    • column: ColName

      the name of the column to delete

    • Optional inplace: boolean

      whether to modify the rows inplace or make a copy

    Returns Table<Omit<RowType, ColName>>

    a new Table without the specified column

Static fromMap

  • fromMap<KeyType, MapRowType>(map: Map<KeyType, MapRowType>): Table<MapRowType & { id: KeyType }>
  • Type parameters

    • KeyType

    • MapRowType

    Parameters

    • map: Map<KeyType, MapRowType>

    Returns Table<MapRowType & { id: KeyType }>

Generated using TypeDoc