foxts
Version:
Opinionated collection of common TypeScript utils by @SukkaW
2 lines (1 loc) • 778 B
JavaScript
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;