Skip to content

lib: add JSDoc to os module functions #38197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions lib/os.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,17 @@ const {
const getHomeDirectory = getCheckedFunction(_getHomeDirectory);
const getHostname = getCheckedFunction(_getHostname);
const getInterfaceAddresses = getCheckedFunction(_getInterfaceAddresses);
/**
* @returns {string}
*/
const getOSRelease = () => release;
/**
* @returns {string}
*/
const getOSType = () => type;
/**
* @returns {string}
*/
const getOSVersion = () => version;

getFreeMem[SymbolToPrimitive] = () => getFreeMem();
Expand All @@ -97,11 +106,30 @@ const kEndianness = isBigEndian ? 'BE' : 'LE';

const avgValues = new Float64Array(3);

/**
* @returns {number[]}
*/
function loadavg() {
getLoadAvg(avgValues);
return [avgValues[0], avgValues[1], avgValues[2]];
}

/**
* Returns an array of objects containing information about each
* logical CPU core.
*
* @returns {Array<{
* model: string
* speed: number
* times: {
* user: number
* nice: number
* sys: number
* idle: number
* irq: number
* }
* }>}
*/
function cpus() {
// [] is a bugfix for a regression introduced in 51cea61
const data = getCPUs() || [];
Expand All @@ -123,16 +151,25 @@ function cpus() {
return result;
}

/**
* @returns {string}
*/
function arch() {
return process.arch;
}
arch[SymbolToPrimitive] = () => process.arch;

/**
* @returns {string}
*/
function platform() {
return process.platform;
}
platform[SymbolToPrimitive] = () => process.platform;

/**
* @returns {string}
*/
function tmpdir() {
var path;
if (isWindows) {
Expand All @@ -155,6 +192,9 @@ function tmpdir() {
}
tmpdir[SymbolToPrimitive] = () => tmpdir();

/**
* @returns {'BE' | 'LE'}
*/
function endianness() {
return kEndianness;
}
Expand Down Expand Up @@ -204,6 +244,17 @@ function getCIDR(address, netmask, family) {
return `${address}/${ones}`;
}

/**
* @returns {Object.<string, Array<{
* address: string
* netmask: string
* family: 'IPv4' | 'IPv6'
* mac: string
* internal: boolean
* scopeid: number
* cidr: string | null
* }>>}
*/
function networkInterfaces() {
const data = getInterfaceAddresses();
const result = {};
Expand Down Expand Up @@ -234,6 +285,9 @@ function networkInterfaces() {
return result;
}

/**
* @returns {void}
*/
function setPriority(pid, priority) {
if (priority === undefined) {
priority = pid;
Expand All @@ -249,6 +303,9 @@ function setPriority(pid, priority) {
throw new ERR_SYSTEM_ERROR(ctx);
}

/**
* @returns {number}
*/
function getPriority(pid) {
if (pid === undefined)
pid = 0;
Expand All @@ -264,6 +321,18 @@ function getPriority(pid) {
return priority;
}

/**
* @param {{ encoding?: string }} options If `encoding` is set to `'buffer'`,
* the `username`, `shell`, and `homedir` values will be `Buffer` instances.
* Default: `'utf8'`
* @returns {{
* uid: number
* gid: number
* username: string
* homedir: string
* shell: string | null
* }}
*/
function userInfo(options) {
if (typeof options !== 'object')
options = null;
Expand Down