quickload
Version:
A simple utility to load json config files.
114 lines (113 loc) • 3.38 kB
TypeScript
/**
* @fileoverview Environment checker utility module for detecting and validating runtime environments.
*
* This module provides utilities for:
* - Checking current environment type (development, production, test, staging, UAT)
* - Detecting server-side vs client-side execution context
* - Validating environment variables
* - Determining SSR (Server-Side Rendering) vs CSR (Client-Side Rendering) contexts
*
* The module supports various runtime environments and frameworks like Next.js, ensuring
* proper environment detection in both server and browser contexts.
*
* @example
* // Check current environment
* if (isDev) {
* console.log('Running in development mode');
* }
*
* // Check if running on server
* if (isServer) {
* console.log('Running on server');
* }
*
* // Validate environment variables
* if (isEnvVarDefined('API_KEY')) {
* console.log('API key is configured');
* }
*
* @module env.checker
*/
/**
* Supported environment types
*/
export type Environment = 'development' | 'production' | 'test' | 'staging' | 'uat';
/**
* Supported environment.
*
* development | production | test | staging | uat
*/
export declare const ENV: {
/** Where developers do their daily work */
readonly Development: "development";
/** The live environment where the application serves real users */
readonly Production: "production";
/** Used for automated tests and QA activities */
readonly Test: "test";
/** Mirrors production as closely as possible */
readonly Staging: "staging";
/** Where clients/stakeholders test new features */
readonly UAT: "uat";
};
/**
* Check if code is running in a browser environment.
* @returns {boolean} true if browser, otherwise false.
*/
export declare const isBrowser: boolean;
/**
* Check if code is running on the server.
* @returns {boolean} true if server, otherwise false.
*/
export declare const isServer: boolean;
/**
* Check current environment is development.
*
* @returns {boolean}: true if development, else false.
*/
export declare const isDev: boolean;
/**
* Check current environment is production.
*
* @returns {boolean}: true if production, else false.
*/
export declare const isProd: boolean;
/**
* Check current environment is test.
*
* @returns {boolean}: true if test, else false.
*/
export declare const isTest: boolean;
/**
* Check current environment is staging.
*
* @returns {boolean}: true if staging, else false.
*/
export declare const isStage: boolean;
/**
* Check current environment is uat (User Acceptance Testing).
*
* @returns {boolean}: true if uat, else false.
*/
export declare const isUat: boolean;
/**
* Check if the current execution is happening on the server during SSR.
*
* @returns {boolean}: true if server-side rendering, else false.
*/
export declare const isSSR: () => boolean;
/**
* Check if the current execution is happening on the client during CSR.
*
* @returns {boolean}: true if client-side rendering, else false.
*/
export declare const isCSR: () => boolean;
/**
* Check if a specific environment variable is defined.
*
* @example
* isEnvVarDefined('API_URL');
*
* @param {string} key The environment variable name.
* @returns {boolean}: true if the environment variable is defined, else false.
*/
export declare const isEnvVarDefined: (key: string) => boolean;