{"id":23133912,"url":"https://github.com/lcanady/parser","last_synced_at":"2026-01-26T19:24:48.515Z","repository":{"id":57305565,"uuid":"365104533","full_name":"lcanady/parser","owner":"lcanady","description":null,"archived":false,"fork":false,"pushed_at":"2024-11-04T12:26:43.000Z","size":189,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"Main","last_synced_at":"2024-12-05T23:33:36.036Z","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/lcanady.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":"2021-05-07T03:34:05.000Z","updated_at":"2024-11-04T12:26:47.000Z","dependencies_parsed_at":"2024-01-14T05:55:00.460Z","dependency_job_id":"8bab1569-6ada-4087-a66a-03f8ee5d6ada","html_url":"https://github.com/lcanady/parser","commit_stats":{"total_commits":43,"total_committers":3,"mean_commits":"14.333333333333334","dds":"0.16279069767441856","last_synced_commit":"4c55900f391fd3f1498c61492d2f7a5ee1c22172"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lcanady%2Fparser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lcanady%2Fparser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lcanady%2Fparser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lcanady%2Fparser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lcanady","download_url":"https://codeload.github.com/lcanady/parser/tar.gz/refs/heads/Main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230019768,"owners_count":18160600,"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-12-17T12:09:09.733Z","updated_at":"2026-01-26T19:24:48.461Z","avatar_url":"https://github.com/lcanady.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"The Javascript powered, pluggable Muschcode engine.\n\n- [Installation](#installation)\n- [Basic Usage](#basic-usage)\n    - [`string(lists: string, ctx: Context) =\u003e Promise\u003cstring\u003e`](#stringlists-string-ctx-context--promisestring)\n  - [**Functions**](#functions)\n    - [`add(name: string, (args: string[], data = {}) =\u003e {})`](#addname-string-args-string-data----)\n  - [**Substitutions**](#substitutions)\n    - [`addSubs(list: string, ...subs: Sub[])`](#addsubslist-string-subs-sub)\n    - [`substitute(lists: string, msg: string)`](#substitutelists-string-msg-string)\n- [Plugins](#plugins)\n- [Development](#development)\n\n## Installation\n\ninstall the parser with your favorite package manager:\n\n```\nnpm install @ursamu/parser\nyarn add @ursamu/parser\n```\n\n## Basic Usage\n\n```js\nimport { Parser } from \"@ursamu/parser\";\n\n// Create a new parser.\nconst parser = new Parser();\n\n// add a function\nparser.add(\"div\", (args) =\u003e parseInt(args[0]) / parseInt(args[1]));\n\n// Add some substitutions\nparser.addSub(\n  \"telnet\",\n  { before: /%r/g, after: \"\\n\" },\n  { before: /%b/g, after: \" \" },\n  { before: /%t/g, after: \"\\t\" }\n);\n\n// run the parser!\nparser\n  .string(\"telnet\", {\n    msg: \"Hello %0!! [div(6,2)]\",\n    scope: { \"%0\": \"World!\" },\n    data: {},\n  })\n  .then((results) =\u003e console.log(results)); // =\u003e Hello World!!! 3\n```\n\n#### `string(lists: string, ctx: Context) =\u003e Promise\u003cstring\u003e`\n\n### **Functions**\n\nFunctions are the basis of mushcode, and through the parser you are able to represent whatever codebase you wish!\n\n#### `add(name: string, (args: string[], data = {}) =\u003e {})`\n\nAdd a new function to the parser.\n\n```js\nparser.add(\"hello\", (args) =\u003e `hello ${args[0]}!`);\n// hello(Dave) =\u003e hello Dave!\n\nparser.add(\"add\", (args) =\u003e args.reduce((a, b) =\u003e a + parseInt(b), 0));\n// add(2,3) =\u003e 5\n```\n\n- **`args`** The following args are available to the add method:\n  - `args: any[]` An array of arguments given the function in a comma seperated list.\n  - `data: {}` An object where any data needed by the run of the parser is kept. enactor, target, location, etc.\n\n### **Substitutions**\n\nThe parser comes with a customisable substitution system that can take stand in expressions. In a Mux-like example `%crWARNING!!%cn`. To customize what substitutisns are available through the parser:\n\n#### `addSubs(list: string, ...subs: Sub[])`\n\nAdd a new subsitution to the parser. There are two lists that are pre-determined. `pre` and `post`. `pre` substitutions happen before the code is run through the eval process. `post` happens after all of the other substitutions have been run.\n\n- `list` is the list of substitutions that this range should be added too.\n- `subs` A comma seperated list of substitutions to be added to the particular label.\n  - `before` The starting string or regular expression to search for.\n  - `after` What the matched regular expression or text should be substituted for. If you've ised a regi;ar expression for your before, then you can use wildcard matches `$1`.\n  - `strip?` When a function strips the substitutions from your string, what characters should it be substituted with? With most you can get away with a space, or leaving the field blank.\n\n```js\nparser.addSubs(\"telnet\", [\n  {\n    before: /%r/g,\n    after: \"\\n\",\n  }.\n  {\n    before: /%t/g,\n    after: \"\\t\",\n    strip: \"    \"\n  }\n]);\n```\n\n#### `substitute(lists: string, msg: string)`\n\nMake substitutions from the provided apace seperated list string omto the message.\n\n```js\nconst results = parser.substitute(\"telnet\", \"This is a %rtest.\");\n```\n\n## Plugins\n\nThe parser is customizable through a rogbust plugin system.\n\n`parser.plugin(myPlugin)`\n\nThe syntax for creating a plugin is simple:\n\n```js\nexport const plugin = (parser) =\u003e {\n  parser.add(\"add\", (args) =\u003e args.reduce((a, b) =\u003e a + b, 0));\n};\n```\n\n## Development\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flcanady%2Fparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flcanady%2Fparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flcanady%2Fparser/lists"}