from

Validates an unknown value as a sheet and returns a key-ascending shallow clone.

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

// The boundary for external input: validate, then clone.
Sheet.from({ "2025": [1, 2], "2024": [3] });
// { "2024": [3], "2025": [1, 2] }  (keys ascending)

// Outer object and each row are new; cell references are preserved.
const cell = { v: 1 };
Sheet.from({ a: [cell] }).a[0] === cell; // true

// Non-sheet input throws.
Sheet.from(new Map()); // throws SheetError "SHEET_INVALID_SHEET"

// An empty object is a valid (empty) sheet.
Sheet.from({}); // {}

API Reference

Signature

Sheet.from<T = unknown, TKey extends string = string>(
  value: unknown,
): Sheet<T, TKey>;

Parameters

ParameterTypeRequiredNotes
valueunknownYesMust be a plain object whose own enumerable string keys all map to dense arrays.

Returns

A new sheet with keys ascending and each row copied. Cell values are not deep-copied. Symbol keys and non-enumerable properties are dropped.

Throws

  • SHEET_INVALID_SHEET — value is not a plain object, a row is not an array, a row is sparse, or input is an array / function / Date / Map / Set / class instance.

Agent Contract

FieldValue
Kindstatic helper
Canonical namefrom
AliasesNone
Mutates inputsNo
ReturnsSheet<T, TKey>

Agent Notes

  • Use from at the boundary of unknown/external data; for copying a value you already know is a sheet, use clone.
  • For a non-cloning check or assertion, use isSheet / assertSheet.
  • Represent missing cells as explicit undefined; sparse arrays are rejected.