{"id":21359570,"url":"https://github.com/suin/refractor-flatten","last_synced_at":"2025-07-31T19:03:25.524Z","repository":{"id":57163467,"uuid":"373058359","full_name":"suin/refractor-flatten","owner":"suin","description":"A utility to transform Refractor ASTs to flat arrays.","archived":false,"fork":false,"pushed_at":"2021-06-02T06:15:16.000Z","size":145,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-28T20:48:11.566Z","etag":null,"topics":["refractor"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/suin.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":"2021-06-02T06:08:37.000Z","updated_at":"2021-06-02T06:15:02.000Z","dependencies_parsed_at":"2022-08-31T22:23:03.204Z","dependency_job_id":null,"html_url":"https://github.com/suin/refractor-flatten","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suin%2Frefractor-flatten","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suin%2Frefractor-flatten/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suin%2Frefractor-flatten/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suin%2Frefractor-flatten/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/suin","download_url":"https://codeload.github.com/suin/refractor-flatten/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243835376,"owners_count":20355597,"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","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":["refractor"],"created_at":"2024-11-22T05:28:43.969Z","updated_at":"2025-03-16T06:26:12.144Z","avatar_url":"https://github.com/suin.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @suin/refractor-flatten\n\nA utility to transform [Refractor](https://github.com/wooorm/refractor) ASTs to flat arrays.\n\n## Installation\n\n```bash\nyarn add @suin/refractor-flatten\n# or\nnpm install @suin/refractor-flatten\n```\n\n## Usage\n\n### Basic Usage\n\n```typescript\nimport refractor from \"refractor\";\nimport flatten from \"@suin/refractor-flatten\";\n\nconst tree = refractor.highlight(\"`${value}`\", \"js\");\nconst flat = flatten(tree);\n```\n\nThe structure of `tree` is:\n\n```\nroot[1]\n└─0 element\u003cspan\u003e[3]\n    │ properties: {\"className\":[\"token\",\"template-string\"]}\n    ├─0 element\u003cspan\u003e[1]\n    │   │ properties: {\"className\":[\"token\",\"template-punctuation\",\"string\"]}\n    │   └─0 text \"`\"\n    ├─1 element\u003cspan\u003e[3]\n    │   │ properties: {\"className\":[\"token\",\"interpolation\"]}\n    │   ├─0 element\u003cspan\u003e[1]\n    │   │   │ properties: {\"className\":[\"token\",\"interpolation-punctuation\",\"punctuation\"]}\n    │   │   └─0 text \"${\"\n    │   ├─1 text \"value\"\n    │   └─2 element\u003cspan\u003e[1]\n    │       │ properties: {\"className\":[\"token\",\"interpolation-punctuation\",\"punctuation\"]}\n    │       └─0 text \"}\"\n    └─2 element\u003cspan\u003e[1]\n        │ properties: {\"className\":[\"token\",\"template-punctuation\",\"string\"]}\n        └─0 text \"`\"\n```\n\nThe structure of the `flat` above becomes:\n\n```\nroot[5]\n├─0 element\u003cspan\u003e[1]\n│   │ properties: {\"className\":[\"token\",\"template-string\",\"template-punctuation\",\"string\"]}\n│   └─0 text \"`\"\n├─1 element\u003cspan\u003e[1]\n│   │ properties: {\"className\":[\"token\",\"template-string\",\"interpolation\",\"interpolation-punctuation\",\"punctuation\"]}\n│   └─0 text \"${\"\n├─2 element\u003cspan\u003e[1]\n│   │ properties: {\"className\":[\"token\",\"template-string\",\"interpolation\"]}\n│   └─0 text \"value\"\n├─3 element\u003cspan\u003e[1]\n│   │ properties: {\"className\":[\"token\",\"template-string\",\"interpolation\",\"interpolation-punctuation\",\"punctuation\"]}\n│   └─0 text \"}\"\n└─4 element\u003cspan\u003e[1]\n    │ properties: {\"className\":[\"token\",\"template-string\",\"template-punctuation\",\"string\"]}\n    └─0 text \"`\"\n```\n\n## API Reference\n\nhttps://suin.github.io/refractor-flatten/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuin%2Frefractor-flatten","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsuin%2Frefractor-flatten","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuin%2Frefractor-flatten/lists"}