{"id":13339476,"url":"https://github.com/tdast/tdast-util-from-csv","last_synced_at":"2025-08-11T01:36:35.728Z","repository":{"id":57376575,"uuid":"294620602","full_name":"tdast/tdast-util-from-csv","owner":"tdast","description":"tdast utility to parse csv into tdast (RFC-4180 compliant)","archived":false,"fork":false,"pushed_at":"2020-09-13T20:40:56.000Z","size":25,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-09T17:18:04.096Z","etag":null,"topics":["ast","csv","parse","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-11T07:07:16.000Z","updated_at":"2020-09-13T20:40:58.000Z","dependencies_parsed_at":"2022-08-29T21:20:35.188Z","dependency_job_id":null,"html_url":"https://github.com/tdast/tdast-util-from-csv","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/tdast/tdast-util-from-csv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdast%2Ftdast-util-from-csv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdast%2Ftdast-util-from-csv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdast%2Ftdast-util-from-csv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdast%2Ftdast-util-from-csv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tdast","download_url":"https://codeload.github.com/tdast/tdast-util-from-csv/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdast%2Ftdast-util-from-csv/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269818803,"owners_count":24480074,"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","parse","tabular-data","tdast","tdast-util","unist","util"],"created_at":"2024-07-29T19:20:03.775Z","updated_at":"2025-08-11T01:36:35.709Z","avatar_url":"https://github.com/tdast.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tdast-util-from-csv\n\n[**tdast**][tdast] utility to parse csv into tdast ([RFC-4180][] compliant).\n\n---\n\n## Install\n\n```sh\nnpm install tdast-util-from-csv\n```\n\n## Use\n\nWith some [RFC-4180][] compliant CSV content (example below includes escaped double quotes and linebreaks):\n\n```csv\n\"col1\",\"c\"\"o\"\"\"\"l,2,,\",\"co\\nl\\n\\n3\\n\"\nrow1col1,  row1col2  ,\" row1col3\\n,\\n\"\"\"\n\"\\nrow2col1\",row2col2,row2col3\\n\n```\n\n`tdast-util-from-csv` will parse the CSV content into a tdast `Table` node tracking row/column/cell offsets and attaching well-defined [`UnistPosition`][dfn-unist-position].\n\n```js\nimport fromCsv from 'tdast-util-from-csv';\n\nconst options = { header: true };\nexpect(fromCsv(csv, options)).toEqual({\n  type: 'table',\n  position: {\n    start: {\n      line: 1,\n      column: 2,\n      offset: 1,\n    },\n    end: {\n      line: 3,\n      column: 30,\n      offset: 102,\n    },\n  },\n  children: [\n    {\n      type: 'row',\n      index: 0,\n      position: {\n        start: {\n          line: 1,\n          column: 2,\n          offset: 1,\n        },\n        end: {\n          line: 1,\n          column: 33,\n          offset: 32,\n        },\n      },\n      children: [\n        {\n          type: 'column',\n          index: 0,\n          position: {\n            start: {\n              line: 1,\n              column: 2,\n              offset: 1,\n            },\n            end: {\n              line: 1,\n              column: 6,\n              offset: 5,\n            },\n          },\n          value: 'col1',\n        },\n        {\n          type: 'column',\n          index: 1,\n          position: {\n            start: {\n              line: 1,\n              column: 9,\n              offset: 8,\n            },\n            end: {\n              line: 1,\n              column: 22,\n              offset: 21,\n            },\n          },\n          value: 'c\"o\"\"l,2,,',\n        },\n        {\n          type: 'column',\n          index: 2,\n          position: {\n            start: {\n              line: 1,\n              column: 25,\n              offset: 24,\n            },\n            end: {\n              line: 1,\n              column: 33,\n              offset: 32,\n            },\n          },\n          value: 'co\\nl\\n\\n3\\n',\n        },\n      ],\n    },\n    {\n      type: 'row',\n      index: 1,\n      position: {\n        start: {\n          line: 2,\n          column: 1,\n          offset: 34,\n        },\n        end: {\n          line: 2,\n          column: 38,\n          offset: 71,\n        },\n      },\n      children: [\n        {\n          type: 'cell',\n          columnIndex: 0,\n          position: {\n            start: {\n              line: 2,\n              column: 1,\n              offset: 34,\n            },\n            end: {\n              line: 2,\n              column: 9,\n              offset: 42,\n            },\n          },\n          rowIndex: 1,\n          value: 'row1col1',\n        },\n        {\n          type: 'cell',\n          columnIndex: 1,\n          position: {\n            start: {\n              line: 2,\n              column: 10,\n              offset: 43,\n            },\n            end: {\n              line: 2,\n              column: 22,\n              offset: 55,\n            },\n          },\n          rowIndex: 1,\n          value: '  row1col2  ',\n        },\n        {\n          type: 'cell',\n          columnIndex: 2,\n          position: {\n            start: {\n              line: 2,\n              column: 24,\n              offset: 57,\n            },\n            end: {\n              line: 2,\n              column: 38,\n              offset: 71,\n            },\n          },\n          rowIndex: 1,\n          value: ' row1col3\\n,\\n\"',\n        },\n      ],\n    },\n    {\n      type: 'row',\n      index: 2,\n      position: {\n        start: {\n          line: 3,\n          column: 2,\n          offset: 74,\n        },\n        end: {\n          line: 3,\n          column: 30,\n          offset: 102,\n        },\n      },\n      children: [\n        {\n          type: 'cell',\n          columnIndex: 0,\n          position: {\n            start: {\n              line: 3,\n              column: 2,\n              offset: 74,\n            },\n            end: {\n              line: 3,\n              column: 11,\n              offset: 83,\n            },\n          },\n          rowIndex: 2,\n          value: '\\nrow2col1',\n        },\n        {\n          type: 'cell',\n          columnIndex: 1,\n          position: {\n            start: {\n              line: 3,\n              column: 13,\n              offset: 85,\n            },\n            end: {\n              line: 3,\n              column: 21,\n              offset: 93,\n            },\n          },\n          rowIndex: 2,\n          value: 'row2col2',\n        },\n        {\n          type: 'cell',\n          columnIndex: 2,\n          position: {\n            start: {\n              line: 3,\n              column: 22,\n              offset: 94,\n            },\n            end: {\n              line: 3,\n              column: 30,\n              offset: 102,\n            },\n          },\n          rowIndex: 2,\n          value: 'row2col3',\n        },\n      ],\n    },\n  ],\n});\n```\n\n## API\n\n### `fromCsv(csv[, options])`\n\n#### Interface\n```ts\nfunction fromCsv(\n  // RFC-4180 compliant CSV string\n  csv: string,\n  // optional options to configure parser\n  options?: Options,\n): Table;\n```\n\n[RFC-4180][] compliant CSV parser to parse CSV to a tdast `Table` node.\n\nParsed `Cell` nodes conveniently escape any double-quote characters while preserving the original [`UnistPosition`][dfn-unist-position].  This enables conversion of the tdast tree into other [syntax trees][syntax-tree] that can make use of the positional information.\n\n#### Related interfaces\n```ts\ninterface Options {\n  // if the first row of the CSV contains header values\n  header?: boolean;\n}\n```\n\n## Author's Note\nI have little experience writing parsers.  Unlike most CSV parsers, this parser does not use regexp and its implementation is specifically written to track and assemble a tdast tree with well-defined [`UnistPosition`][dfn-unist-position].\n\nThe parser **should** be well-behaved since it is implemented against the [RFC-4180][] spec with some testing.\n\nIf there are any issues or you want to implement this in a more elegant/efficient way, please let me know through GH issues!\n\n\u003c!-- Definitions --\u003e\n[dfn-unist-position]: https://github.com/syntax-tree/unist#position\n[rfc-4180]: https://tools.ietf.org/html/rfc4180\n[syntax-tree]: https://github.com/syntax-tree\n[tdast]: https://github.com/tdast/tdast\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftdast%2Ftdast-util-from-csv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftdast%2Ftdast-util-from-csv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftdast%2Ftdast-util-from-csv/lists"}