{"id":30138520,"url":"https://github.com/tdast/tdastscript","last_synced_at":"2025-08-11T01:36:37.894Z","repository":{"id":144112472,"uuid":"294025147","full_name":"tdast/tdastscript","owner":"tdast","description":"utility to create tdast trees","archived":false,"fork":false,"pushed_at":"2020-09-10T03:25:48.000Z","size":18,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-09T17:18:00.886Z","etag":null,"topics":["ast","hyperscript","script","tabular-data","tdast","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-09T06:37:56.000Z","updated_at":"2020-09-13T09:17:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"c8592eb1-ef94-4830-815c-37d4f9eff09a","html_url":"https://github.com/tdast/tdastscript","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/tdast/tdastscript","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdast%2Ftdastscript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdast%2Ftdastscript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdast%2Ftdastscript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdast%2Ftdastscript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tdast","download_url":"https://codeload.github.com/tdast/tdastscript/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdast%2Ftdastscript/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269804753,"owners_count":24477852,"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","hyperscript","script","tabular-data","tdast","unist","util"],"created_at":"2025-08-11T01:36:37.287Z","updated_at":"2025-08-11T01:36:37.854Z","avatar_url":"https://github.com/tdast.png","language":"JavaScript","readme":"# tdastscript\n\nutility to create [**tdast**][tdast] trees.\n\n---\n\n## Install\n\n```sh\nnpm install tdastscript\n```\n\n\n## Use\n\n```js\nimport td from 'tdastscript';\n\nconst tdast = td('table', [\n  td('row', [\n    td('column', 'row0-column0'),\n    td('column', 'row0-column1'),\n    td('column', {\n      value: 'row0-column3',\n      badProperty: 'badProperty',\n      dataType: 'percentage',\n      data: { fieldA: 'valueA', fieldB: true },\n      label: 'Column 3',\n    }),\n  ]),\n  td('row', [\n    'row1-cell0',\n    'row1-cell1',\n    'row1-cell2',\n  ]),\n]);\n```\n\nyields the following tree:\n\n```js\nexpect(tdast).toEqual({\n  type: 'table',\n  children: [\n    {\n      type: 'row',\n      index: 0,\n      children: [\n        {\n          type: 'column',\n          index: 0,\n          value: 'row0-column0',\n        },\n        {\n          type: 'column',\n          index: 1,\n          value: 'row0-column1',\n        },\n        {\n          type: 'column',\n          index: 2,\n          value: 'row0-column2',\n        },\n      ],\n    },\n    {\n      type: 'row',\n      index: 1,\n      children: [\n        {\n          type: 'cell',\n          columnIndex: 0,\n          rowIndex: 1,\n          value: 'row1-cell0',\n        },\n        {\n          type: 'cell',\n          columnIndex: 1,\n          rowIndex: 1,\n          value: 'row1-cell1',\n        },\n        {\n          type: 'cell',\n          columnIndex: 2,\n          rowIndex: 1,\n          value: 'row1-cell2',\n        },\n      ],\n    },\n  ],\n});\n```\n\n## API\n\n### `td(type[, props][, children|value])`\n#### Interface\n```ts\nfunction td(\n  /** Node type */\n  arg1?: NodeType,\n  /** Either node properties, children nodes or value */\n  arg2?: Properties | Children | Value,\n  /** children nodes or value */\n  arg3?: Children | Value,,\n): Node;\n```\n\nReturns a tdast `Node` (i.e. `Cell`, `Column`, `Row`, `Table`) with associated `properties`, `children` or `value` based on how it is called.\n\n`tdastscript` conveniently assigns row/column indices on `Row`, `Column`, `Cell` nodes, based on how it is composed.\n\n`tdastscript` can be used in a composable way, as shown in the opening example.  See the following examples below for details on usage and behaviors.\n\n#### Examples\n\nUse without optional arguments to create simple nodes.\n\n```js\nexpect(td('table')).toEqual({\n  type: 'table',\n  children: [],\n});\nexpect(td('row')).toEqual({\n  type: 'row',\n  children: [],\n});\nexpect(td('cell')).toEqual({\n  type: 'cell',\n  value: undefined,\n});\nexpect(td('column')).toEqual({\n  type: 'column',\n  value: undefined,\n});\n```\n\nFor **Literal** nodes, such as `Cell` and `Column`, if the second argument is skipped and only the third argument is provided as singleton values, create literal nodes:\n\n```js\nexpect(td('cell', 'cell1')).toEqual({\n  type: 'cell',\n  value: 'cell1',\n});\n\nexpect(td('column', 'column1')).toEqual({\n  type: 'column',\n  value: 'column1',\n});\n```\n\nFor **Parent** nodes, such as `Table` and `Row`, if the second argument is skipped and only the the third argument is provided as child nodes, create parent nodes:\n\n```js\nexpect(td('table', [\n  { type: 'row', children: [] },\n  { type: 'row', children: [] },\n])).toEqual({\n  type: 'table',\n  children: [\n    { type: 'row', children: [] },\n    { type: 'row', children: [] },\n  ],\n});\n\nexpect(td('row', [\n  { type: 'cell', value: 'cell1' },\n  'cell2', // accepts value literal shorthand to create Cell nodes\n])).toEqual({\n  type: 'row',\n  children: [\n    { type: 'cell', value: 'cell1' },\n    { type: 'cell', value: 'cell2' },\n  ],\n});\n```\n\nIf the second argument is not skipped, attach the properties to the specified nodes.  Note that `tdastscript` will only attach properties specified by the node's interface.  Refer to the formal [type definitions][type-definitions] for details.\n\n```js\nexpect(td('table', { \n  data: { badProperty: 'badProperty', fieldA: 'valueA' },\n  position: UnistPosition,\n})).toEqual({\n  type: 'table',\n  data: { fieldA: 'valueA' },\n  position: UnistPosition,\n});\n\nexpect(td('row', { \n  data: { badProperty: 'badProperty', fieldA: 'valueA' },\n  index: 5,\n  position: UnistPosition,\n}), [\n  'cell1',\n  'cell2',\n]).toEqual({\n  type: 'row',\n  data: { fieldA: 'valueA' },\n  index: 5,\n  position: UnistPosition,\n  children: [\n    { type: 'cell', value: 'cell1' },\n    { type: 'cell', value: 'cell2' },\n  ],\n});\n```\n\n#### Related interfaces\n```ts\n/** tdastscript can return any valid tdast node. */\ntype Node = Cell | Column | Row | Table;\n\n/** Node types of tdast nodes. */\ntype NodeType = 'cell' | 'column' | 'row' | 'table';\n\n/** Child nodes can be actual nodes or string values representing Cell nodes */\ntype Children = Node[] | string[];\n\n/** Node properties in object syntax */\ntype Properties = Record\u003cstring, any\u003e;\n\n/** Alias for loosely-typed value */\ntype Value = any;\n```\n\n\u003c!-- Definitions --\u003e\n[tdast]: https://github.com/tdast/tdast\n[type-definitions]: https://github.com/tdast/tdast-types\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftdast%2Ftdastscript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftdast%2Ftdastscript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftdast%2Ftdastscript/lists"}