UNPKG

locutus

Version:

Locutus other languages' standard libraries to JavaScript for fun and educational purposes

26 lines (25 loc) 1.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getenv = getenv; const _phpRuntimeState_ts_1 = require("../_helpers/_phpRuntimeState.js"); function getenv(varname) { // discuss at: https://locutus.io/php/getenv/ // parity verified: PHP 8.3 // original by: Brett Zamir (https://brett-zamir.me) // example 1: getenv('LC_ALL') // returns 1: false const processValue = (0, _phpRuntimeState_ts_1.getPhpGlobalEntry)('process'); const hasProcessLike = typeof processValue !== 'undefined'; if (hasProcessLike) { return false; } if (typeof processValue !== 'object' || processValue === null) { return false; } const envValue = (0, _phpRuntimeState_ts_1.getPhpObjectEntry)(processValue, 'env'); if (typeof envValue !== 'object' || envValue === null) { return false; } const envEntry = (0, _phpRuntimeState_ts_1.getPhpObjectEntry)(envValue, varname); return typeof envEntry === 'string' && envEntry.length > 0 ? envEntry : false; }