diff --git a/lib/os.js b/lib/os.js index 09a70d2f7b19e5..ace39c8e120397 100644 --- a/lib/os.js +++ b/lib/os.js @@ -40,7 +40,7 @@ const { getOSType: _getOSType, getPriority: _getPriority, getTotalMem, - getUserInfo: _getUserInfo, + getUserInfo, getUptime, isBigEndian, setPriority: _setPriority @@ -64,7 +64,6 @@ const getHostname = getCheckedFunction(_getHostname); const getInterfaceAddresses = getCheckedFunction(_getInterfaceAddresses); const getOSRelease = getCheckedFunction(_getOSRelease); const getOSType = getCheckedFunction(_getOSType); -const getUserInfo = getCheckedFunction(_getUserInfo); getFreeMem[Symbol.toPrimitive] = () => getFreeMem(); getHostname[Symbol.toPrimitive] = () => getHostname(); @@ -239,6 +238,19 @@ function getPriority(pid) { return priority; } +function userInfo(options) { + if (typeof options !== 'object') + options = null; + + const ctx = {}; + const user = getUserInfo(options, ctx); + + if (user === undefined) + throw new ERR_SYSTEM_ERROR(ctx); + + return user; +} + module.exports = { arch, cpus, @@ -255,7 +267,7 @@ module.exports = { tmpdir, totalmem: getTotalMem, type: getOSType, - userInfo: getUserInfo, + userInfo, uptime: getUptime, // Deprecated APIs