@common.js/function-timeout 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +17 -4
  2. package/readme.md +0 -64
package/package.json CHANGED
@@ -1,11 +1,16 @@
1
1
  {
2
2
  "name": "@common.js/function-timeout",
3
- "version": "0.1.1",
4
- "description": "Make a synchronous function have a timeout",
3
+ "version": "0.1.2",
4
+ "description": "function-timeout package exported as CommonJS modules",
5
5
  "license": "MIT",
6
6
  "repository": "etienne-martin/common.js",
7
7
  "funding": "https://github.com/sponsors/sindresorhus",
8
8
  "type": "commonjs",
9
+ "exports": {
10
+ "types": "./index.d.ts",
11
+ "node": "./index.js",
12
+ "default": "./browser.js"
13
+ },
9
14
  "engines": {
10
15
  "node": ">=14.16"
11
16
  },
@@ -26,7 +31,15 @@
26
31
  },
27
32
  "homepage": "https://github.com/etienne-martin/common.js#readme",
28
33
  "dependencies": {},
29
- "types": "./index.d.ts",
34
+ "commonjs": {
35
+ "source": {
36
+ "name": "function-timeout",
37
+ "version": "0.1.1"
38
+ },
39
+ "transformRevision": 1,
40
+ "buildKey": "8929f06958d571aee903e24848ec6faf185ed8f31ce760b97eb2a75873a7e349"
41
+ },
42
+ "browser": "./browser.js",
30
43
  "main": "./index.js",
31
- "browser": "./browser.js"
44
+ "types": "./index.d.ts"
32
45
  }
package/readme.md DELETED
@@ -1,64 +0,0 @@
1
- # function-timeout
2
-
3
- > Make a synchronous function have a timeout
4
-
5
- This can be useful if you accept external data and want to ensure processing it does not take too long.
6
-
7
- The timeout only works in Node.js. When used in a browser, the function will be wrapped, but never time out.
8
-
9
- *I have a [different package](https://github.com/sindresorhus/super-regex) to prevent [ReDoS](https://en.wikipedia.org/wiki/ReDoS) for regexes.*
10
-
11
- ## Install
12
-
13
- ```sh
14
- npm install function-timeout
15
- ```
16
-
17
- ## Usage
18
-
19
- ```js
20
- import functionTimeout, {isTimeoutError} from 'function-timeout';
21
-
22
- const generateNumbers = count => {
23
- // Imagine this takes a long time.
24
- };
25
-
26
- const generateNumbersWithTimeout = functionTimeout(generateNumbers, {timeout: 100});
27
-
28
- try {
29
- console.log(generateNumbersWithTimeout(500));
30
- } catch (error) {
31
- if (isTimeoutError(error)) {
32
- console.error('Timed out');
33
- } else {
34
- throw error;
35
- }
36
- }
37
- ```
38
-
39
- ## API
40
-
41
- ### functionTimeout(function, options?)
42
-
43
- Returns a wrapped version of the given function that throws a timeout error if the execution takes longer than the given timeout.
44
-
45
- #### options
46
-
47
- Type: `object`
48
-
49
- ##### timeout?
50
-
51
- Type: `number` *(integer)*
52
-
53
- The time in milliseconds to wait before timing out.
54
-
55
- Keep in mind that execution time can vary between different hardware and Node.js versions. Set a generous timeout to avoid flakiness.
56
-
57
- ### isTimeoutError(error)
58
-
59
- Returns a boolean for whether the given error is a timeout error.
60
-
61
- ## Related
62
-
63
- - [super-regex](https://github.com/sindresorhus/super-regex) - Make a regular expression time out if it takes too long to execute
64
- - [p-timeout](https://github.com/sindresorhus/p-timeout) - Timeout a promise after a certain amount of time