transpose

Turns rows into columns, reading input rows in ascending key order.

import { Sheet } from "@teakit/sheet";

// Default output keys are the string indices "0", "1", ...
Sheet.transpose({ a: [1, 2], b: [3, 4] });
// { "0": [1, 3], "1": [2, 4] }

// keys[index] labels each input column. Input rows are read ascending
// (cost before revenue), so each column lists [cost, revenue].
Sheet.transpose({ revenue: [100, 120], cost: [60] }, { keys: ["2024-01", "2024-02"] });
// { "2024-01": [60, 100], "2024-02": [undefined, 120] }

// "-" is preserved, not skipped; missing positions use fill.
Sheet.transpose({ a: [1, 2], b: [3] }, { fill: 0 });
// { "0": [1, 3], "1": [2, 0] }

API Reference

Signature

Sheet.transpose<T, TInputKey extends string, TOutputKey extends string, TFill>(
  sheet: Sheet<T, TInputKey>,
  options?: SheetTransposeOptions<TOutputKey, TFill>,
): Sheet<T | TFill | undefined, TOutputKey>;

Parameters

ParameterTypeRequiredNotes
options.keysreadonly string[]NoLabels for input columns by index. No duplicates; must cover every column (at least the max input row length).
options.fillTFillNoValue for missing positions. Defaults to undefined.

Returns

A sheet whose keys are the column labels (ascending) and whose rows hold each original key's value at that column, in ascending input-key order. "-" is preserved.

Throws

  • SHEET_INVALID_TRANSPOSE_OPTIONS — duplicate keys, or fewer keys than the max input row length (which would drop columns).

Agent Contract

FieldValue
Kindstatic structure tool
Canonical nametranspose
AliasesNone
Mutates inputsNo
ReturnsSheet<T | TFill | undefined, TOutputKey>

Agent Notes

  • Input rows are read in ascending key order; if you need a specific input key set first, run normalize with keys.
  • transpose does not skip or invent "-".