{"id":18057378,"url":"https://github.com/1computer1/rett","last_synced_at":"2025-04-05T10:22:54.519Z","repository":{"id":65489790,"uuid":"96500039","full_name":"1Computer1/rett","owner":"1Computer1","description":"Regular expressions template tag https://www.npmjs.com/package/rett","archived":false,"fork":false,"pushed_at":"2017-07-11T21:05:23.000Z","size":18,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-13T09:48:19.657Z","etag":null,"topics":["es6","regex","regexp","template-literals"],"latest_commit_sha":null,"homepage":"","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/1Computer1.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}},"created_at":"2017-07-07T04:47:06.000Z","updated_at":"2024-10-02T11:13:06.000Z","dependencies_parsed_at":"2023-01-25T17:25:11.035Z","dependency_job_id":null,"html_url":"https://github.com/1Computer1/rett","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1Computer1%2Frett","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1Computer1%2Frett/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1Computer1%2Frett/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1Computer1%2Frett/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/1Computer1","download_url":"https://codeload.github.com/1Computer1/rett/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247320253,"owners_count":20919743,"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":["es6","regex","regexp","template-literals"],"created_at":"2024-10-31T02:07:34.535Z","updated_at":"2025-04-05T10:22:54.495Z","avatar_url":"https://github.com/1Computer1.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rett\n\n*Regular Expressions Template Tag*  \n\n## Features\n\n- Removes need to use double backslash.\n- Escapes special regex characters.\n- Choosing when to escape special characters.\n- Multiline regex with comments and indents.\n- Utility for making complex regex.  \n\n## Usage\n\n### Basic Use\n\nThe `re` function can either take a template tag or be called normally.  \nWhen called normally, it takes regex flags and can only take a template tag from then on.  \n\n```js\nconst re = require('rett');\n\nconsole.log(re`\\d+\\b`);\n// =\u003e /\\d+\\b/\n\nconsole.log(re('gi')`\\b[a-z]\\b`);\n// =\u003e /\\b[a-z]\\b/gi\n```\n\n### Substitutions\n\nInterpolate values just like any other template string.  \nAll values will automatically be escaped.  \n\n```js\nconst text = '?+{[()';\n\nconsole.log(re`${text} \\d+`);\n// =\u003e /\\?\\+\\{\\[\\(\\) \\d+/\n```\n\n### Multiline Regex\n\nThe `re.line` function is used for multiline regex.  \nIt has support for indents as well as single-line comments.  \nIt works in the same way as the `re` function.  \n\n```js\nconsole.log(re.line`\n    (\n        \\d+     // Digits\n        [A-Z]   // Letter\n    )\n`);\n\n// =\u003e /(\\d+[A-Z])/\n```\n\n### Ignoring Escape\n\nIgnore escapes if you are planning on building regex bit by bit.  \nThis is done with the `re.ignore` function which can take either a string or a template tag.  \nThe `re.raw` function is also available for disabling escaping altogether.  \n\n```js\nconst special = '{0,2}';\n\nconsole.log(re`1${re.ignore(special)}`);\n// =\u003e /1{0,2}/\n\nconsole.log(re.raw`1${special}`);\n// =\u003e /1{0,2}/\n\nconst digits = re.ignore`\\d+`;\n\nconsole.log(re`-?${digits}`);\n// =\u003e /-?\\d+/\n```\n\n## Utility\n\n### `re.escape()`\n\nEscapes special regex characters from a string.  \nCan take a template tag and will escape interpolated values.  \n\n```js\nconsole.log(re.escape('What?'));\n// =\u003e 'What\\\\?'\n```\n\n### `re.unescape()`\n\nUnescapes special regex characters from a string.  \nCan take a template tag and will unescape interpolated values.  \nNote that this is not a perfect reversal.  \n\n```js\nconsole.log(re.unescape('What\\\\?'));\n// =\u003e 'What?'\n```\n\n### `re.join()`\n\nJoins an array together by a character.  \nEscapes the values of the array.  \nUseful for making different possibilties with `|` in regex.  \n\n```js\nconst list = re.join(['(', ')', '?']);\nconst regex = re`${list}`;\n\nconsole.log(regex);\n// =\u003e /\\(|\\)|\\?/\n```\n\n## Options\n\n### `re.options`\n\nYou can set the default options here.  \n\n- `escape`: default for escaping substitutions.\n- `multiline`: default for parsing as multiline.\n- `debug`: logs to console whenever a regex is made.\n- `flags.default`: default for flags if no flags provided.\n- `flags.addtion`: flags to add onto exisiting flags.\n\n```js\nre.options = {\n    escape: true,\n    multiline: true,\n    debug: true,\n    flags: {\n        default: 'u',\n        addition: 'u'\n    }\n};\n\nconsole.log(re`\n    ABC  // Matches A, B, then C.\n    (\\d) // Then a number.\n`);\n\n// =\u003e /ABC(\\d)/u\n```\n\n### `re.specialEscapeRegex`\n\nRegex for escaping special characters.  \nReassign with your own if needed.  \n\n### `re.RegExp`\n\nConstructor used for creating new regular expression instances.  \nReassign with your own if needed.  \n\n## Other\n\n### `re.create()`\n\nCreates a new regex from the values inputted.  \nUsed internally.  \n\n```js\nconsole.log(re.create(['a', 'b'], [1], { flags: 'g' }));\n// =\u003e /a1b/g\n```\n\n### `re.isTemplateTag()`\n\nChecks if a value is a template tag.  \nUsed internally.  \n\n```js\nconsole.log(re.isTemplateTag`asdf`);\n// =\u003e true\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1computer1%2Frett","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F1computer1%2Frett","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1computer1%2Frett/lists"}