@gotake/gotake-sdk
Version:
SDK for interacting with GoTake blockchain contracts
45 lines (44 loc) • 1.31 kB
JavaScript
;
/**
* Safe environment detection utilities
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.isNodeEnvironment = isNodeEnvironment;
exports.isBrowserEnvironment = isBrowserEnvironment;
exports.hasEnvironmentVariables = hasEnvironmentVariables;
exports.getEnvironmentVariable = getEnvironmentVariable;
/**
* Check if running in Node.js environment
*/
function isNodeEnvironment() {
return typeof process !== 'undefined' &&
process.versions != null &&
process.versions.node != null;
}
/**
* Check if running in browser environment
*/
function isBrowserEnvironment() {
return typeof window !== 'undefined' && typeof document !== 'undefined';
}
/**
* Check if environment variables are available
*/
function hasEnvironmentVariables() {
return isNodeEnvironment() &&
typeof process !== 'undefined' &&
typeof process['env'] === 'object';
}
/**
* Safe environment variable getter
*/
function getEnvironmentVariable(key, defaultValue) {
if (!hasEnvironmentVariables()) {
return defaultValue;
}
// Additional safety check before accessing environment variables
if (typeof process === 'undefined' || !process['env']) {
return defaultValue;
}
return process['env'][key] || defaultValue;
}