UNPKG

@techmely/utils

Version:

Collection of helpful JavaScript / TypeScript utils

72 lines (65 loc) 1.53 kB
'use strict'; /*! * @techmely/utils * Copyright(c) 2021-2024 Techmely <techmely.creation@gmail.com> * MIT Licensed */ // src/env.ts var _envShim = /* @__PURE__ */ Object.create(null); var _getEnv = (useShim) => globalThis.process?.env || // Node.js/Bun undefined || // Vite env globalThis.Deno?.env.toObject() || // Deno env globalThis.__env__ || // Custom env (useShim ? _envShim : globalThis); function envShims() { return new Proxy(_envShim, { get(_, prop) { const env = _getEnv(); return env[prop] ?? _envShim[prop]; }, has(_, prop) { const env = _getEnv(); return prop in env || prop in _envShim; }, set(_, prop, value) { const env = _getEnv(true); env[prop] = value; return true; }, deleteProperty(_, prop) { if (!prop) { return false; } const env = _getEnv(true); delete env[prop]; return true; }, ownKeys() { const env = _getEnv(); return Object.keys(env); } }); } // src/process.ts var _process = globalThis.process || /* @__PURE__ */ Object.create(null); var processShims = { versions: {} }; var globProcess = new Proxy(_process, { get(target, prop) { if (prop === "env") { return envShims(); } if (prop in target) { return target[prop]; } if (prop in processShims) { return processShims[prop]; } } }); // src/isMacOs.ts function isMacOS() { return /^darwin/i.test(globProcess.platform || ""); } exports.isMacOS = isMacOS;