{"_id":"@bluelovers/to-regex-range2","name":"@bluelovers/to-regex-range2","dist-tags":{"latest":"5.0.1"},"versions":{"5.0.1":{"name":"@bluelovers/to-regex-range2","version":"5.0.1","description":"Pass two numbers, get a regex-compatible source string for matching ranges. Validated against more than 2.78 million test assertions.","keywords":["bash","date","expand","expansion","expression","glob","match","match date","match number","match numbers","match year","matches","matching","number","numbers","numerical","range","ranges","regex","regexp","regular","regular expression","sequence","create-by-yarn-tool","create-by-tsdx"],"homepage":"https://github.com/bluelovers/to-regex-range#readme","bugs":{"url":"https://github.com/bluelovers/to-regex-range/issues"},"repository":{"type":"git","url":"git+https://github.com/bluelovers/to-regex-range.git"},"license":"MIT","author":{"name":"Jon Schlinkert","url":"https://github.com/jonschlinkert"},"contributors":[{"name":"Jon Schlinkert","url":"http://twitter.com/jonschlinkert"},{"name":"Rouven Weßling","url":"www.rouvenwessling.de"}],"sideEffects":false,"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.esm.mjs","require":"./dist/index.cjs"},"./package.json":"./package.json","./src/*":"./src/*"},"main":"dist/index.cjs","unpkg":"dist/index.umd.production.min.cjs","module":"dist/index.esm.mjs","types":"dist/index.d.ts","typings":"dist/index.d.ts","directories":{"test":"test"},"scripts":{"pretest":"echo pretest","test":"yarn run test:jest","test:jest":"jest --passWithNoTests","test:jest:clearCache":"jest --clearCache","test:jest:snapshot":"yarn run test:jest -- -u","test:snapshot":"yarn run test -- -u","posttest":"yarn run build","install:frozenLockfile":"yarn-tool install --frozen-lockfile","install:resetLockfile":"yarn-tool install --reset-lockfile","build":"yarn run build:tsdx && yarn run build:dts:bundle","build:dts:bundle":"ynpx dts-bundle-generator -o ./dist/index.d.ts ./src/index.ts --no-banner --inline-declare-global & echo build:dts:bundle","build:dts:copy":"copy .\\src\\index.d.ts .\\dist\\index.d.ts & echo build:dts","build:dts:tsc":"yarn run build:dts:tsc:emit && yarn run build:dts:copy","build:dts:tsc:emit":"tsc --emitDeclarationOnly --declaration --noEmit false","build:tsdx":"ynpx @bluelovers/tsdx build --target node","ci:install":"yarn install --frozen-lockfile && yarn add -W typescript@next jest ts-jest ts-node ynpx lerna yarn-tool","ci:build":"echo ci:build","npm:publish":"npm publish","npm:publish:bump":"yarn run version:bump && npm publish","preversion":"echo preversion && yarn run test","version":"echo version","version:bump":"yarn-tool version","postversion":"echo postversion","prepublish":"echo prepublish","prepare":"echo prepare","prepublishOnly":"yarn run preversion","prepublishOnly:check-bin":"ynpx --quiet @yarn-tool/check-pkg-bin","prepublishOnly:update":"yarn run ncu && yarn run sort-package-json","prepack":"echo prepack","pack":"echo pack","postpack":"echo postpack","publish":"echo publish","postpublish":"yarn run postpublish:changelog && yarn run postpublish:git:commit && yarn run postpublish:git:tag && yarn run postpublish:git:push","postpublish:changelog":"ynpx --quiet @yarn-tool/changelog && git add ./CHANGELOG.md","postpublish:git:commit":"git commit -m \"chore(release): publish\" . & echo postpublish:git:commit","postpublish:git:push":"git push --follow-tags","postpublish:git:tag":"ynpx --quiet @yarn-tool/tag","postpublishOnly":"echo postpublishOnly","ncu":"yarn-tool ncu -u","sort-package-json":"yarn-tool sort","tsc:showConfig":"ynpx get-current-tsconfig -p"},"dependencies":{"@lazy-assert/check-basic":"^1.0.8"},"devDependencies":{"@bluelovers/tsconfig":"*","@types/jest":"^29.0.3","fill-range":"^7.0.1","text-table":"^0.2.0","time-diff":"^0.3.1"},"packageManager":"yarn@1.22.19","engines":{"node":">=8.0"},"publishConfig":{"access":"public"},"gitHead":"44f432bbe5ac9fe374c8a0d3d9e78702d6b823ed","_id":"@bluelovers/to-regex-range2@5.0.1","_nodeVersion":"18.9.0","_npmVersion":"8.19.1","dist":{"integrity":"sha512-0fVn7EqIBAZjlnyzz87E5JUs0H+4KwW/i2RVzWRbcjb+xBxD0TIvRGUYGrfvb5eiQf0cuJn4F/zkTmd0cgrA0g==","shasum":"bd7622edae106023048caebf1584840be7c1590e","tarball":"https://registry.npmjs.org/@bluelovers/to-regex-range2/-/to-regex-range2-5.0.1.tgz","fileCount":18,"unpackedSize":144876,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCw4DpqnIt4SG6j+5migSwT/rURyN1Dt6frZkNZ+8qeUwIgX4gfbaI6UsBci6DviEvVT1tCYPY2grIuLZx+MklIW80="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjKPgrACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq7fg//YKIcLYOI1+pmByYVgVvxw5BbTjlU1f7jYTPAyLc3H/PfjHgL\r\n+esibYbjtW9EV/qPFflidPQT1HKgND1vGZD3Oz4DUt7ZF9w+8nZ1cvOLH2oM\r\nZ4FhvVmgWwGT4orqPCfE3v4y55bGXHA9Z1i5xf6aD7CJmzhzhkrmKFMqfDlz\r\n4hr2tL0/1xW/yEKgF/oyOGMLKjtZQzUN2u4AeURFeM9e7UeZe3pnkWuUAAHd\r\nYs2/MMLietxBJwQOzaUV/oiWDzMuSHw2W22fFbi3GfXQ3r+AkT+huCzqgOQo\r\nW+eCz+beqpxmXD6IiOtFhAj3QcyCrkyZkcSmWP6vOqspvY4yZ6oAf2YeZTvp\r\nipXYo91Kbh8WeyRmNwKAkl2hSmf3q4waVFXDxQ6DszNekCvc43vNcUOENKVL\r\nr7nNIUFhsmkwfajrN1txfpZVQLeeESqoWXh+3U3EdrMOZ1oJy02Wz/fTkpQN\r\nXfv+77prVjSLptLS+tev8y8Jat8e/OQnveV1NFV/4RSraSfNiv/RlAdVthTS\r\nkP9P5CabnlJjTuhTqQr0VfIyFMRWKKVN79oRjVjwS+JYvS6Tl7O84jey79PJ\r\nJXvN0khFcKjM62CSbIjVo1cxX2NkD8sSal3EfZzoxWQinFDLS6ucv1cqUgU+\r\nEERsVdkNjZ7cWQMBEMT3SLpFzNz76Z037ic=\r\n=TBkY\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"bluelovers","email":"codelovers@users.sourceforge.net"},"maintainers":[{"name":"bluelovers","email":"codelovers@users.sourceforge.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/to-regex-range2_5.0.1_1663629354955_0.12709333981689075"},"_hasShrinkwrap":false}},"time":{"created":"2022-09-19T23:15:54.903Z","5.0.1":"2022-09-19T23:15:55.244Z","modified":"2022-09-19T23:15:55.385Z"},"maintainers":[{"name":"bluelovers","email":"codelovers@users.sourceforge.net"}],"description":"Pass two numbers, get a regex-compatible source string for matching ranges. Validated against more than 2.78 million test assertions.","homepage":"https://github.com/bluelovers/to-regex-range#readme","keywords":["bash","date","expand","expansion","expression","glob","match","match date","match number","match numbers","match year","matches","matching","number","numbers","numerical","range","ranges","regex","regexp","regular","regular expression","sequence","create-by-yarn-tool","create-by-tsdx"],"repository":{"type":"git","url":"git+https://github.com/bluelovers/to-regex-range.git"},"contributors":[{"name":"Jon Schlinkert","url":"http://twitter.com/jonschlinkert"},{"name":"Rouven Weßling","url":"www.rouvenwessling.de"}],"author":{"name":"Jon Schlinkert","url":"https://github.com/jonschlinkert"},"bugs":{"url":"https://github.com/bluelovers/to-regex-range/issues"},"license":"MIT","readme":"# to-regex-range [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W8YFZ425KND68) [![NPM version](https://img.shields.io/npm/v/to-regex-range.svg?style=flat)](https://www.npmjs.com/package/to-regex-range) [![NPM monthly downloads](https://img.shields.io/npm/dm/to-regex-range.svg?style=flat)](https://npmjs.org/package/to-regex-range) [![NPM total downloads](https://img.shields.io/npm/dt/to-regex-range.svg?style=flat)](https://npmjs.org/package/to-regex-range) [![Linux Build Status](https://img.shields.io/travis/micromatch/to-regex-range.svg?style=flat&label=Travis)](https://travis-ci.org/micromatch/to-regex-range)\n\n> Pass two numbers, get a regex-compatible source string for matching ranges. Validated against more than 2.78 million test assertions.\n\nPlease consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save to-regex-range\n```\n\n<details>\n<summary><strong>What does this do?</strong></summary>\n\n<br>\n\nThis libary generates the `source` string to be passed to `new RegExp()` for matching a range of numbers.\n\n**Example**\n\n```js\nconst toRegexRange = require('to-regex-range');\nconst regex = new RegExp(toRegexRange('15', '95'));\n```\n\nA string is returned so that you can do whatever you need with it before passing it to `new RegExp()` (like adding `^` or `$` boundaries, defining flags, or combining it another string).\n\n<br>\n\n</details>\n\n<details>\n<summary><strong>Why use this library?</strong></summary>\n\n<br>\n\n### Convenience\n\nCreating regular expressions for matching numbers gets deceptively complicated pretty fast.\n\nFor example, let's say you need a validation regex for matching part of a user-id, postal code, social security number, tax id, etc:\n\n* regex for matching `1` => `/1/` (easy enough)\n* regex for matching `1` through `5` => `/[1-5]/` (not bad...)\n* regex for matching `1` or `5` => `/(1|5)/` (still easy...)\n* regex for matching `1` through `50` => `/([1-9]|[1-4][0-9]|50)/` (uh-oh...)\n* regex for matching `1` through `55` => `/([1-9]|[1-4][0-9]|5[0-5])/` (no prob, I can do this...)\n* regex for matching `1` through `555` => `/([1-9]|[1-9][0-9]|[1-4][0-9]{2}|5[0-4][0-9]|55[0-5])/` (maybe not...)\n* regex for matching `0001` through `5555` => `/(0{3}[1-9]|0{2}[1-9][0-9]|0[1-9][0-9]{2}|[1-4][0-9]{3}|5[0-4][0-9]{2}|55[0-4][0-9]|555[0-5])/` (okay, I get the point!)\n\nThe numbers are contrived, but they're also really basic. In the real world you might need to generate a regex on-the-fly for validation.\n\n**Learn more**\n\nIf you're interested in learning more about [character classes](http://www.regular-expressions.info/charclass.html) and other regex features, I personally have always found [regular-expressions.info](http://www.regular-expressions.info/charclass.html) to be pretty useful.\n\n### Heavily tested\n\nAs of April 07, 2019, this library runs [>1m test assertions](./test/test.js) against generated regex-ranges to provide brute-force verification that results are correct.\n\nTests run in ~280ms on my MacBook Pro, 2.5 GHz Intel Core i7.\n\n### Optimized\n\nGenerated regular expressions are optimized:\n\n* duplicate sequences and character classes are reduced using quantifiers\n* smart enough to use `?` conditionals when number(s) or range(s) can be positive or negative\n* uses fragment caching to avoid processing the same exact string more than once\n\n<br>\n\n</details>\n\n## Usage\n\nAdd this library to your javascript application with the following line of code\n\n```js\nconst toRegexRange = require('to-regex-range');\n```\n\nThe main export is a function that takes two integers: the `min` value and `max` value (formatted as strings or numbers).\n\n```js\nconst source = toRegexRange('15', '95');\n//=> 1[5-9]|[2-8][0-9]|9[0-5]\n\nconst regex = new RegExp(`^${source}$`);\nconsole.log(regex.test('14')); //=> false\nconsole.log(regex.test('50')); //=> true\nconsole.log(regex.test('94')); //=> true\nconsole.log(regex.test('96')); //=> false\n```\n\n## Options\n\n### options.capture\n\n**Type**: `boolean`\n\n**Deafault**: `undefined`\n\nWrap the returned value in parentheses when there is more than one regex condition. Useful when you're dynamically generating ranges.\n\n```js\nconsole.log(toRegexRange('-10', '10'));\n//=> -[1-9]|-?10|[0-9]\n\nconsole.log(toRegexRange('-10', '10', { capture: true }));\n//=> (-[1-9]|-?10|[0-9])\n```\n\n### options.shorthand\n\n**Type**: `boolean`\n\n**Deafault**: `undefined`\n\nUse the regex shorthand for `[0-9]`:\n\n```js\nconsole.log(toRegexRange('0', '999999'));\n//=> [0-9]|[1-9][0-9]{1,5}\n\nconsole.log(toRegexRange('0', '999999', { shorthand: true }));\n//=> \\d|[1-9]\\d{1,5}\n```\n\n### options.relaxZeros\n\n**Type**: `boolean`\n\n**Default**: `true`\n\nThis option relaxes matching for leading zeros when when ranges are zero-padded.\n\n```js\nconst source = toRegexRange('-0010', '0010');\nconst regex = new RegExp(`^${source}$`);\nconsole.log(regex.test('-10')); //=> true\nconsole.log(regex.test('-010')); //=> true\nconsole.log(regex.test('-0010')); //=> true\nconsole.log(regex.test('10')); //=> true\nconsole.log(regex.test('010')); //=> true\nconsole.log(regex.test('0010')); //=> true\n```\n\nWhen `relaxZeros` is false, matching is strict:\n\n```js\nconst source = toRegexRange('-0010', '0010', { relaxZeros: false });\nconst regex = new RegExp(`^${source}$`);\nconsole.log(regex.test('-10')); //=> false\nconsole.log(regex.test('-010')); //=> false\nconsole.log(regex.test('-0010')); //=> true\nconsole.log(regex.test('10')); //=> false\nconsole.log(regex.test('010')); //=> false\nconsole.log(regex.test('0010')); //=> true\n```\n\n## Examples\n\n| **Range**                   | **Result**                                                                      | **Compile time** |\n| ---                         | ---                                                                             | ---              |\n| `toRegexRange(-10, 10)`     | `-[1-9]\\|-?10\\|[0-9]`                                                           | _132μs_          |\n| `toRegexRange(-100, -10)`   | `-1[0-9]\\|-[2-9][0-9]\\|-100`                                                    | _50μs_           |\n| `toRegexRange(-100, 100)`   | `-[1-9]\\|-?[1-9][0-9]\\|-?100\\|[0-9]`                                            | _42μs_           |\n| `toRegexRange(001, 100)`    | `0{0,2}[1-9]\\|0?[1-9][0-9]\\|100`                                                | _109μs_          |\n| `toRegexRange(001, 555)`    | `0{0,2}[1-9]\\|0?[1-9][0-9]\\|[1-4][0-9]{2}\\|5[0-4][0-9]\\|55[0-5]`                | _51μs_           |\n| `toRegexRange(0010, 1000)`  | `0{0,2}1[0-9]\\|0{0,2}[2-9][0-9]\\|0?[1-9][0-9]{2}\\|1000`                         | _31μs_           |\n| `toRegexRange(1, 50)`       | `[1-9]\\|[1-4][0-9]\\|50`                                                         | _24μs_           |\n| `toRegexRange(1, 55)`       | `[1-9]\\|[1-4][0-9]\\|5[0-5]`                                                     | _23μs_           |\n| `toRegexRange(1, 555)`      | `[1-9]\\|[1-9][0-9]\\|[1-4][0-9]{2}\\|5[0-4][0-9]\\|55[0-5]`                        | _30μs_           |\n| `toRegexRange(1, 5555)`     | `[1-9]\\|[1-9][0-9]{1,2}\\|[1-4][0-9]{3}\\|5[0-4][0-9]{2}\\|55[0-4][0-9]\\|555[0-5]` | _43μs_           |\n| `toRegexRange(111, 555)`    | `11[1-9]\\|1[2-9][0-9]\\|[2-4][0-9]{2}\\|5[0-4][0-9]\\|55[0-5]`                     | _38μs_           |\n| `toRegexRange(29, 51)`      | `29\\|[34][0-9]\\|5[01]`                                                          | _24μs_           |\n| `toRegexRange(31, 877)`     | `3[1-9]\\|[4-9][0-9]\\|[1-7][0-9]{2}\\|8[0-6][0-9]\\|87[0-7]`                       | _32μs_           |\n| `toRegexRange(5, 5)`        | `5`                                                                             | _8μs_            |\n| `toRegexRange(5, 6)`        | `5\\|6`                                                                          | _11μs_           |\n| `toRegexRange(1, 2)`        | `1\\|2`                                                                          | _6μs_            |\n| `toRegexRange(1, 5)`        | `[1-5]`                                                                         | _15μs_           |\n| `toRegexRange(1, 10)`       | `[1-9]\\|10`                                                                     | _22μs_           |\n| `toRegexRange(1, 100)`      | `[1-9]\\|[1-9][0-9]\\|100`                                                        | _25μs_           |\n| `toRegexRange(1, 1000)`     | `[1-9]\\|[1-9][0-9]{1,2}\\|1000`                                                  | _31μs_           |\n| `toRegexRange(1, 10000)`    | `[1-9]\\|[1-9][0-9]{1,3}\\|10000`                                                 | _34μs_           |\n| `toRegexRange(1, 100000)`   | `[1-9]\\|[1-9][0-9]{1,4}\\|100000`                                                | _36μs_           |\n| `toRegexRange(1, 1000000)`  | `[1-9]\\|[1-9][0-9]{1,5}\\|1000000`                                               | _42μs_           |\n| `toRegexRange(1, 10000000)` | `[1-9]\\|[1-9][0-9]{1,6}\\|10000000`                                              | _42μs_           |\n\n## Heads up!\n\n**Order of arguments**\n\nWhen the `min` is larger than the `max`, values will be flipped to create a valid range:\n\n```js\ntoRegexRange('51', '29');\n```\n\nIs effectively flipped to:\n\n```js\ntoRegexRange('29', '51');\n//=> 29|[3-4][0-9]|5[0-1]\n```\n\n**Steps / increments**\n\nThis library does not support steps (increments). A pr to add support would be welcome.\n\n## History\n\n### v2.0.0 - 2017-04-21\n\n**New features**\n\nAdds support for zero-padding!\n\n### v1.0.0\n\n**Optimizations**\n\nRepeating ranges are now grouped using quantifiers. rocessing time is roughly the same, but the generated regex is much smaller, which should result in faster matching.\n\n## Attribution\n\nInspired by the python library [range-regex](https://github.com/dimka665/range-regex).\n\n## About\n\n<details>\n<summary><strong>Contributing</strong></summary>\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\n</details>\n\n<details>\n<summary><strong>Running Tests</strong></summary>\n\nRunning and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:\n\n```sh\n$ npm install && npm test\n```\n\n</details>\n\n<details>\n<summary><strong>Building docs</strong></summary>\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme && verb\n```\n\n</details>\n\n### Related projects\n\nYou might also be interested in these projects:\n\n* [expand-range](https://www.npmjs.com/package/expand-range): Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. Used… [more](https://github.com/jonschlinkert/expand-range) | [homepage](https://github.com/jonschlinkert/expand-range \"Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. Used by micromatch.\")\n* [fill-range](https://www.npmjs.com/package/fill-range): Fill in a range of numbers or letters, optionally passing an increment or `step` to… [more](https://github.com/jonschlinkert/fill-range) | [homepage](https://github.com/jonschlinkert/fill-range \"Fill in a range of numbers or letters, optionally passing an increment or `step` to use, or create a regex-compatible range with `options.toRegex`\")\n* [micromatch](https://www.npmjs.com/package/micromatch): Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. | [homepage](https://github.com/micromatch/micromatch \"Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch.\")\n* [repeat-element](https://www.npmjs.com/package/repeat-element): Create an array by repeating the given value n times. | [homepage](https://github.com/jonschlinkert/repeat-element \"Create an array by repeating the given value n times.\")\n* [repeat-string](https://www.npmjs.com/package/repeat-string): Repeat the given string n times. Fastest implementation for repeating a string. | [homepage](https://github.com/jonschlinkert/repeat-string \"Repeat the given string n times. Fastest implementation for repeating a string.\")\n\n### Contributors\n\n| **Commits** | **Contributor** |  \n| --- | --- |  \n| 63 | [jonschlinkert](https://github.com/jonschlinkert) |  \n| 3  | [doowb](https://github.com/doowb) |  \n| 2  | [realityking](https://github.com/realityking) |  \n\n### Author\n\n**Jon Schlinkert**\n\n* [GitHub Profile](https://github.com/jonschlinkert)\n* [Twitter Profile](https://twitter.com/jonschlinkert)\n* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)\n\nPlease consider supporting me on Patreon, or [start your own Patreon page](https://patreon.com/invite/bxpbvm)!\n\n<a href=\"https://www.patreon.com/jonschlinkert\">\n<img src=\"https://c5.patreon.com/external/logo/become_a_patron_button@2x.png\" height=\"50\">\n</a>\n\n### License\n\nCopyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert).\nReleased under the [MIT License](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on April 07, 2019._","readmeFilename":"README.md"}