foxts 3.9.0 → 3.10.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.
@@ -0,0 +1,39 @@
1
+ interface NodeOSLike {
2
+ cpus(): any[];
3
+ availableParallelism?: () => number;
4
+ }
5
+ interface NavigatorLike {
6
+ hardwareConcurrency?: number;
7
+ }
8
+ /**
9
+ * Returns the number of available parallelism for the current platform.
10
+ *
11
+ * Usage:
12
+ *
13
+ * ```js
14
+ * // with a passed in Node.js os module
15
+ * import * as os from 'node:os';
16
+ * import availableParallelism from 'foxts/available-parallelism';
17
+ *
18
+ * availableParallelism(os); // number
19
+ *
20
+ * // In a browser environment, it can read navigator object
21
+ * import availableParallelism from 'foxts/available-parallelism';
22
+ * availableParallelism(navigator); // number
23
+ *
24
+ * // You can dynamic import of the Node.js os module
25
+ * import availableParallelism from 'foxts/available-parallelism';
26
+ * await availableParallelism(import('node:os')); // number
27
+ *
28
+ * // If you don't pass any arguments, it will automatically detect the environment
29
+ * import availableParallelism from 'foxts/available-parallelism';
30
+ * await availableParallelism(); // number
31
+ * ```
32
+ */
33
+ declare function availableParallelism(platform: NodeOSLike | NavigatorLike): number;
34
+ declare function availableParallelism(asyncNodeOS?: Promise<NodeOSLike>): Promise<number>;
35
+ declare function isNodeOSLike(platform: unknown): platform is NodeOSLike;
36
+ declare function isNavigatorLike(platform: unknown): platform is NavigatorLike;
37
+
38
+ export { availableParallelism, isNavigatorLike, isNodeOSLike };
39
+ export type { NavigatorLike, NodeOSLike };
@@ -0,0 +1 @@
1
+ function e(e){return"object"==typeof e&&null!==e&&"cpus"in e&&"function"==typeof e.cpus}function n(e){return"object"==typeof e&&null!==e&&"hardwareConcurrency"in e&&"number"==typeof e.hardwareConcurrency}function r(e){return"availableParallelism"in e&&"function"==typeof e.availableParallelism?e.availableParallelism():e.cpus().length||1}Object.defineProperty(exports,"__esModule",{value:!0}),exports.availableParallelism=function(a){return null==a?"object"==typeof window&&"navigator"in globalThis&&n(globalThis.navigator)?Promise.resolve(globalThis.navigator.hardwareConcurrency??1):import("node:os").then(n=>e(n)?r(n):1).catch(()=>1):e(a)?r(a):n(a)?a.hardwareConcurrency??1:"then"in a&&"function"==typeof a.then?a.then(r):1},exports.isNavigatorLike=n,exports.isNodeOSLike=e;
@@ -0,0 +1 @@
1
+ function n(n){return null==n?"object"==typeof window&&"navigator"in globalThis&&a(globalThis.navigator)?Promise.resolve(globalThis.navigator.hardwareConcurrency??1):import("node:os").then(n=>e(n)?r(n):1).catch(()=>1):e(n)?r(n):a(n)?n.hardwareConcurrency??1:"then"in n&&"function"==typeof n.then?n.then(r):1}function e(n){return"object"==typeof n&&null!==n&&"cpus"in n&&"function"==typeof n.cpus}function a(n){return"object"==typeof n&&null!==n&&"hardwareConcurrency"in n&&"number"==typeof n.hardwareConcurrency}function r(n){return"availableParallelism"in n&&"function"==typeof n.availableParallelism?n.availableParallelism():n.cpus().length||1}export{n as availableParallelism,a as isNavigatorLike,e as isNodeOSLike};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foxts",
3
- "version": "3.9.0",
3
+ "version": "3.10.0",
4
4
  "description": "Opinionated collection of common TypeScript utils by @SukkaW",
5
5
  "repository": {
6
6
  "url": "https://github.com/SukkaW/foxts"
@@ -212,6 +212,12 @@
212
212
  "import": "./dist/shuffle-array.mjs",
213
213
  "require": "./dist/shuffle-array.js",
214
214
  "default": "./dist/shuffle-array.js"
215
+ },
216
+ "./available-parallelism": {
217
+ "types": "./dist/available-parallelism.d.ts",
218
+ "import": "./dist/available-parallelism.mjs",
219
+ "require": "./dist/available-parallelism.js",
220
+ "default": "./dist/available-parallelism.js"
215
221
  }
216
222
  },
217
223
  "sideEffects": false,