Acme.BookStore.HttpApi.Host/node_modules/homedir-polyfill/index.js
(开头部分) 1KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
'use strict';
var os = require('os');
var fs = require('fs');
var parse = require('parse-passwd');
function homedir() {
// The following logic is from looking at logic used in the different platform
// versions of the uv_os_homedir function found in https://github.com/libuv/libuv
// This is the function used in modern versions of node.js
if (process.platform === 'win32') {
// check the USERPROFILE first
if (process.env.USERPROFILE) {
return process.env.USERPROFILE;
}
// check HOMEDRIVE and HOMEPATH
if (process.env.HOMEDRIVE && process.env.HOMEPATH) {
return process.env.HOMEDRIVE + process.env.HOMEPATH;
}
// fallback to HOME
if (process.env.HOME) {
return process.env.HOME;
}
return null;
}
// check HOME environment variable first
if (process.env.HOME) {
return process.env.HOME;
}
// on linux platforms (including OSX) find the current user and get their homedir from the /etc/passwd file
var passwd = tryReadFileSync('/etc/passwd');
var home = find(parse(passwd), getuid());
if (home) {
return home;
}
// fallback to using user environment variables
var user = process.env.LOGNAME || process.env.USER || process.env.LNAME || process.env.USERNAME;
if (!user) {
return null;
}
if (process.platform === 'darwin') {
return '/Users/' + user;
}
return '/home/' + user;
}
function find(arr, uid) {
var len = arr.length;
for (var i = 0; i < len; i++) {
if (+arr[i].uid === uid) {
后面还有 25 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
