@xylabs/platform
Advanced tools
Comparing version 4.0.10 to 4.1.0
import type { subtle as subtleType } from 'node:crypto'; | ||
export declare const isBrowser: () => boolean; | ||
export declare const isWebworker: () => boolean; | ||
export declare const getGlobal: <T extends object>() => typeof globalThis | T; | ||
export declare const subtle: typeof subtleType; | ||
//# sourceMappingURL=index.d.ts.map |
export { subtle } from 'node:crypto'; | ||
export declare const isBrowser: () => boolean; | ||
export declare const isWebworker: () => boolean; | ||
export declare const getGlobal: <T extends object>() => typeof globalThis | T; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@xylabs/platform", | ||
"version": "4.0.10", | ||
"version": "4.1.0", | ||
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries", | ||
@@ -49,6 +49,6 @@ "keywords": [ | ||
"devDependencies": { | ||
"@xylabs/ts-scripts-yarn3": "^4.0.7", | ||
"@xylabs/tsconfig": "^4.0.7", | ||
"@xylabs/tsconfig-dom": "^4.0.7", | ||
"typescript": "^5.5.4" | ||
"@xylabs/ts-scripts-yarn3": "^4.1.0", | ||
"@xylabs/tsconfig": "^4.1.0", | ||
"@xylabs/tsconfig-dom": "^4.1.0", | ||
"typescript": "^5.6.2" | ||
}, | ||
@@ -55,0 +55,0 @@ "engines": { |
import type { subtle as subtleType } from 'node:crypto' | ||
export const isBrowser = () => { | ||
return !isWebworker() && self.constructor?.name === 'Window' | ||
return !isWebworker() && globalThis.constructor?.name === 'Window' | ||
} | ||
export const isWebworker = () => { | ||
return typeof self === 'object' && self.constructor?.name === 'DedicatedWorkerGlobalScope' | ||
return typeof globalThis === 'object' && globalThis.constructor?.name === 'DedicatedWorkerGlobalScope' | ||
} | ||
export const getGlobal = <T extends object>() => | ||
isWebworker() | ||
? (self as unknown as T) | ||
: isBrowser() | ||
? (window as unknown as T) | ||
: globalThis | ||
export const subtle = getGlobal<Window>().crypto.subtle as typeof subtleType | ||
export const subtle = globalThis.crypto.subtle as typeof subtleType |
@@ -10,8 +10,1 @@ export { subtle } from 'node:crypto' | ||
} | ||
export const getGlobal = <T extends object>() => | ||
isBrowser() | ||
? (window as unknown as T) | ||
: isWebworker() | ||
? (self as unknown as T) | ||
: globalThis |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14733
76