{"id":17492416,"url":"https://github.com/kakasoo/regexp-manager","last_synced_at":"2025-04-22T20:28:13.974Z","repository":{"id":65272929,"uuid":"589176189","full_name":"kakasoo/regexp-manager","owner":"kakasoo","description":"type-safe regexp pattern builder","archived":false,"fork":false,"pushed_at":"2023-12-03T09:19:15.000Z","size":566,"stargazers_count":21,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-19T03:54:21.440Z","etag":null,"topics":["builder","design-pattern","regexp","type-safe","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/regexp-manager","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/kakasoo.png","metadata":{"files":{"readme":"README(legacy).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}},"created_at":"2023-01-15T10:29:31.000Z","updated_at":"2024-04-17T03:13:48.000Z","dependencies_parsed_at":"2023-02-15T15:31:45.248Z","dependency_job_id":"2e722006-7d0d-4a2c-b0b6-ba3e0380a36e","html_url":"https://github.com/kakasoo/regexp-manager","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kakasoo%2Fregexp-manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kakasoo%2Fregexp-manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kakasoo%2Fregexp-manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kakasoo%2Fregexp-manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kakasoo","download_url":"https://codeload.github.com/kakasoo/regexp-manager/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250318070,"owners_count":21410872,"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":["builder","design-pattern","regexp","type-safe","typescript"],"created_at":"2024-10-19T09:04:18.148Z","updated_at":"2025-04-22T20:28:13.956Z","avatar_url":"https://github.com/kakasoo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# regexp-manager\n\nThe library aims to make regular expressions easier for developers who have worked with ORM.\nInspired by [TypeORM's queryBuilder](https://orkhan.gitbook.io/typeorm/docs/select-query-builder#what-is-querybuilder), the library is designed to provide a builder pattern named RegExpBuilder.\n\n# findOne method (incomplete 23.01.24)\n\n```typescript\nit('from method set initial value \u0026 include other 1', () =\u003e {\n    // If you put the mouse over the variable,\n    // you can see in advance what regular expression pattern will come out.\n\n    const test = new RegExpBuilder().findOne({\n        from: 'test',\n        include: { partial: 'left' },\n        moreThanEqual: 1,\n        lessThanEqual: 3,\n    });\n\n    expect(test).toBe('(?\u003c=(left))(test){1,3}');\n});\n```\n\nThe test variable is deduced from type to `'(?\u003c=(left))(test)'`, without having to check whether it is `'(?\u003c=(left))(test)'`.  \nTherefore, the findOne method is useful when you immediately deduce and write a value, even if it may be less free than other RegExpBuilder methods.  \nnow `from` and `include`, `lessThanEqual`, `moreThanEqual` options available.\n\n[this link is test code of `findOne` method. it will help you.](https://github.com/kakasoo/regexp-manager/blob/main/src/test/regexp-repository.spec.ts)\n\n# createRegExpBuilder\n\n```typescript\n/**\n * return : /(?\u003c=(forehead))(test)/gi\n */\nconst includeRegExp = new RegExpBuilder().from('test').include('forehead', { isForehead: true }).getOne();\n```\n\n```typescript\n/**\n * return : /((?\u003c=(cat))(mouse))(?=(dog))/gi\n */\nconst includeRegExp = new RegExpBuilder().from('mouse').include('cat').include('dog', { isForehead: false }).getOne();\n```\n\nyou just use `createRegExpBuilder()` method.  \nso, you can create regExp and decorate by using RegExpBuilder methods.  \nYou can simply call a method called `createRegExpBuilder` to create a builder, and you can use various methods to create regular expressions without learning it.  \nThe code above makes you not have to memorize regular expression symbols such as lookaround and lookbehind.\n\n## createRegExpBuilder methods\n\n### from method\n\n```typescript\nconst regExp = new RegExpBuilder('initialValue').getOne(); // RegExp\n```\n\n```typescript\nconst regExp = new RegExpBuilder().from('initialValue').getOne(); // RegExp, same meaning.\n```\n\n`from` method receives the first string of regular expressions as a parameter to be created in the builder pattern.  \nIf you want to create a more complex pattern, you can also write the `sub-expression` below.  \nAll methods to be implemented in the future will be made all sub-expression possible.\n\n### getOne method\n\nReturns regexp instances based on methods written so far.\n\n### getRawOne method\n\nReturns string based on methods written so far.  \nYou can use this as the first parameter of the regular expression constructor.\n\n### include \u0026 andInclude method\n\n```typescript\n/**\n * return : /(?\u003c=(forehead))(test)/gi\n */\nconst includeRegExp = new RegExpBuilder().from('test').include('forehead', { isForehead: true }).getOne();\n```\n\n```typescript\nconst includeRegExp = new RegExpBuilder()\n    .from('test')\n    .include('[0-9]+', { isForehead: true })\n    .andInclude('[a-z]+', { isForehead: true })\n    .getOne();\n\nconst res = 'cat123test'.match(includeRegExp)?.at(0);\nexpect(res).toBe('test');\n```\n\n```typescript\n/**\n * return : `(cat is behind of )(?=(dog))`\n */\nconst includeRegExp = new RegExpBuilder().from('cat is behind of ').include('dog', { isForehead: false }).getOne();\n\nconst res = 'cat is behind of dog'.match(includeRegExp)?.at(0);\nexpect(res).toBe('cat is behind of ');\n```\n\nThe include method is a method that contains a string that is not included in a capture group.  \nThe first parameter of the include method is the sub-expression function that generates the character or its string to be included, and the second parameter is options.  \nThe options means where the string of this inclusion relationship should be located before or after the initial value.\n\nThe include method should only be used once per builder. If you want to use a second inclusion, sconsider and include.\n\n### isOptinonal method (incomplete)\n\n### whatever method (incomplete)\n\n### and method\n\n```typescript\nconst leftHand = new RegExpBuilder('Hand').and('left', { isForehead: true }).getRawOne();\nexpect(leftHand).toBe('leftHand');\n```\n\n```typescript\nconst regexp = new RegExpBuilder('one')\n    .and((qb) =\u003e {\n        return qb.from('two').and('three').getRawOne();\n    })\n    .getRawOne();\nexpect(regexp).toBe('threetwoone');\n```\n\nThe `and` method is responsible for modifying the initial value.  \nWhen writing a initial value, it would be more readable to write it separately using the and method rather than writing it in a single line.\n\n### or\n\n```typescript\nconst leftOrRight = new RegExpBuilder('left').or('right').getRawOne();\nexpect(leftOrRight).toBe('left|right');\n```\n\n```typescript\nconst leftOrRight = new RegExpBuilder('left')\n    .or((qb) =\u003e {\n        return qb\n            .from('r')\n            .and('i', { isForehead: false })\n            .and('g', { isForehead: false })\n            .and('h', { isForehead: false })\n            .and('t', { isForehead: false })\n            .getRawOne();\n    })\n    .getRawOne();\n\nexpect(leftOrRight).toBe('left|right');\n```\n\nThe `or` method is responsible for modifying the initial value.  \nWhen writing a initial value, it would be more readable to write it separately using the and method rather than writing it in a single line.\n\n### join\n\n```typescript\nconst regexp = new RegExpBuilder()\n    .from((qb) =\u003e {\n        return qb.join([(qb) =\u003e qb.from('one'), qb.from('two').getRawOne(), 'three'], '|');\n    })\n    .getRawOne();\n\nexpect(regexp).toBe('one|two|three');\n```\n\nthe `join` method make from method easy.\n\n### lessThanEqual\n\n```typescript\nit('1. string \"cat\" but lessThanEqual 3', () =\u003e {\n    // If you don't set maximum value, it will be empty string.\n    // regExp: /(cat){3,}/gi\n    const regExp = new RegExpBuilder().from('(cat)').lessThanEqual(3).getOne();\n\n    expect('cat'.match(regExp)?.at(0) === 'cat').toBe(true);\n    expect('catcat'.match(regExp)?.at(0) === 'catcat').toBe(true);\n    expect('catcatcat'.match(regExp)?.at(0) === 'catcatcat').toBe(true);\n\n    expect('catcatcatcat'.match(regExp)?.at(0) === 'catcatcat').toBe(true);\n    expect('catcatcatcat'.match(regExp)?.at(0) === 'catcatcatcat').toBe(false);\n});\n```\n\n### moreThanEqual\n\n```typescript\nit('1. string \"cat\" but moreThanEqual 3', () =\u003e {\n    // If you don't set minimum value, it will be 1.\n    // regExp: /(cat){1,3}/gi\n    const regExp = new RegExpBuilder().from('(cat)').moreThanEqual(3).getOne();\n\n    expect('cat'.match(regExp)?.at(0) === 'cat').toBe(false);\n    expect('catcat'.match(regExp)?.at(0) === 'catcat').toBe(false);\n    expect('catcatcat'.match(regExp)?.at(0) === 'catcatcat').toBe(true);\n\n    expect('catcatcatcat'.match(regExp)?.at(0) === 'catcatcatcat').toBe(true);\n    expect('catcatcatcat'.match(regExp)?.at(0) === 'catcatcatcat').toBe(true);\n});\n```\n\n### between\n\n```typescript\nit('1. string \"cat\" but lessThanEqual 3', () =\u003e {\n    const pattern1 = new RegExpBuilder().from('(cat)').lessThanEqual(3).moreThanEqual(3).getRawOne();\n    const pattern2 = new RegExpBuilder().from('(cat)').between(3, 3).getRawOne();\n\n    // (cat){3, 3}\n    expect(pattern1).toBe(pattern2);\n});\n```\n\n## order by execution\n\n1. from ( or constructor )\n2. whatever, isoptional\n3. include\n4. lessThanEqual, moreThanEqual, between\n\nNo matter how you write RegExpBuilder's method, the order of the methods is enforced.  \nThis is to ensure action.\n\n# sub-expression\n\n```typescript\nconst current = new RegExpBuilder()\n    .from((qb) =\u003e {\n        return qb.from('cat').include('dog').getRawOne(); // string is ok\n    })\n    .getOne();\n```\n\n```typescript\nconst current = new RegExpBuilder()\n    .from((qb) =\u003e {\n        return qb.from('cat').include('dog'); // RegExpBuilder instance is ok\n    })\n    .getOne();\n```\n\nSub-expression should return the completed string from the builder. ( Maybe `getRawOne method` will help. )  \nHowever, simply returning a RegExpBuilder instance allows it to work without difficulty.  \nThis is an exception to prevent human error.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkakasoo%2Fregexp-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkakasoo%2Fregexp-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkakasoo%2Fregexp-manager/lists"}