UNPKG

@settlemint/sdk-utils

Version:

Shared utilities and helper functions for SettleMint SDK modules

48 lines (46 loc) 1.45 kB
let environment = require("environment"); //#region src/runtime/ensure-server.ts /** * Ensures that code is running on the server and not in a browser environment. * * @throws {Error} If called from a browser environment * @example * import { ensureServer } from "@settlemint/sdk-utils/runtime"; * * // Will throw if running in browser * ensureServer(); */ function ensureServer() { if (environment.isBrowser) { throw new Error("This function can only be used on the server as including it in the browser will expose your access token."); } } /** * Ensures that code is running in a browser environment and not on the server. * * @throws {Error} If called from a server environment * @example * import { ensureBrowser } from "@settlemint/sdk-utils/runtime"; * * // Will throw if running on server * ensureBrowser(); */ function ensureBrowser() { if (!environment.isBrowser) { throw new Error("This function can only be used on the browser as it is missing the access token."); } } /** * Boolean indicating if code is currently running in a browser environment */ const runsInBrowser = environment.isBrowser; /** * Boolean indicating if code is currently running in a server environment */ const runsOnServer = !environment.isBrowser; //#endregion exports.ensureBrowser = ensureBrowser; exports.ensureServer = ensureServer; exports.runsInBrowser = runsInBrowser; exports.runsOnServer = runsOnServer; //# sourceMappingURL=runtime.cjs.map