@cucumber/node
    Preparing search index...

    Class DataTable

    Represents the cells of a Gherkin data table associated with a test step.

    For steps that include a data table, an instance of this will be injected as the last argument to your step function.

    Index

    Constructors

    • Parameters

      • cells: readonly (readonly string[])[]

      Returns DataTable

    Methods

    • Returns an array, with each item representing a row of the table as key/value pairs using the header row for keys.

      Returns readonly Record<string, string>[]

      const dataTable = new DataTable([
      ['a', 'b', 'c'],
      ['1', '2', '3'],
      ['4', '5', '6'],
      ['7', '8', '9']
      ])
      console.log(dataTable.hashes())
      // [
      // { a: '1', b: '2', c: '3' },
      // { a: '4', b: '5', c: '6' },
      // { a: '7', b: '8', c: '9' }
      // ]
    • Returns an array, with each item being a cell value from the first/only column.

      Returns readonly string[]

      For use with single-column data tables that represent a simple list.

      const dataTable = new DataTable([
      ['foo'],
      ['bar'],
      ['baz']
      ])
      console.log(dataTable.list())
      // ['foo', 'bar', 'baz']

      When not all rows have exactly 1 column

    • Returns a copy of the raw cells, as a two-dimensional array.

      Returns readonly (readonly string[])[]

      const dataTable = new DataTable([
      ['a', 'b', 'c'],
      ['1', '2', '3'],
      ['4', '5', '6']
      ])
      console.log(dataTable.raw())
      // [['a', 'b', 'c'], ['1', '2', '3'], ['4', '5', '6']]
    • Returns a copy of the raw cells, as a two-dimensional array, with the first (header) row omitted.

      Returns readonly (readonly string[])[]

      const dataTable = new DataTable([
      ['a', 'b', 'c'],
      ['1', '2', '3'],
      ['4', '5', '6']
      ])
      console.log(dataTable.rows())
      // [['1', '2', '3'], ['4', '5', '6']]
    • Returns key/value pairs with keys from the first column and values from the second.

      Returns Record<string, string>

      For use with two-column data tables that represent key/value pairs.

      const dataTable = new DataTable([
      ['Tom', '1'],
      ['Dick', '2'],
      ['Sally', '3']
      ])
      console.log(dataTable.rowsHash())
      // { Tom: '1', Dick: '2', Sally: '3' }

      When not all rows have exactly 2 columns

    • Returns a fresh data table instance based on the cells being transposed.

      Returns DataTable

      const dataTable = new DataTable([
      ['a', 'b', 'c'],
      ['1', '2', '3']
      ])
      console.log(dataTable.transpose().raw())
      // [['a', '1'], ['b', '2'], ['c', '3']]