{"_id":"super-regex","_rev":"5-baf7a181cc845e42fdab53fcb3aa61e1","name":"super-regex","dist-tags":{"latest":"1.1.0"},"versions":{"0.1.0":{"name":"super-regex","version":"0.1.0","keywords":["regex","regexp","regular","expression","timeout","time","out","cancel","expire","abort","redos","security","script","execute"],"author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"license":"MIT","_id":"super-regex@0.1.0","maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"homepage":"https://github.com/sindresorhus/super-regex#readme","bugs":{"url":"https://github.com/sindresorhus/super-regex/issues"},"dist":{"shasum":"7c15012feb1e26e6c64a333becffbd00fb6c6222","tarball":"https://registry.npmjs.org/super-regex/-/super-regex-0.1.0.tgz","fileCount":5,"integrity":"sha512-L2U77lcEufdx00TsUpveQy0RfcmFlEI7E1cewB9jg/wCCd4GQFs2eLUtarGL0m9e5l67MIRWp5hc6dUXnOPa+Q==","signatures":[{"sig":"MEUCIQCQ/dZ4YxdTGw1bUksyKtIRwQ8mcGTe7zXnV1scLntTVwIgOTm8p365JDMGrJAGtvtfeD4Wo9+VzwZatXZ31hjNd5s=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":6875,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJimd1TACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq+nw/+I6Qdd0Gm3kJKluPu11W4FKVUoKgnIyE7xzJ6epDx6oLcKSQo\r\nxZu8F6g1ilQnR9yEBoFYa9AU+uAIaCNPAwD1W5q1wmFAltzeVfB9/QAVlwwg\r\nBQWVbudeFckxJtlTXeuCvpTKpdSvvI/RClUdR/itA/kOWYSR+zgQruFZrZ8E\r\nch9UsG/vmHD+xhzVDvw6mN1esZd9OrMEDq6nhjzSF6SmrrdJozCawdQiimjc\r\nk8Zz0rzSlMBYSdhpeMCuVlMndQ5BPGTVfNWwWZsJba3mvxEr7ZH8SxO2ZIK8\r\nJJCyWWdZ7MhN2eOqqmcv+KlIFqJbf+/L+8q67qKGFS6DScpLJbWs8wjpiTVq\r\n78cKSr4o8CErdMBZGfLiavEdvsiazSDoB2XPTCicir9qyB9frSl1EZ6IOu5C\r\nEk/t8I+fL7g2jcPRcEir+FuzJzisUm9r1e9AWMi4SRSK1YkjEROtTtCSqgjS\r\nYwf2lKoTakcnYVntq8WXrwBeW/EhlXnYir2Hv7sK2bzbs2VX7HVK2/Qqzv4F\r\n09dNU5qzv/mXN5ObJbDs1qttRDe4IK+4f98xAXZo1ush3KxICHF8aaI/Phxs\r\nRinRePVI8QDK7oWZLDlPzTYiiGCBgbjoyvjtOn9pjHIsnpfvDZDtRvjaKscL\r\n428z2w0k7Pc04Kmpf33uecYO9di4CE5KFk0=\r\n=/dOs\r\n-----END PGP SIGNATURE-----\r\n"},"type":"module","types":"./index.d.ts","engines":{"node":">=14.16"},"exports":"./index.js","funding":"https://github.com/sponsors/sindresorhus","gitHead":"690235582ec311c062c429f282d83705b5f0de6c","scripts":{"test":"xo && ava && tsd"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"repository":{"url":"git+https://github.com/sindresorhus/super-regex.git","type":"git"},"_npmVersion":"8.3.2","description":"Make a regular expression time out if it takes too long to execute","directories":{},"_nodeVersion":"14.19.2","dependencies":{"clone-regexp":"^3.0.0","function-timeout":"^0.1.0"},"_hasShrinkwrap":false,"devDependencies":{"xo":"^0.49.0","ava":"^4.3.0","tsd":"^0.20.0"},"_npmOperationalInternal":{"tmp":"tmp/super-regex_0.1.0_1654250835033_0.318311709612211","host":"s3://npm-registry-packages"}},"0.2.0":{"name":"super-regex","version":"0.2.0","keywords":["regex","regexp","regular","expression","timeout","time","out","cancel","expire","abort","redos","security","script","execute"],"author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"license":"MIT","_id":"super-regex@0.2.0","maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"homepage":"https://github.com/sindresorhus/super-regex#readme","bugs":{"url":"https://github.com/sindresorhus/super-regex/issues"},"dist":{"shasum":"dc1e071e55cdcf56930eb6271f73653a655b2642","tarball":"https://registry.npmjs.org/super-regex/-/super-regex-0.2.0.tgz","fileCount":5,"integrity":"sha512-WZzIx3rC1CvbMDloLsVw0lkZVKJWbrkJ0k1ghKFmcnPrW1+jWbgTkTEWVtD9lMdmI4jZEz40+naBxl1dCUhXXw==","signatures":[{"sig":"MEUCIGqOr6PBq4TRSr1ZUDmuuLsyQ9mF0R0XbbPDOgCYvJIAAiEA62BBiKS+XziRh641DbJMetMIpKbIu2UW8BGa+i2h6xg=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":8013,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJixr6YACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoNixAAlAfw4/yAFE01PaKFEoAa5D6JTGitwVNy9OfPGit7X5dVSuPT\r\na4fn1BUMh4Qi+xfVcfX9IbC4uFgFTi9t1xGyeD4q2lBjON2WDzoZD3Tov5r0\r\nPpQ5ZryOIlyIdxm+v8XprsDbv6h+2LQSFm/vSrqB7iIotAejOt/GsWIhvOAZ\r\nl92ABilhSVbz7q68TDzspkdw9pa3d7OCyq79qUwhuJqMkro25/81xw3aqvCn\r\nO4d1blWtsI4ICh+twRWaTDFBJKqf/c2y6m/iBQuk+b8pGO3paKHkD49J9pp/\r\nOLyBonAtDMHhUTKHNQRVulsBiHFvi/SBo6HoRswC38VGI308hmH9VjavRn9i\r\nVC49KduAIKSPIGPe2X5hFxgA/FfgQXCZDldqU2MUE72ROoNSBxnx3v+zz/Qn\r\nzi/JWYzPHcQLvplrl8UFKXxoPk/rCKctqqgkZm5dmMfXZxCH976cY5jLiXiA\r\nLrpYSz70R2ReajvCMa4LnxCGly6ojQqSAaC1y4gthlaE4JOsdTM6rh4bVYXj\r\nH+Y7WsQve+LykMmrTek4K07BIVUAtl1fd9Mjn9IDNAhzGM4UUjBR7G6jLu0/\r\nt8Yfn6OzCzBkMhCOGhdWJ5oxEi/WgtOtD8m+3NTeNvrMpaFxM2IGB4OaR3vz\r\nh+UNTVropMH67/dOLxyi2HlOmAWLgUIzH/4=\r\n=Uw8r\r\n-----END PGP SIGNATURE-----\r\n"},"type":"module","types":"./index.d.ts","engines":{"node":">=14.16"},"exports":"./index.js","funding":"https://github.com/sponsors/sindresorhus","gitHead":"2ec23494aa3628d434cdcb6492afdcb0ba1a4062","scripts":{"test":"xo && ava && tsd"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"repository":{"url":"git+https://github.com/sindresorhus/super-regex.git","type":"git"},"_npmVersion":"8.3.2","description":"Make a regular expression time out if it takes too long to execute","directories":{},"_nodeVersion":"14.19.3","dependencies":{"time-span":"^5.1.0","clone-regexp":"^3.0.0","function-timeout":"^0.1.0"},"_hasShrinkwrap":false,"devDependencies":{"xo":"^0.49.0","ava":"^4.3.0","tsd":"^0.20.0"},"_npmOperationalInternal":{"tmp":"tmp/super-regex_0.2.0_1657192087959_0.8323758941429744","host":"s3://npm-registry-packages"}},"0.3.0":{"name":"super-regex","version":"0.3.0","keywords":["regex","regexp","regular","expression","timeout","time","out","cancel","expire","abort","redos","security","script","execute"],"author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"license":"MIT","_id":"super-regex@0.3.0","maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"homepage":"https://github.com/sindresorhus/super-regex#readme","bugs":{"url":"https://github.com/sindresorhus/super-regex/issues"},"dist":{"shasum":"ffbacf605bdde6e03cecf17d5f818c4c7a3662dc","tarball":"https://registry.npmjs.org/super-regex/-/super-regex-0.3.0.tgz","fileCount":5,"integrity":"sha512-ZpZxS+UwxXb4W/k7qrssgkv6e/U0161NOKRFan1D9VfcF9UZBxw2KZSyL6SDdWx/CATbkiuREDRymUzTpilPyg==","signatures":[{"sig":"MEUCIGKs5sdGye/TKsNXpY0C0ZGeSH5/b8xt45hVnVIVt5cZAiEA+pSzY9lh3NWvxlVQrwD3NS+kmTl8fLigHb7SwqcujAw=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":8038},"type":"module","types":"./index.d.ts","engines":{"node":">=18"},"exports":{"types":"./index.d.ts","default":"./index.js"},"funding":"https://github.com/sponsors/sindresorhus","gitHead":"20370f196503b0775d95ed9e1cfc18190d0bc12b","scripts":{"test":"xo && ava && tsd","benchmark":"node benchmark/index.js"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"repository":{"url":"git+https://github.com/sindresorhus/super-regex.git","type":"git"},"_npmVersion":"9.2.0","description":"Make a regular expression time out if it takes too long to execute","directories":{},"sideEffects":false,"_nodeVersion":"18.18.2","dependencies":{"time-span":"^5.1.0","function-timeout":"^1.0.1"},"_hasShrinkwrap":false,"devDependencies":{"xo":"^0.56.0","ava":"^5.3.1","tsd":"^0.29.0"},"_npmOperationalInternal":{"tmp":"tmp/super-regex_0.3.0_1699784033683_0.9400856325730906","host":"s3://npm-registry-packages"}},"1.0.0":{"name":"super-regex","version":"1.0.0","keywords":["regex","regexp","regular","expression","timeout","time","out","cancel","expire","abort","redos","security","script","execute"],"author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"license":"MIT","_id":"super-regex@1.0.0","maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"homepage":"https://github.com/sindresorhus/super-regex#readme","bugs":{"url":"https://github.com/sindresorhus/super-regex/issues"},"dist":{"shasum":"dd90d944a925a1083e7d8570919b21cb76e3d925","tarball":"https://registry.npmjs.org/super-regex/-/super-regex-1.0.0.tgz","fileCount":5,"integrity":"sha512-CY8u7DtbvucKuquCmOFEKhr9Besln7n9uN8eFbwcoGYWXOMW07u2o8njWaiXt11ylS3qoGF55pILjRmPlbodyg==","signatures":[{"sig":"MEQCIFUR00RjKA/8/f2XFJ8/0lRcfjN7AWazUZ2p5NwmaOnDAiAq7LlVbtX4avQ/S3wKz81nK4vFT483peAhopvPnG04OQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":8038},"type":"module","types":"./index.d.ts","engines":{"node":">=18"},"exports":{"types":"./index.d.ts","default":"./index.js"},"funding":"https://github.com/sponsors/sindresorhus","gitHead":"fba5633210483b33c26a106bf54a8e051d6fa8df","scripts":{"test":"xo && ava && tsd","benchmark":"node benchmark/index.js"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"repository":{"url":"git+https://github.com/sindresorhus/super-regex.git","type":"git"},"_npmVersion":"9.2.0","description":"Make a regular expression time out if it takes too long to execute","directories":{},"sideEffects":false,"_nodeVersion":"18.19.1","dependencies":{"time-span":"^5.1.0","function-timeout":"^1.0.1"},"_hasShrinkwrap":false,"devDependencies":{"xo":"^0.58.0","ava":"^6.1.2","tsd":"^0.31.0"},"_npmOperationalInternal":{"tmp":"tmp/super-regex_1.0.0_1712131451947_0.7153223594159954","host":"s3://npm-registry-packages"}},"1.1.0":{"name":"super-regex","version":"1.1.0","description":"Make a regular expression time out if it takes too long to execute","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/super-regex.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","default":"./index.js"},"sideEffects":false,"engines":{"node":">=18"},"scripts":{"test":"xo && node --test && tsd","benchmark":"node benchmark/index.js"},"keywords":["regex","regexp","regular","expression","timeout","time","out","cancel","expire","abort","redos","security","script","execute","async","asynchronous","worker","non-blocking"],"dependencies":{"function-timeout":"^1.0.1","make-asynchronous":"^1.0.1","time-span":"^5.1.0"},"devDependencies":{"tsd":"^0.31.0","xo":"^0.58.0"},"gitHead":"50f4b43a9e141b86ff7025c407596b5fed8ed965","types":"./index.d.ts","_id":"super-regex@1.1.0","bugs":{"url":"https://github.com/sindresorhus/super-regex/issues"},"homepage":"https://github.com/sindresorhus/super-regex#readme","_nodeVersion":"20.19.5","_npmVersion":"11.6.1","dist":{"integrity":"sha512-WHkws2ZflZe41zj6AolvvmaTrWds/VuyeYr9iPVv/oQeaIoVxMKaushfFWpOGDT+GuBrM/sVqF8KUCYQlSSTdQ==","shasum":"14b69b6374f7b3338db52ecd511dae97c27acf75","tarball":"https://registry.npmjs.org/super-regex/-/super-regex-1.1.0.tgz","fileCount":5,"unpackedSize":18640,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIEpgoChx51tNsOnKdkJ8BgvmpapJrZHceJrt0LPsC6NyAiEAy20IxA+K3/2zhDAXnpCE+kKP4ONW+9WeVELsuBqLHa4="}]},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/super-regex_1.1.0_1762248612588_0.37291710401512645"},"_hasShrinkwrap":false}},"time":{"created":"2022-06-03T10:07:15.032Z","modified":"2025-11-04T09:30:12.968Z","0.1.0":"2022-06-03T10:07:15.252Z","0.2.0":"2022-07-07T11:08:08.211Z","0.3.0":"2023-11-12T10:13:53.888Z","1.0.0":"2024-04-03T08:04:12.209Z","1.1.0":"2025-11-04T09:30:12.779Z"},"bugs":{"url":"https://github.com/sindresorhus/super-regex/issues"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"license":"MIT","homepage":"https://github.com/sindresorhus/super-regex#readme","keywords":["regex","regexp","regular","expression","timeout","time","out","cancel","expire","abort","redos","security","script","execute","async","asynchronous","worker","non-blocking"],"repository":{"type":"git","url":"git+https://github.com/sindresorhus/super-regex.git"},"description":"Make a regular expression time out if it takes too long to execute","maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"readme":"# super-regex\n\n> Make a regular expression time out if it takes too long to execute\n\nThis can be used to prevent [ReDoS vulnerabilities](https://en.wikipedia.org/wiki/ReDoS) when running a regular expression against untrusted user input.\n\nThis package also has a better API than the built-in regular expression methods. For example, none of the methods mutate the regex.\n\n**Synchronous methods** (`isMatch`, `firstMatch`, `matches`) use a timeout mechanism that only works in Node.js. In the browser, they will not time out.\n\n**Asynchronous methods** (`isMatchAsync`, `firstMatchAsync`, `matchesAsync`) run the regex in a worker thread and support timeout in both Node.js and browsers. They are especially useful for preventing ReDoS attacks in browser environments and for non-blocking execution in servers.\n\n## Install\n\n```sh\nnpm install super-regex\n```\n\n## Usage\n\n```js\nimport {isMatch} from 'super-regex';\n\nconsole.log(isMatch(/\\d+/, getUserInput(), {timeout: 1000}));\n```\n\n```js\nimport {isMatchAsync} from 'super-regex';\n\nconsole.log(await isMatchAsync(/\\d+/, getUserInput(), {timeout: 1000}));\n```\n\n## API\n\n### isMatch(regex, string, options?)\n\nReturns a boolean for whether the given `regex` matches the given `string`.\n\nIf the regex takes longer to match than the given timeout, it returns `false`.\n\n*This method is similar to [`RegExp#test`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test), but differs in that the given `regex` is [never mutated, even when it has the `/g` flag](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test#using_test_on_a_regex_with_the_global_flag).*\n\n### firstMatch(regex, string, options?)\n\nReturns the first `Match` or `undefined` if there was no match.\n\nIf the regex takes longer to match than the given timeout, it returns `undefined`.\n\n### matches(regex, string, options?)\n\nReturns an iterable of `Match`es.\n\nIf the regex takes longer to match than the given timeout, it returns an empty array.\n\n**The `regex` must have the `/g` flag.**\n\n### isMatchAsync(regex, string, options?)\n\nReturns a promise that resolves to a boolean for whether the given `regex` matches the given `string`.\n\nIf the regex takes longer to match than the given timeout, it returns `false`.\n\nThis method runs the regex in a worker thread, which allows it to time out in both Node.js and browsers. This is especially useful for preventing ReDoS attacks in browser environments.\n\n*This method is similar to [`RegExp#test`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test), but differs in that the given `regex` is [never mutated, even when it has the `/g` flag](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test#using_test_on_a_regex_with_the_global_flag).*\n\n```js\nimport {isMatchAsync} from 'super-regex';\n\nconsole.log(await isMatchAsync(/\\d+/, getUserInput(), {timeout: 1000}));\n```\n\n### firstMatchAsync(regex, string, options?)\n\nReturns a promise that resolves to the first match or `undefined` if there was no match.\n\nIf the regex takes longer to match than the given timeout, it returns `undefined`.\n\nThis method runs the regex in a worker thread, which allows it to time out in both Node.js and browsers. This is especially useful for preventing ReDoS attacks in browser environments.\n\n```js\nimport {firstMatchAsync} from 'super-regex';\n\nconsole.log(await firstMatchAsync(/\\d+/, getUserInput(), {timeout: 1000}));\n```\n\n### matchesAsync(regex, string, options?)\n\nReturns an async iterable of matches.\n\nIf the regex takes longer to match than the given timeout, it returns an empty iterable.\n\nThis method runs the regex in a worker thread, which allows it to time out in both Node.js and browsers. This is especially useful for preventing ReDoS attacks in browser environments.\n\n**The `regex` must have the `/g` flag.**\n\n```js\nimport {matchesAsync} from 'super-regex';\n\nfor await (const match of matchesAsync(/\\d+/g, getUserInput(), {timeout: 1000})) {\n\tconsole.log(match);\n}\n```\n\n#### options\n\nType: `object`\n\n##### timeout?\n\nType: `number` *(integer)*\n\nThe time in milliseconds to wait before timing out.\n\n##### throwOnTimeout?\n\nType: `boolean`\\\nDefault: `false`\n\nThrow a timeout error instead of returning a default value when the timeout is reached.\n\nThis lets you distinguish between “no match” and “timeout”.\n\nBy default, when a timeout occurs:\n- `isMatch()` returns `false`\n- `firstMatch()` returns `undefined`\n- `matches()` returns an empty array\n- `isMatchAsync()` returns `false`\n- `firstMatchAsync()` returns `undefined`\n- `matchesAsync()` returns an empty iterable\n\n##### matchTimeout?\n\nType: `number` *(integer)*\n\nOnly works in `matches()`.\n\nThe time in milliseconds to wait before timing out when searching for each match.\n\n### Match\n\n```ts\n{\n\tmatch: string;\n\tindex: number;\n\tgroups: string[];\n\tnamedGroups: {string: string}; // object with string values\n\tinput: string;\n}\n```\n\n## Related\n\n- [function-timeout](https://github.com/sindresorhus/function-timeout) - Make a synchronous function have a timeout\n","readmeFilename":"readme.md"}