{"name":"function-timeout","version":"0.1.0","description":"Make a synchronous function have a timeout","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/function-timeout.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","node":"./index.js","default":"./browser.js"},"engines":{"node":">=14.16"},"scripts":{"test":"xo && ava && tsd"},"keywords":["function","synchronous","timeout","time","out","cancel","expire","abort","regex","regexp","redos","security","func","fn","script","execute"],"devDependencies":{"ava":"^4.3.0","in-range":"^3.0.0","time-span":"^5.0.0","tsd":"^0.20.0","xo":"^0.49.0"},"types":"./index.d.ts","gitHead":"8ee023af773e121d970da212224fe21a3376a1ea","bugs":{"url":"https://github.com/sindresorhus/function-timeout/issues"},"homepage":"https://github.com/sindresorhus/function-timeout#readme","_id":"function-timeout@0.1.0","_nodeVersion":"14.19.2","_npmVersion":"8.3.2","dist":{"integrity":"sha512-P+OaGUVgyAJS3b9l2p1mHzAfjZhNLrZ0IcCzo+RY2mVWm15j6s75ck5p6j5ZLoVkVGki2X1L4lOiUkxLoCYpBg==","shasum":"ddbf013e9ab83bbe170a65589b6a233b0084bfa0","tarball":"http://registry-npm.ywwl.com/function-timeout/download/function-timeout-0.1.0.tgz","fileCount":6,"unpackedSize":5828,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEipPN73WEHn2hz/9goMr0hgcHe/STh73JnNCzfI26a7AiEAo/ZRg/sCjOpqTL27yvQIRhkYiFtQb8xIXTbt9KdMi5s="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJimds+ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrIBw/+MVvAVMhZPgZLXx+mZwNyoFHDhkUXddwUkf8Hsa+qJHYrX7ir\r\nYrJNX+sOj+H1Ko5tgiy5HmW9WXH0CQeban9LwcILpB4y74RHAM6FRD0Nf7mo\r\n9u6tlObPgpqTZLb4hv2B7PHK5doXgQc1KFZwVLhuak7ZA1UjH2TOQ53dXxAw\r\nHk7tccGeFLEEetlNAbFc0foN6lF8yDDCpNYzz72qm4kHa6X8OZmyD+ZsOO1n\r\nJZ49Itl+YA13I9LlFiRh8TXqvO+9OKmaZUQ5eXeeP8KrXtkTN09i9d6S/JBs\r\nveaXYfSqQHnAmeczyXKGE9PMu6P+nPFQkfmrE/E5LzK2h7rmWtZVfDaaQiVX\r\nvIMmvdmqVjPdC55/t5V5PfdOHXqnAQRn0THbpHYzrUclCM6fHxBpk+I6cx4S\r\nLCgxZOydt35wji4y0jiQQruuSaVXXBKB4tSaNQK9POU73y3h6GA/QkbaNzrq\r\nuVgs4vt80gZUsaJfl2AH65Ul34aD0v7YEDZLTZFozxLxQKgvUyjwIYvuIN+w\r\n7yuKTisoJzt6Rzuk8o0Lqa0+IGnVxebG+o6WT4fyB8yElPR/6sGTpo8bO12i\r\nmsH7kvADCE/u3l0zZSWU6mVBc0CGW9s/J7BW9RIXpHpu9B95We2JdCYxuTFp\r\npMcmDOKKcRqFS9S4nmXCmyL5RInOd1XBHTA=\r\n=8sFf\r\n-----END PGP SIGNATURE-----\r\n","size":2527,"noattachment":false,"key":"/function-timeout/-/function-timeout-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/function-timeout_0.1.0_1654250302461_0.9300863745963093"},"_hasShrinkwrap":false,"readme":"# function-timeout\n\n> Make a synchronous function have a timeout\n\nThis can be useful if you accept external data and want to ensure processing it does not take too long.\n\nThe timeout only works in Node.js. When used in a browser, the function will be wrapped, but never time out.\n\n*I have a [different package](https://github.com/sindresorhus/super-regex) to prevent [ReDoS](https://en.wikipedia.org/wiki/ReDoS) for regexes.*\n\n## Install\n\n```sh\nnpm install function-timeout\n```\n\n## Usage\n\n```js\nimport functionTimeout, {isTimeoutError} from 'function-timeout';\n\nconst generateNumbers = count => {\n\t// Imagine this takes a long time.\n};\n\nconst generateNumbersWithTimeout = functionTimeout(generateNumbers, {timeout: 100});\n\ntry {\n\tconsole.log(generateNumbersWithTimeout(500));\n} catch (error) {\n\tif (isTimeoutError(error)) {\n\t\tconsole.error('Timed out');\n\t} else {\n\t\tthrow error;\n\t}\n}\n```\n\n## API\n\n### functionTimeout(function, options?)\n\nReturns a wrapped version of the given function that throws a timeout error if the execution takes longer than the given timeout.\n\n#### options\n\nType: `object`\n\n##### timeout?\n\nType: `number` *(integer)*\n\nThe time in milliseconds to wait before timing out.\n\nKeep in mind that execution time can vary between different hardware and Node.js versions. Set a generous timeout to avoid flakiness.\n\n### isTimeoutError(error)\n\nReturns a boolean for whether the given error is a timeout error.\n\n## Related\n\n- [super-regex](https://github.com/sindresorhus/super-regex) - Make a regular expression time out if it takes too long to execute\n- [p-timeout](https://github.com/sindresorhus/p-timeout) - Timeout a promise after a certain amount of time\n","publish_time":1654250302569,"_cnpm_publish_time":1654250302569,"dist-tags":{"latest":"1.0.2"}}