{"_id":"@c-syn/regext","_rev":"10-c42502daa39f311322406206c78c9089","name":"@c-syn/regext","dist-tags":{"latest":"0.0.7"},"versions":{"0.0.5":{"name":"@c-syn/regext","version":"0.0.5","description":"Transforms regular expressions into dynamic templates for flexible text generation.","main":"lib/index.js","types":"lib/index.d.ts","scripts":{"build":"tsc --build","test":"mocha '__tests__/**/*.test.js'"},"repository":{"type":"git","url":"git+https://github.com/C-Syn/RegExT.git"},"keywords":["regext","regex","regexp","transform regex","regex template","template","regular expression","mustache template","handlebars"],"type":"module","author":{"name":"C-Syn"},"license":"Apache-2.0","bugs":{"url":"https://github.com/C-Syn/RegExT/issues"},"homepage":"https://github.com/C-Syn/RegExT#readme","devDependencies":{"@types/node":"^20.11.17","@typescript-eslint/eslint-plugin":"^7.0.1","@typescript-eslint/parser":"^7.0.1","chai":"^5.1.0","eslint":"^8.56.0","eslint-config-prettier":"^9.1.0","eslint-plugin-prettier":"^5.1.3","mocha":"^10.3.0","prettier":"^3.2.5","ts-node":"^10.9.2","typescript":"^5.3.3"},"dependencies":{"regexp-tree":"^0.1.27"},"_id":"@c-syn/regext@0.0.5","gitHead":"2fcbe7afa2073af5c26e71295db082b0568adab2","_nodeVersion":"21.6.1","_npmVersion":"10.2.4","dist":{"integrity":"sha512-/XngZPEqrdK9tpYWKnwCqXSUtJAL5ctAL0vfjxsGGsfurj7dmZZ0zlJd9NSHHubTIJORTivy67lm2UpjBde2Mw==","shasum":"9b5419ee1897205c2d8a0b1ed860a75798f1820a","tarball":"https://registry.npmjs.org/@c-syn/regext/-/regext-0.0.5.tgz","fileCount":7,"unpackedSize":27361,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHtSnf2BvyYaQOzzsfm8SzG6RUDXhAf4n8Jj3ufn1QEfAiAlmeVPpLcfUs/wyFT3/pzINAQwmdRqa6lDKCofKGPHGA=="}]},"_npmUser":{"name":"ca5e","email":"kees@csyn.nl"},"directories":{},"maintainers":[{"name":"ca5e","email":"kees@csyn.nl"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/regext_0.0.5_1708963742098_0.6053926251459167"},"_hasShrinkwrap":false},"0.0.6":{"name":"@c-syn/regext","version":"0.0.6","description":"Transforms regular expressions into dynamic templates for flexible text generation.","main":"lib/index.js","types":"lib/index.d.ts","scripts":{"build":"tsc --build","test":"mocha '__tests__/**/*.test.js'"},"repository":{"type":"git","url":"git+https://github.com/C-Syn/RegExT.git"},"keywords":["regext","regex","regexp","transform regex","regex template","template","regular expression","mustache template","handlebars"],"type":"module","author":{"name":"C-Syn"},"license":"Apache-2.0","bugs":{"url":"https://github.com/C-Syn/RegExT/issues"},"homepage":"https://github.com/C-Syn/RegExT#readme","devDependencies":{"@types/node":"^20.11.17","@typescript-eslint/eslint-plugin":"^7.0.1","@typescript-eslint/parser":"^7.0.1","chai":"^5.1.0","eslint":"^8.56.0","eslint-config-prettier":"^9.1.0","eslint-plugin-prettier":"^5.1.3","mocha":"^10.3.0","prettier":"^3.2.5","ts-node":"^10.9.2","typescript":"^5.3.3"},"dependencies":{"regexp-tree":"^0.1.27"},"_id":"@c-syn/regext@0.0.6","gitHead":"672055638c0fa6ab5fab7cd75c253bfce8e61b32","_nodeVersion":"21.6.1","_npmVersion":"10.2.4","dist":{"integrity":"sha512-vCHxzszQ2w9p8eMTjMnfyGTwluRTp3L3S6esKfjajggzaNYSgBGE2cxofPEco+zR6zN0y9cA3GD+9uUv7jzMug==","shasum":"8858bbdcce0e4f7dbb7fb6307ebfa57c61350830","tarball":"https://registry.npmjs.org/@c-syn/regext/-/regext-0.0.6.tgz","fileCount":7,"unpackedSize":27751,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDx/zEuVQ0AcNw1EWNC3X55ply0r/qCDMc3HP0Xanqf2AIhAO7RLX0iT5bNKVy9fCWYzpnc+gOA3WDy+wKRxkvriJ0C"}]},"_npmUser":{"name":"ca5e","email":"kees@csyn.nl"},"directories":{},"maintainers":[{"name":"ca5e","email":"kees@csyn.nl"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/regext_0.0.6_1708965348562_0.9692361531317815"},"_hasShrinkwrap":false},"0.0.7":{"name":"@c-syn/regext","version":"0.0.7","description":"Transforms regular expressions into dynamic templates for flexible text generation.","main":"lib/index.js","types":"lib/index.d.ts","scripts":{"build":"tsc --build","test":"mocha '__tests__/**/*.test.js'"},"repository":{"type":"git","url":"git+https://github.com/C-Syn/RegExT.git"},"keywords":["regext","regex","regexp","transform regex","regex template","template","regular expression","mustache template","handlebars"],"type":"module","author":{"name":"C-Syn"},"license":"Apache-2.0","bugs":{"url":"https://github.com/C-Syn/RegExT/issues"},"homepage":"https://github.com/C-Syn/RegExT#readme","devDependencies":{"@types/node":"^20.11.17","@typescript-eslint/eslint-plugin":"^7.0.1","@typescript-eslint/parser":"^7.0.1","chai":"^5.1.0","eslint":"^8.56.0","eslint-config-prettier":"^9.1.0","eslint-plugin-prettier":"^5.1.3","mocha":"^10.3.0","prettier":"^3.2.5","ts-node":"^10.9.2","typescript":"^5.3.3"},"dependencies":{"regexp-tree":"^0.1.27"},"_id":"@c-syn/regext@0.0.7","gitHead":"daa05fcd22dade0678ca5f79308589d59b7a51b3","_nodeVersion":"21.0.0","_npmVersion":"10.2.4","dist":{"integrity":"sha512-n0LdZJ1WPjy9H1pje6BslG26io5XBo1V744U/gzCAWoIZ4jLwrA/snerkwkQeElIFa8ZhajRZyqEiXoAiThGNg==","shasum":"ffa3d5b6c0a84213fbd9759331502546a3ac95aa","tarball":"https://registry.npmjs.org/@c-syn/regext/-/regext-0.0.7.tgz","fileCount":7,"unpackedSize":28843,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCsW9yS5yuC0jApGdbtEwWtApXqg02kLZUR8hX1BYkGJQIgIk9ffU0VRp9x7VKKtgLmAAj+89kPNj4wBW1vYZPRRmA="}]},"_npmUser":{"name":"ca5e","email":"kees@csyn.nl"},"directories":{},"maintainers":[{"name":"ca5e","email":"kees@csyn.nl"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/regext_0.0.7_1709628110071_0.817131447387015"},"_hasShrinkwrap":false}},"time":{"created":"2024-02-19T10:19:31.188Z","0.0.1":"2024-02-19T10:19:31.414Z","modified":"2024-03-05T08:41:50.839Z","0.0.2":"2024-02-19T19:38:01.500Z","0.0.3":"2024-02-19T19:44:46.696Z","0.0.4":"2024-02-19T19:52:48.118Z","0.0.5":"2024-02-26T16:09:02.375Z","0.0.6":"2024-02-26T16:35:48.726Z","0.0.7":"2024-03-05T08:41:50.367Z"},"maintainers":[{"name":"ca5e","email":"kees@csyn.nl"}],"description":"Transforms regular expressions into dynamic templates for flexible text generation.","homepage":"https://github.com/C-Syn/RegExT#readme","keywords":["regext","regex","regexp","transform regex","regex template","template","regular expression","mustache template","handlebars"],"repository":{"type":"git","url":"git+https://github.com/C-Syn/RegExT.git"},"author":{"name":"C-Syn"},"bugs":{"url":"https://github.com/C-Syn/RegExT/issues"},"license":"Apache-2.0","readme":"# RegExp to Template Converter\n\nThis package provides a class to convert regular expressions into template strings. It currently supports both a [Mustache](https://mustache.github.io/) and plain [style](#type).\nThe underlying function is strongly dependent on the [regexp-tree](https://www.npmjs.com/package/regexp-tree) package, which is used to parse the regular expression into an [abstract syntax tree (AST)](https://astexplorer.net/#/gist/4ea2b52f0e546af6fb14f9b2f5671c1c/32f6c6b53186e618a73edd3c51f2168c6a05a21b). Its parser module is generated from the [regexp grammar](https://github.com/DmitrySoshnikov/regexp-tree/blob/master/src/parser/regexp.bnf), which is based on the regular expressions grammar used in ECMAScript. After parsing, the [AST](https://astexplorer.net/#/gist/4ea2b52f0e546af6fb14f9b2f5671c1c/32f6c6b53186e618a73edd3c51f2168c6a05a21b) is then traversed to generate the template string.\n\n## Installation\n\n```bash\nnpm install @c-syn/regext\n```\n\n## Usage\n\n```typescript\nimport RegExT from \"@c-syn/regext\" \n\nconst regexp = /.../ // Your regular expression\nconst type = \"Mustache\" // or \"plain\"\n\nconst template = new RegExT(regexp, type).template\n```\n> [!TIP]\n> Try this code in the [RegExT Playground](https://playcode.io/1769499). \n\nRegExT is a class that takes two parameters: a regular expression and a type. The class has a `toString` method that returns the template string, it contains the following properties. The `convert` function that is used to generate the template string is also exposed `import { convert } from 'regex-template'`.\n\n| Property | Type | Description |\n| --- | --- | --- |\n| `regexp` | `RegExp` | The regular expression that was used to generate the template string. |\n| `type` | `string` | The [type](#type) of template string that was generated. |\n| `template` | `string` | The template string that was generated. |\n\n### `type`\n\nThe `type` parameter is a string that specifies the type of template string that should be generated. The following types are supported. If no type, or an unknown type, is specified, type is set to `Mustache`.\n\n| Type | Description |\n| --- | --- |\n| `Mustache` | A template string that uses the [Mustache](https://mustache.github.io/) syntax. |\n| `plain` | A plain template string. |\n\n## Example\n\n```regexp\n/(?:(?<=[^`\\\\])|^)\\[(?=[^@\\n\\]]+\\]\\([^@)]*@[:a-z0-9_-]*\\))(?<showtext>[^@\\n\\]]+)\\]\\((?:(?:(?<type>[a-z0-9_-]*):)?)(?:(?<term>[^@\\n:#)]*?)?(?:#(?<trait>[^@\\n:#)]*))?)?@(?<scopetag>[a-z0-9_-]*)(?::(?<vsntag>[a-z0-9_-]*))?\\)/g\n```\n\nThe regular expression above is used to match a markdown link with a [specific format](https://tno-terminology-design.github.io/tev2-specifications/docs/specs/tools/trrt#predefined-interpreters). Depending on the specified [type](#type), the regular expression will be converted into the following templates.\n\n> **Mustache**\n> ```handlebars\n> [{{showtext}}]({{#type}}{{type}}:{{/type}}{{term}}{{#trait}}#{{trait}}{{/trait}}@{{scopetag}}{{#vsntag}}:{{vsntag}}{{/vsntag}})\n> ```\n\n> **Plain**\n> ```\n> [showtext](type:term#trait@scopetag:vsntag)\n> ```\n\n## Use Cases\n\nThe generated template string can be used to convert any texts into texts that match the regular expression. Conversion can be done by replacing the template string with the corresponding values. For instance, after interpreting a text, it is converted using [Handlebars](https://handlebarsjs.com/) to match another regular expression.\n\nThe generated template string can also be used to quickly visualize the structure of the regular expression. This can be useful when debugging or when trying to understand the structure of a regular expression.\n\n## Process\n\nAfter the regular expression is parsed into an [abstract syntax tree (AST)](https://astexplorer.net/#/gist/4ea2b52f0e546af6fb14f9b2f5671c1c/32f6c6b53186e618a73edd3c51f2168c6a05a21b), the [AST](https://astexplorer.net/#/gist/4ea2b52f0e546af6fb14f9b2f5671c1c/32f6c6b53186e618a73edd3c51f2168c6a05a21b) is traversed to generate the template string. \nThe following steps are walked through on every [node](https://www.npmjs.com/package/regexp-tree#ast-nodes-specification), mostly depending on the specific type.\n\n1. Certain types of nodes are removed (i.e., [`ClassRange`](https://www.npmjs.com/package/regexp-tree#character-class-ranges), [`Disjunction`](https://www.npmjs.com/package/regexp-tree#disjunction), [`Assertion`](https://www.npmjs.com/package/regexp-tree#assertions)) as they may contain [`Char`](https://www.npmjs.com/package/regexp-tree#char) nodes that should not be included in the template string. For instance: ranges of characters that the regular expression is supposed to match are removed.\n2. [`Repetition`](https://www.npmjs.com/package/regexp-tree#quantifiers) nodes are changed to [`Alternative`](https://www.npmjs.com/package/regexp-tree#alternative) nodes if the [Quantifier's](https://www.npmjs.com/package/regexp-tree#quantifiers) `from` and `to` properties are identical. Within the changed node, the [`Repetition`](https://www.npmjs.com/package/regexp-tree#quantifiers) node is repeated `n` times.\n3. [`Group`](https://www.npmjs.com/package/regexp-tree#groups) nodes are checked for their `capturing` property. If it is set to `true`, the group is converted into a [`Char`](https://www.npmjs.com/package/regexp-tree#char) node based on the specified template string type. Either the `name`, if it exists, or the `number` property is used to identify the group in the template string.\n4. [`Alternative`](https://www.npmjs.com/package/regexp-tree#alternative) (or *concatenation*) nodes are handled according to the specified template string type. For instance, in the case of using the [`Mustache`](#usage) type, the [`Alternative`](https://www.npmjs.com/package/regexp-tree#alternative) node is wrapped in a `section` block (e.g., `{{#person}}{{person}} exists{{/person}}`).\n\nAfter these steps halve been walked through, every [`Char`](https://www.npmjs.com/package/regexp-tree#char) node its value is concatenated, resulting in the template string.\n\n## Limitations\n\nDue to the nature of the [process](#process) used to generate the template string, the following limitations apply.\n\n1. Nodes of types [`ClassRange`](https://www.npmjs.com/package/regexp-tree#character-class-ranges), [`Disjunction`](https://www.npmjs.com/package/regexp-tree#disjunction), and [`Assertion`](https://www.npmjs.com/package/regexp-tree#assertions) are removed from the [AST](https://astexplorer.net/#/gist/4ea2b52f0e546af6fb14f9b2f5671c1c/32f6c6b53186e618a73edd3c51f2168c6a05a21b). This means that the template string will not contain any information about these nodes.\n2. [`Backreferences`](https://www.npmjs.com/package/regexp-tree#backreferences) are not (yet) supported. This means that the template string will not contain any information about backreferences.\n3. [`Quantifiers`](https://www.npmjs.com/package/regexp-tree#quantifiers) (repetitions) are only handled if the `from` and `to` properties of the node are identical. In this case, the number of times the expressions is supposed to be repeated is clear. If the [`Quantifier`](https://www.npmjs.com/package/regexp-tree#quantifiers) applies to a [`Character class`](https://www.npmjs.com/package/regexp-tree#character-class), it is ignored; as this means 'one of' a list of [`Chars`](https://www.npmjs.com/package/regexp-tree#char) is supposed to picked, which can't be assumed. If the `from` and `to` properties are different, the corresponding expression is not repeated in the template string.\n4. [`Meta characters`](https://www.npmjs.com/package/regexp-tree#meta-char) representing ranges of characters (e.g., `.`, `\\s`, `\\w`) are ignored. This means that the template string will not contain any information about these nodes.\n","readmeFilename":"README.md"}