UNPKG

telefunc

Version:

Remote functions. Instead of API.

39 lines (38 loc) 1.12 kB
export { isProduction }; export { getNodeEnv }; import { assertIsNotBrowser } from './assertIsNotBrowser.js'; assertIsNotBrowser(); function isProduction() { if (globalThis.__TELEFUNC__IS_NON_RUNNABLE_DEV) return false; // If the server environment isn't a Node.js server, then we assume an Edge environment (e.g. Cloudflare Workers) if (isNotNode()) return true; const val = getNodeEnv(); if (val === undefined || val === 'development' || val === '') return false; // We consider production if `val` is 'production', 'staging', 'test', etc. return true; } // Caching calls to process.env because it's expensive let nodeEnv; function getNodeEnv() { if (!nodeEnv) { if (isNotNode()) { nodeEnv = { value: null }; } else { nodeEnv = { value: process.env.NODE_ENV }; } } return nodeEnv.value; } let isNotNode_; function isNotNode() { if (!isNotNode_) { isNotNode_ = { value: typeof process == 'undefined' || !('env' in process), }; } return isNotNode_.value; }