{"id":13339458,"url":"https://github.com/tdast/tdast-util-from-array","last_synced_at":"2025-08-11T01:36:38.883Z","repository":{"id":57376576,"uuid":"294295628","full_name":"tdast/tdast-util-from-array","owner":"tdast","description":"tdast utility to transform a JS array into tdast","archived":false,"fork":false,"pushed_at":"2020-09-12T04:35:12.000Z","size":9,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-09T17:18:04.463Z","etag":null,"topics":["ast","csv","tabular-data","tdast","tdast-util","unist","util"],"latest_commit_sha":null,"homepage":"https://github.com/tdast","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tdast.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-09-10T03:45:14.000Z","updated_at":"2020-09-12T04:35:15.000Z","dependencies_parsed_at":"2022-08-29T21:20:35.953Z","dependency_job_id":null,"html_url":"https://github.com/tdast/tdast-util-from-array","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/tdast/tdast-util-from-array","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdast%2Ftdast-util-from-array","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdast%2Ftdast-util-from-array/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdast%2Ftdast-util-from-array/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdast%2Ftdast-util-from-array/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tdast","download_url":"https://codeload.github.com/tdast/tdast-util-from-array/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdast%2Ftdast-util-from-array/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269804863,"owners_count":24477872,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ast","csv","tabular-data","tdast","tdast-util","unist","util"],"created_at":"2024-07-29T19:20:03.546Z","updated_at":"2025-08-11T01:36:38.864Z","avatar_url":"https://github.com/tdast.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tdast-util-from-array\n\n[**tdast**][tdast] utility to transform a JS array into tdast.\n\n---\n\n## Install\n\n```sh\nnpm install tdast-util-from-array\n```\n\n## Use\n\n```js\nimport fromArray from 'tdast-util-from-array';\n\nconst array = [\n  { column1: 1, column2: 'two', column3: 3, column4: null },\n  { column1: null, column2: 'two', column3: 33, column4: 'four' },\n];\n\nexpect(fromArray(array)).toEqual({\n  type: 'table',\n  children: [\n    {\n      type: 'row',\n      index: 0,\n      children: [\n        {\n          type: 'column',\n          index: 0,\n          value: 'column1',\n        },\n        {\n          type: 'column',\n          index: 1,\n          value: 'column2',\n        },\n        {\n          type: 'column',\n          index: 2,\n          value: 'column3',\n        },\n        {\n          type: 'column',\n          index: 3,\n          value: 'column4',\n        },\n      ],\n    },\n    {\n      type: 'row',\n      index: 1,\n      children: [\n        {\n          type: 'cell',\n          columnIndex: 0,\n          rowIndex: 1,\n          value: 1,\n        },\n        {\n          type: 'cell',\n          columnIndex: 1,\n          rowIndex: 1,\n          value: 'two',\n        },\n        {\n          type: 'cell',\n          columnIndex: 2,\n          rowIndex: 1,\n          value: 3,\n        },\n        {\n          type: 'cell',\n          columnIndex: 3,\n          rowIndex: 1,\n          value: null,\n        },\n      ],\n    },\n    {\n      type: 'row',\n      index: 2,\n      children: [\n        {\n          type: 'cell',\n          columnIndex: 0,\n          rowIndex: 2,\n          value: null,\n        },\n        {\n          type: 'cell',\n          columnIndex: 1,\n          rowIndex: 2,\n          value: 'two',\n        },\n        {\n          type: 'cell',\n          columnIndex: 2,\n          rowIndex: 2,\n          value: 33,\n        },\n        {\n          type: 'cell',\n          columnIndex: 3,\n          rowIndex: 2,\n          value: 'four',\n        },\n      ],\n    },\n  ],\n});\n```\n\n## API\n\n### `fromArray(array[, options])`\n\n#### Interface\n```ts\nfunction fromArray(array: any[], options?: Options): Table\n```\n\nTransforms a JS array into a tdast tree.\n\nCreated `Row`, `Column` and `Cell` nodes are automatically assigned relevant row/column indices.\n\nInfers and creates columns from object keys if not explicitly specified.  Columns can be explicitly specified in `options`, affording more structure to the tdast `Column` nodes.\n\n#### Example\n\n```js\nconst array = [\n  { column1: 1, column2: 'two', column3: 3, column4: null },\n  { column1: null, column2: 'two', column3: 33, column4: 'four' },\n];\n\nconst options = {\n  columns: [\n    {\n      label: 'Column 1',\n      data: { category: 'A' },\n      dataType: 'number',\n      value: 'column1',\n    },\n    {\n      label: 'Column 2',\n      data: { category: 'B' },\n      dataType: 'string',\n      value: 'column2',\n    },\n    {\n      label: 'Column 3',\n      data: { category: 'A' },\n      dataType: 'number',\n      value: 'column3',\n    },\n    {\n      label: 'Column 1',\n      data: { category: 'B' },\n      dataType: 'mixed',\n      value: 'column4',\n    },\n  ],\n};\n\nexpect(fromArray(array, options)).toEqual({\n  type: 'table',\n  children: [\n    {\n      type: 'row',\n      index: 0,\n      children: [\n        {\n          type: 'column',\n          index: 0,\n          label: 'Column 1',\n          data: { category: 'A' },\n          dataType: 'number',\n          value: 'column1',\n        },\n        {\n          type: 'column',\n          index: 1,\n          label: 'Column 2',\n          data: { category: 'B' },\n          dataType: 'string',\n          value: 'column2',\n        },\n        {\n          type: 'column',\n          index: 2,\n          label: 'Column 3',\n          data: { category: 'A' },\n          dataType: 'number',\n          value: 'column3',\n        },\n        {\n          type: 'column',\n          index: 3,\n          label: 'Column 1',\n          data: { category: 'B' },\n          dataType: 'mixed',\n          value: 'column4',\n        },\n      ],\n    },\n    {\n      type: 'row',\n      index: 1,\n      children: [\n        {\n          type: 'cell',\n          columnIndex: 0,\n          rowIndex: 1,\n          value: 1,\n        },\n        {\n          type: 'cell',\n          columnIndex: 1,\n          rowIndex: 1,\n          value: 'two',\n        },\n        {\n          type: 'cell',\n          columnIndex: 2,\n          rowIndex: 1,\n          value: 3,\n        },\n        {\n          type: 'cell',\n          columnIndex: 3,\n          rowIndex: 1,\n          value: null,\n        },\n      ],\n    },\n    {\n      type: 'row',\n      index: 2,\n      children: [\n        {\n          type: 'cell',\n          columnIndex: 0,\n          rowIndex: 2,\n          value: null,\n        },\n        {\n          type: 'cell',\n          columnIndex: 1,\n          rowIndex: 2,\n          value: 'two',\n        },\n        {\n          type: 'cell',\n          columnIndex: 2,\n          rowIndex: 2,\n          value: 33,\n        },\n        {\n          type: 'cell',\n          columnIndex: 3,\n          rowIndex: 2,\n          value: 'four',\n        },\n      ],\n    },\n  ],\n});\n```\n\n#### Related interfaces\n```ts\ninterface Column {\n  value: any;\n  data?: Data;\n  dataType?: string;\n  label?: string;\n}\n\ninterface Options {\n  columns?: Column[];\n}\n```\n\n\u003c!-- Definitions --\u003e\n[tdast]: https://github.com/tdast/tdast\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftdast%2Ftdast-util-from-array","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftdast%2Ftdast-util-from-array","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftdast%2Ftdast-util-from-array/lists"}