UNPKG

game-analysis-types

Version:

Common TypeScript types and utilities for game analysis tools.

58 lines 1.73 kB
/** * Service for managing environment variables */ export class EnvironmentService { static instance; static getInstance() { if (!EnvironmentService.instance) { EnvironmentService.instance = new EnvironmentService(); } return EnvironmentService.instance; } getVariable(key) { // Only use process.env for backend compatibility if (typeof process !== 'undefined' && process.env && process.env[key] !== undefined) { return process.env[key]; } return undefined; } /** * Alias for getVariable for backward compatibility */ get(key, defaultValue = '') { return this.getVariable(key) || defaultValue; } /** * Set an environment variable (mainly for testing) * @param key - The environment variable key * @param value - The value to set */ setVariable(key, value) { if (typeof process !== 'undefined' && process.env) { process.env[key] = value; } } /** * Check if an environment variable is defined * @param key - The environment variable key * @returns True if defined, false otherwise */ hasVariable(key) { return this.getVariable(key) !== undefined; } /** * Check if the environment is development * @returns True if development environment */ isDevelopment() { return this.getVariable('NODE_ENV') === 'development'; } /** * Check if the environment is production * @returns True if production environment */ isProduction() { return this.getVariable('NODE_ENV') === 'production'; } } //# sourceMappingURL=EnvironmentService.js.map