UNPKG

telefunc

Version:

Remote functions. Instead of API.

34 lines (33 loc) 948 B
export { isProduction, getNodeEnv }; function isProduction() { // 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; }