Skip to content

Instantly share code, notes, and snippets.

@emeraldsanto
Created August 4, 2020 02:04
Show Gist options
  • Save emeraldsanto/d947e4c92d9f4922c2cf71ebbd69e299 to your computer and use it in GitHub Desktop.
Save emeraldsanto/d947e4c92d9f4922c2cf71ebbd69e299 to your computer and use it in GitHub Desktop.
Utility class providing getters for the current environment file
import env from "../../env.json";
/**
* Wrapper over the current environment file, provides
* utility methods to query the file without having to import it manually
*/
export class Environment {
/**
* Checks wether or not the app is running in debug mode
*/
static isDebug(): boolean {
return !!__DEV__;
}
/**
* Checks wether or not the app is running in release mode
*/
static isRelease(): boolean {
return !Environment.isDebug();
}
/**
* Checks wether or not the current environment is `DEVELOPMENT`
*/
static isDevelopment(): boolean {
return env.name === "DEVELOPMENT";
}
/**
* Checks wether or not the current environment is `STAGING`
*/
static isStaging(): boolean {
return env.name === "STAGING";
}
/**
* Checks wether or not the current environment is `PRODUCTION`
*/
static isProduction(): boolean {
return env.name === "PRODUCTION";
}
/**
* Gets the environment name
* @returns {"DEVELOPMENT" | "STAGING" | "PRODUCTION"}
*/
static getName(): string {
return env.name;
}
/**
* Gets the environment specific values
*/
static getValues(): typeof env.values {
return env.values;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment