UNPKG

advanced-js-kit

Version:

Modern TypeScript utility library with tree-shaking support - Array, String, Number, Network, Sleep, and JWT utilities for JavaScript and TypeScript projects

54 lines (52 loc) 1.74 kB
'use strict'; // src/universal/utils/index.ts function isNodeEnvironment() { return typeof process !== "undefined" && process.versions != null && process.versions.node != null; } function isBrowserEnvironment() { return typeof window !== "undefined" && typeof document !== "undefined"; } function isWebWorkerEnvironment() { return typeof globalThis.importScripts === "function" && typeof window === "undefined"; } function getEnvironment() { if (isNodeEnvironment()) return "node"; if (isBrowserEnvironment()) return "browser"; if (isWebWorkerEnvironment()) return "webworker"; return "unknown"; } var EnvironmentError = class extends Error { constructor(message, requiredEnvironment, currentEnvironment) { super(message); this.requiredEnvironment = requiredEnvironment; this.currentEnvironment = currentEnvironment; this.name = "EnvironmentError"; } }; function assertNodeEnvironment() { if (!isNodeEnvironment()) { throw new EnvironmentError( "This functionality requires Node.js environment", "node", getEnvironment() ); } } function assertBrowserEnvironment() { if (!isBrowserEnvironment()) { throw new EnvironmentError( "This functionality requires browser environment", "browser", getEnvironment() ); } } exports.EnvironmentError = EnvironmentError; exports.assertBrowserEnvironment = assertBrowserEnvironment; exports.assertNodeEnvironment = assertNodeEnvironment; exports.getEnvironment = getEnvironment; exports.isBrowserEnvironment = isBrowserEnvironment; exports.isNodeEnvironment = isNodeEnvironment; exports.isWebWorkerEnvironment = isWebWorkerEnvironment; //# sourceMappingURL=index.cjs.map //# sourceMappingURL=index.cjs.map