diff --git a/index.ts b/index.ts index 823d58d..06ea916 100644 --- a/index.ts +++ b/index.ts @@ -1,17 +1,19 @@ +import {notNull} from "@softwareventures/nullable"; + export type Table = string[][]; export type ReadonlyTable = ReadonlyArray>; export function* tableToRecords(table: ReadonlyTable): Iterable> { - const header = table[0]; + const header = notNull(table[0]); for (let i = 1; i < table.length; ++i) { - const row = table[i]; + const row = notNull(table[i]); const record: Record = {}; for (let j = 0; j < row.length && j < header.length; ++j) { - const name = header[j]; - record[name] = row[j]; + const name = notNull(header[j]); + record[name] = notNull(row[j]); } yield record; @@ -23,14 +25,14 @@ export function recordsToTable(records: ReadonlyArray headers .map(header => { if (header in record) { - return record[header]; + return notNull(record[header]); } else { throw new Error("Inconsistent records."); } diff --git a/package.json b/package.json index 33f90a3..b5c87b4 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "node": "^14 || ^16 || >=18" }, "dependencies": { + "@softwareventures/nullable": "^3.0.0", "tslib": "^1.9.3 || ^2.0.0 || ^2.1.0" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 005696e..2f43729 100644 --- a/yarn.lock +++ b/yarn.lock @@ -481,6 +481,13 @@ lodash "^4.17.4" read-pkg-up "^7.0.0" +"@softwareventures/nullable@^3.0.0": + version "3.0.0" + resolved "https://registry.yarnpkg.com/@softwareventures/nullable/-/nullable-3.0.0.tgz#979045c99e7c8a9055cb25c3c5cb5b9edfc50085" + integrity sha512-kgYOGJHzgZl0QGqMqbRe34i5VaRQUsG+X9AcblJL1lGDq+npLsCS974VSJmOBxnSqIQ5dcgah+zBxHndH8qzfg== + dependencies: + tslib "2.4.0" + "@softwareventures/semantic-release-config@3.0.0": version "3.0.0" resolved "https://registry.yarnpkg.com/@softwareventures/semantic-release-config/-/semantic-release-config-3.0.0.tgz#11bc1edbe4de1cd37a79dcf050d5be6e8467ada0"