{"name":"function-timeout","version":"1.0.1","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"},"sideEffects":false,"engines":{"node":">=18"},"scripts":{"test":"xo && ava && tsd"},"keywords":["function","synchronous","timeout","time","out","cancel","expire","abort","regex","regexp","redos","security","func","fn","script","execute","halt","termination"],"devDependencies":{"ava":"^5.3.1","in-range":"^3.0.0","time-span":"^5.1.0","tsd":"^0.29.0","xo":"^0.56.0"},"types":"./index.d.ts","gitHead":"dcf1b5c856557450a1122c4dd5f4498d2645001f","bugs":{"url":"https://github.com/sindresorhus/function-timeout/issues"},"homepage":"https://github.com/sindresorhus/function-timeout#readme","_id":"function-timeout@1.0.1","_nodeVersion":"18.18.2","_npmVersion":"9.2.0","dist":{"integrity":"sha512-6yPMImFFuaMPNaTMTBuolA8EanHJWF5Vju0NHpObRURT105J6x1Mf2a7J4P7Sqk2xDxv24N5L0RatEhTBhNmdA==","shasum":"fd379f96501e536617a89ae080d44539ed805f63","tarball":"http://registry-npm.ywwl.com/function-timeout/download/function-timeout-1.0.1.tgz","fileCount":6,"unpackedSize":6114,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHvzWh4l7SMmpQ/HYhizA8iM1AyAUxUQ1O7Kgo8AtsV5AiEAtueHszwtJK5Q19c9fgMIhV6GCi3WnndV6HuvdKLbbU0="}],"size":2650,"noattachment":false,"key":"/function-timeout/-/function-timeout-1.0.1.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_1.0.1_1699558758958_0.2950830782318752"},"_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":1699558759141,"_cnpm_publish_time":1699558759141,"dist-tags":{"latest":"1.0.2"}}