@tb-dev/utils 7.1.1 → 7.2.0

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.
package/dist/index.js CHANGED
@@ -87,6 +87,10 @@ function sleep(ms) {
87
87
  return new Promise((resolve) => void setTimeout(resolve, ms));
88
88
  }
89
89
 
90
+ function timeout(f, ms) {
91
+ return Promise.race([f(), sleep(ms).then(() => null)]);
92
+ }
93
+
90
94
  function splitWhitespace(value, options = {}) {
91
95
  if (value) {
92
96
  if (Array.isArray(value)) {
@@ -104,4 +108,4 @@ function toPixel(value) {
104
108
  return value;
105
109
  }
106
110
 
107
- export { PromiseSet, flushPromises, isNil, noop, panic, sleep, splitWhitespace, toArray, toPixel, todo, trimArray, unimplemented, unreachable, unwrap, unwrapOr, unwrapOrElse, upsert };
111
+ export { PromiseSet, flushPromises, isNil, noop, panic, sleep, splitWhitespace, timeout, toArray, toPixel, todo, trimArray, unimplemented, unreachable, unwrap, unwrapOr, unwrapOrElse, upsert };
@@ -1,3 +1,4 @@
1
1
  export * from './flush-promises';
2
2
  export * from './promise-set';
3
3
  export * from './sleep';
4
+ export * from './timeout';
@@ -0,0 +1 @@
1
+ export declare function timeout<T>(f: () => Promise<T>, ms: number): Promise<T | null>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tb-dev/utils",
3
- "version": "7.1.1",
3
+ "version": "7.2.0",
4
4
  "description": "TypeScript utils",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -24,17 +24,17 @@
24
24
  "typescript"
25
25
  ],
26
26
  "devDependencies": {
27
- "@tb-dev/eslint-config": "^8.2.2",
28
- "@types/node": "^25.0.3",
29
- "@vitest/ui": "^4.0.16",
27
+ "@tb-dev/eslint-config": "^8.2.4",
28
+ "@types/node": "^25.1.0",
29
+ "@vitest/ui": "^4.0.18",
30
30
  "eslint": "^9.39.2",
31
31
  "tslib": "^2.8.1",
32
- "typedoc": "^0.28.15",
33
- "typedoc-plugin-mdn-links": "^5.0.10",
32
+ "typedoc": "^0.28.16",
33
+ "typedoc-plugin-mdn-links": "^5.1.1",
34
34
  "typescript": "^5.9.3",
35
- "vite": "^7.3.0",
35
+ "vite": "^7.3.1",
36
36
  "vite-plugin-dts": "^4.5.4",
37
- "vitest": "^4.0.16"
37
+ "vitest": "^4.0.18"
38
38
  },
39
39
  "files": [
40
40
  "dist"