{"id":18879351,"url":"https://github.com/azusfin/str-lang-tool","last_synced_at":"2026-02-20T00:30:16.659Z","repository":{"id":252090616,"uuid":"839391867","full_name":"Azusfin/str-lang-tool","owner":"Azusfin","description":"A structured way to parse text for a language","archived":false,"fork":false,"pushed_at":"2024-08-31T10:33:22.000Z","size":97,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-12-31T02:43:59.569Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/Azusfin.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2024-08-07T14:11:35.000Z","updated_at":"2024-08-31T10:33:26.000Z","dependencies_parsed_at":"2024-08-25T03:27:43.384Z","dependency_job_id":"000df961-1a48-40d5-b214-8caa8c2d4fd2","html_url":"https://github.com/Azusfin/str-lang-tool","commit_stats":null,"previous_names":["azusfin/str-lang-tool"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azusfin%2Fstr-lang-tool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azusfin%2Fstr-lang-tool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azusfin%2Fstr-lang-tool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azusfin%2Fstr-lang-tool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Azusfin","download_url":"https://codeload.github.com/Azusfin/str-lang-tool/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239841743,"owners_count":19705981,"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":[],"created_at":"2024-11-08T06:35:31.465Z","updated_at":"2026-02-20T00:30:16.611Z","avatar_url":"https://github.com/Azusfin.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# str-lang-tool\n\n\u003e A structured way to parse text for a language\n\n[![NPM Version](https://img.shields.io/npm/v/str-lang-tool.svg?maxAge=3600)](https://www.npmjs.com/package/str-lang-tool)\n[![NPM Downloads](https://img.shields.io/npm/dt/str-lang-tool.svg?maxAge=3600)](https://www.npmjs.com/package/str-lang-tool)\n\n\u003e Uses [Unist](https://github.com/syntax-tree/unist) (Universal Syntax Tree)\n\n## How\n- [How to read text and parse it into a tree](#how-to-read)\n- [How to transform tree into another tree](#how-to-transform)\n\n### How To Read\n```js\nimport { Reader, ReadFeature } from \"str-lang-tool\"\n\nclass ReadFeature1 extends ReadFeature {\n    handle() {\n        if (this.done) return false /* Release feature after done */\n\n        const char = this.ctx.char()\n\n        if (char === /* Some character */) {\n            this.ctx.ancestor.children.push(/* A Node */)\n            this.done = true\n\n            return true\n        } else if (char === /* Some another character */) {\n            this.done = true\n\n            const ancestor = /* A Parent Node */\n            this.ctx.ancestor.children.push(ancestor)\n\n            // Feature succession (Let another feature take handle)\n            return {\n                ancestor,\n                features: ctx =\u003e [new ReadFeature2(ctx)]\n            }\n        } else {\n            return false\n        }\n    }\n}\n\nclass ReadFeature2 extends ReadFeature {\n    handle() {\n        const char = this.ctx.char()\n\n        if (char === /* Some another character */) return false\n\n        this.ctx.ancestor.children.push(/* Another Node */)\n        return true\n    }\n}\n\nconst reader = new Reader({\n    text: /* Some text */,\n    root: /* Output tree */,\n    rootFeatures: ctx =\u003e [new ReadFeature1(ctx)]\n})\n\nconst tree = await reader.read()\n```\n\n### How To Transform\n```js\nimport { Transformer, TransformFeature } from \"str-lang-tool\"\n\nclass TransformFeature1 extends TransformFeature {\n    handle(node) {\n        if (this.done) return false /* Release feature after done */\n\n        if (node.type === /* A Node type */) {\n            this.ctx.output.children.push(node)\n        } else if (node.type === /* Another Node type */) {\n            const output = /* A Parent Node */\n            this.ctx.output.children.push(output)\n\n            // Feature succession (Let another feature handle nested input)\n            return {\n                input: node, output,\n                features: ctx =\u003e [new TransformFeature2(ctx)]\n            }\n        }\n\n        this.done = true\n        return true\n    }\n}\n\nclass TransformFeature2 extends TransformFeature {\n    handle(node) {\n        // Just push whatever\n        this.ctx.output.children.push(node)\n    }\n}\n\nconst transformer = new Transformer({\n    inputRoot: /* Input tree */,\n    outputRoot: /* Output tree */,\n    rootFeatures: ctx =\u003e [new TransformFeature1(ctx)]\n})\n\nconst tree = await transformer.transform()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazusfin%2Fstr-lang-tool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazusfin%2Fstr-lang-tool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazusfin%2Fstr-lang-tool/lists"}