{"name":"function-timeout","version":"1.0.2","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"},"_id":"function-timeout@1.0.2","gitHead":"12471c7f085b034c3b2432a223376e60173ec43a","types":"./index.d.ts","bugs":{"url":"https://github.com/sindresorhus/function-timeout/issues"},"homepage":"https://github.com/sindresorhus/function-timeout#readme","_nodeVersion":"22.1.0","_npmVersion":"10.6.0","dist":{"integrity":"sha512-939eZS4gJ3htTHAldmyyuzlrD58P03fHG49v2JfFXbV6OhvZKRC9j2yAtdHw/zrp2zXHuv05zMIy40F0ge7spA==","shasum":"e5a7b6ffa523756ff20e1231bbe37b5f373aadd5","tarball":"http://registry-npm.ywwl.com/function-timeout/download/function-timeout-1.0.2.tgz","fileCount":6,"unpackedSize":6115,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIQC9uWZVCW5+1NN3WCiIuvBMkRutFxQ7rG44Y2fLEWWl1AIfBtg9mEwZQp0SEZj2vFi92s9dN1am853+WdwoHctXjw=="}],"size":2654,"noattachment":false,"key":"/function-timeout/-/function-timeout-1.0.2.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.2_1715967003799_0.03519201814812045"},"_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":1715967003940,"_cnpm_publish_time":1715967003940,"dist-tags":{"latest":"1.0.2"}}