{"name":"super-regex","version":"0.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":"./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"},"devDependencies":{"ava":"^4.3.0","tsd":"^0.20.0","xo":"^0.49.0"},"gitHead":"690235582ec311c062c429f282d83705b5f0de6c","bugs":{"url":"https://github.com/sindresorhus/super-regex/issues"},"homepage":"https://github.com/sindresorhus/super-regex#readme","_id":"super-regex@0.1.0","_nodeVersion":"14.19.2","_npmVersion":"8.3.2","dist":{"integrity":"sha512-L2U77lcEufdx00TsUpveQy0RfcmFlEI7E1cewB9jg/wCCd4GQFs2eLUtarGL0m9e5l67MIRWp5hc6dUXnOPa+Q==","shasum":"7c15012feb1e26e6c64a333becffbd00fb6c6222","tarball":"http://registry-npm.ywwl.com/super-regex/download/super-regex-0.1.0.tgz","fileCount":5,"unpackedSize":6875,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCQ/dZ4YxdTGw1bUksyKtIRwQ8mcGTe7zXnV1scLntTVwIgOTm8p365JDMGrJAGtvtfeD4Wo9+VzwZatXZ31hjNd5s="}],"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","size":2603,"noattachment":false,"key":"/super-regex/-/super-regex-0.1.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.1.0_1654250835033_0.318311709612211"},"_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":1654250835252,"_cnpm_publish_time":1654250835252,"dist-tags":{"latest":"1.1.0"}}