{"id":13339444,"url":"https://github.com/tdast/tdast-util-to-array","last_synced_at":"2026-05-18T05:38:05.301Z","repository":{"id":144112465,"uuid":"294625766","full_name":"tdast/tdast-util-to-array","owner":"tdast","description":"tdast utility to transform tdast to a JS array","archived":false,"fork":false,"pushed_at":"2020-09-13T08:01:19.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-27T20:43:19.941Z","etag":null,"topics":["array","ast","json","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-11T07:31:12.000Z","updated_at":"2020-09-13T08:53:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"5f0f3c82-e8c3-4596-854e-305a74ed299e","html_url":"https://github.com/tdast/tdast-util-to-array","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/tdast/tdast-util-to-array","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdast%2Ftdast-util-to-array","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdast%2Ftdast-util-to-array/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdast%2Ftdast-util-to-array/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdast%2Ftdast-util-to-array/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tdast","download_url":"https://codeload.github.com/tdast/tdast-util-to-array/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdast%2Ftdast-util-to-array/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267711242,"owners_count":24132080,"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-07-29T02:00:12.549Z","response_time":2574,"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":["array","ast","json","tabular-data","tdast","tdast-util","unist","util"],"created_at":"2024-07-29T19:20:03.357Z","updated_at":"2025-11-08T23:01:41.273Z","avatar_url":"https://github.com/tdast.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tdast-util-to-array\n\n[**tdast**][tdast] utility to transform from tdast to JS array.\n\n---\n\n## Install\n\n```sh\nnpm install tdast-util-to-array\n```\n\n## Use\n\n```js\nimport toArray from 'tdast-util-to-array';\n\nconst tdast = {\n  type: 'table',\n  children: [\n    {\n      type: 'row',\n      index: 0,\n      children: [\n        {\n          type: 'column',\n          index: 0,\n          value: 'col1',\n        },\n        {\n          type: 'column',\n          index: 1,\n          value: 'col2',\n        },\n        {\n          type: 'column',\n          index: 2,\n          value: 'col3',\n        },\n      ],\n    },\n    {\n      type: 'row',\n      index: 1,\n      children: [\n        {\n          type: 'cell',\n          columnIndex: 0,\n          rowIndex: 1,\n          value: 'row1col1',\n        },\n        {\n          type: 'cell',\n          columnIndex: 1,\n          rowIndex: 1,\n          value: 'row1col2',\n        },\n        {\n          type: 'cell',\n          columnIndex: 2,\n          rowIndex: 1,\n          value: 'row1col3',\n        },\n      ],\n    },\n    {\n      type: 'row',\n      index: 2,\n      children: [\n        {\n          type: 'cell',\n          columnIndex: 0,\n          rowIndex: 2,\n          value: 'row2col1',\n        },\n        {\n          type: 'cell',\n          columnIndex: 1,\n          rowIndex: 2,\n          value: 'row2col2',\n        },\n        {\n          type: 'cell',\n          columnIndex: 2,\n          rowIndex: 2,\n          value: 'row2col3',\n        },\n      ],\n    },\n  ],\n};\n\nexpect(toArray(tdast)).toEqual({\n  { col1: 'row1col1', col2: 'row1col2', col3: 'row1col3' },\n  { col1: 'row2col1', col2: 'row2col2', col3: 'row2col3' },\n});\n```\n\n## API\n\n### `toArray(array[, options])`\n\n#### Interface\n```ts\nfunction toArray(\n  // tdast Table node\n  tdast: Table,\n  // options to configure transformer\n  options?: Options,\n): Array\u003cRecord\u003cstring, any\u003e\u003e;\n```\n\nTransforms a [tdast][] `Table` node into a JS array of objects.\n\nIf columns and row cell cardinality do not match, an error will be thrown to inform that the JS array cannot be transformed.\n\nBy default, `toArray` will infer `Column` node values to use as keys for the JS array objects.  If the tdast node does not contain `Column` nodes, or you wish to use explicit column keys, you can specify these with the `options.columns` property as detailed in the example below.\n\n#### Example\nUsing the same tdast tree in the earlier example\n\n```js\nimport toArray from 'tdast-util-to-array';\n\nconst options = {\n  columns ['Col A', 'Col B', 'Col C'],\n};\n\nexpect(toArray(tdast, options)).toEqual([\n  { 'Col A': 'row1col1', 'Col B': 'row1col2', 'Col C': 'row1col3' },\n  { 'Col A': 'row2col1', 'Col B': 'row2col2', 'Col C': 'row2col3' },\n]);\n```\n\n#### Related interfaces\n```ts\ninterface Options {\n  // array of column strings that will be used as object keys.  Overrides the column values detected in the tdast tree.\n  columns?: string[];\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-to-array","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftdast%2Ftdast-util-to-array","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftdast%2Ftdast-util-to-array/lists"}