UNPKG

yini-parser

Version:

Node.js parser for YINI — a clean, structured INI alternative with types, simple section nesting, comments, and strict mode.

63 lines (62 loc) 2.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.localAppEnv = exports.localNodeEnv = exports.isDebug = exports.isDev = exports.isTestEnv = exports.isProdEnv = exports.isDevEnv = void 0; const localNodeEnv = (process.env.NODE_ENV || 'production'); exports.localNodeEnv = localNodeEnv; const localAppEnv = (process.env.APP_ENV || 'production'); exports.localAppEnv = localAppEnv; // export const initEnvs = () => { // const localNodeEnv = (process.env.NODE_ENV || 'production') as TNodeEnv // const localAppEnv = (process.env?.APP_ENV || 'production') as TAppEnv // return { localNodeEnv, localAppEnv } // } // const { localNodeEnv, localAppEnv } = initEnvs() /** Are we running in the environment "development"? Will be based on the (global) environment variable process.env.NODE_ENV. */ const isDevEnv = () => localNodeEnv === 'development'; exports.isDevEnv = isDevEnv; /** Are we running in the environment "production"? Will be based on the (global) environment variable process.env.NODE_ENV. */ const isProdEnv = () => localNodeEnv === 'production'; exports.isProdEnv = isProdEnv; /** Are we running in the environment "test"? Will be based on the (global) variable process.env.NODE_ENV. */ const isTestEnv = () => localNodeEnv === 'test'; exports.isTestEnv = isTestEnv; /** Will be based on the local argument when this process was launched. * @returns True if the DEV flag is set. * @example npm run start -- isDev=1 * @example node dist/index.js isDev=1 */ const isDev = () => { const len = process.argv.length; // NOTE: We will start with index 2, since the first element will be // execPath. The second element will be the path to the // JavaScript file being executed. for (let i = 2; i < len; i++) { const val = process.argv[i] || ''; if (val.toLowerCase() === 'isdev=1' || val.toLowerCase() === 'isdev=true') { return true; } } return false; }; exports.isDev = isDev; /** Will be based on the local argument when this process was launched. * @returns True if the DEBUG flag is set. * @example npm run start -- isDebug=1 * @example node dist/index.js isDebug=1 */ const isDebug = () => { const len = process.argv.length; // NOTE: We will start with index 2, since the first element will be // execPath. The second element will be the path to the // JavaScript file being executed. for (let i = 2; i < len; i++) { const val = process.argv[i] || ''; if (val.toLowerCase() === 'isdebug=1' || val.toLowerCase() === 'isdebug=true') { return true; } } return false; }; exports.isDebug = isDebug;