Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/qpwo/table-to-record
Typescript microlibrary. Convert tables to well-typed records. Compactly store large json as tables.
https://github.com/qpwo/table-to-record
csv json record table typescript
Last synced: 22 days ago
JSON representation
Typescript microlibrary. Convert tables to well-typed records. Compactly store large json as tables.
- Host: GitHub
- URL: https://github.com/qpwo/table-to-record
- Owner: qpwo
- Created: 2022-05-18T21:52:46.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-05-18T22:35:33.000Z (almost 3 years ago)
- Last Synced: 2025-01-02T22:15:24.703Z (about 2 months ago)
- Topics: csv, json, record, table, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/table-to-record
- Size: 4.88 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# table-to-record
Typescript package to convert a table (rectangular array) to a well-typed record (aka object/map/dictionary) so you can concisely store data. (Instead of repeating yourself a million times in an enourmous json.)
```sh
npm i table-to-record
```Usage: `tableToRecord(rows, header, indexToKeyBy)`
## Example
```ts
import { tableToRecord } from 'table-to-record'
const header = ['uid', 'price', 'name', 'is_available'] as const
const rows = [
[888, 2, 'bread', false],
[999, 5, 'milk', true],
] as const
const rec = tableToRecord(rows, header, '0')
// has exact types!
const breadAvailable: true = rec[999].is_available
const _t: false = rec[888].is_availableconsole.log(rec)
/* Result:
{
'888': { uid: 888, price: 2, name: '3', is_available: false },
'999': { uid: 999, price: 5, name: '6', is_available: true },
}
*/
```