UNPKG

topkat-utils

Version:

A comprehensive collection of TypeScript/JavaScript utility functions for common programming tasks. Includes validation, object manipulation, date handling, string formatting, and more. Zero dependencies, fully typed, and optimized for performance.

38 lines 1.3 kB
"use strict"; //---------------------------------------- // ENV UTILS //---------------------------------------- Object.defineProperty(exports, "__esModule", { value: true }); exports.ENV = exports.parseEnv = void 0; /** Parse one dimention object undefined, true, false, null represented as string will be converted to primitives */ function parseEnv(env) { const newEnv = {}; for (const k in env) { const val = env[k]; if (val === 'undefined') newEnv[k] = undefined; else if (val === 'true') newEnv[k] = true; else if (val === 'false') newEnv[k] = false; else if (val === 'null') newEnv[k] = null; else newEnv[k] = env[k]; } return newEnv; } exports.parseEnv = parseEnv; /** READ ONLY, get the environment variables (Eg. NODE_ENV) with parsed values ("true" => true, "4" => 4, "null" => null). On env variables all values are strings * use it like ENV().NODE_ENV */ function ENV() { const throwErr = () => { throw new Error('Please use process.env to write to env'); }; return new Proxy(parseEnv(process.env), { set: throwErr, defineProperty: throwErr, deleteProperty: throwErr, }); } exports.ENV = ENV; //# sourceMappingURL=env-utils.js.map