{"name":"super-regex","version":"0.2.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":"./index.js","types":"./index.d.ts","engines":{"node":">=14.16"},"scripts":{"test":"xo && ava && tsd"},"keywords":["regex","regexp","regular","expression","timeout","time","out","cancel","expire","abort","redos","security","script","execute"],"dependencies":{"clone-regexp":"^3.0.0","function-timeout":"^0.1.0","time-span":"^5.1.0"},"devDependencies":{"ava":"^4.3.0","tsd":"^0.20.0","xo":"^0.49.0"},"gitHead":"2ec23494aa3628d434cdcb6492afdcb0ba1a4062","bugs":{"url":"https://github.com/sindresorhus/super-regex/issues"},"homepage":"https://github.com/sindresorhus/super-regex#readme","_id":"super-regex@0.2.0","_nodeVersion":"14.19.3","_npmVersion":"8.3.2","dist":{"integrity":"sha512-WZzIx3rC1CvbMDloLsVw0lkZVKJWbrkJ0k1ghKFmcnPrW1+jWbgTkTEWVtD9lMdmI4jZEz40+naBxl1dCUhXXw==","shasum":"dc1e071e55cdcf56930eb6271f73653a655b2642","tarball":"http://registry-npm.ywwl.com/super-regex/download/super-regex-0.2.0.tgz","fileCount":5,"unpackedSize":8013,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGqOr6PBq4TRSr1ZUDmuuLsyQ9mF0R0XbbPDOgCYvJIAAiEA62BBiKS+XziRh641DbJMetMIpKbIu2UW8BGa+i2h6xg="}],"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","size":3039,"noattachment":false,"key":"/super-regex/-/super-regex-0.2.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/super-regex_0.2.0_1657192087959_0.8323758941429744"},"_hasShrinkwrap":false,"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\nThe timeout only works in Node.js. In the browser, it will simply not time out.\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## 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#### options\n\nType: `object`\n\n##### timeout?\n\nType: `number` *(integer)*\n\nThe time in milliseconds to wait before timing out.\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","publish_time":1657192088211,"_cnpm_publish_time":1657192088211,"dist-tags":{"latest":"1.1.0"}}