@settlemint/sdk-utils
Version:
Shared utilities and helper functions for SettleMint SDK modules
45 lines (43 loc) • 1.31 kB
JavaScript
import { isBrowser } from "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 (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 (!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 = isBrowser;
/**
* Boolean indicating if code is currently running in a server environment
*/
const runsOnServer = !isBrowser;
//#endregion
export { ensureBrowser, ensureServer, runsInBrowser, runsOnServer };
//# sourceMappingURL=runtime.js.map