Skip to content

Commit face4b8

Browse files
xavdidtargos
authored andcommitted
typings: add JSDoc to os module functions
PR-URL: #38197 Reviewed-By: Bradley Farias <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent 599434a commit face4b8

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

lib/os.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,17 @@ const [
7676
const getHomeDirectory = getCheckedFunction(_getHomeDirectory);
7777
const getHostname = getCheckedFunction(_getHostname);
7878
const getInterfaceAddresses = getCheckedFunction(_getInterfaceAddresses);
79+
/**
80+
* @returns {string}
81+
*/
7982
const getOSRelease = () => release;
83+
/**
84+
* @returns {string}
85+
*/
8086
const getOSType = () => type;
87+
/**
88+
* @returns {string}
89+
*/
8190
const getOSVersion = () => version;
8291

8392
getFreeMem[SymbolToPrimitive] = () => getFreeMem();
@@ -93,11 +102,30 @@ const kEndianness = isBigEndian ? 'BE' : 'LE';
93102

94103
const avgValues = new Float64Array(3);
95104

105+
/**
106+
* @returns {[number, number, number]}
107+
*/
96108
function loadavg() {
97109
getLoadAvg(avgValues);
98110
return [avgValues[0], avgValues[1], avgValues[2]];
99111
}
100112

113+
/**
114+
* Returns an array of objects containing information about each
115+
* logical CPU core.
116+
*
117+
* @returns {Array<{
118+
* model: string
119+
* speed: number
120+
* times: {
121+
* user: number
122+
* nice: number
123+
* sys: number
124+
* idle: number
125+
* irq: number
126+
* }
127+
* }>}
128+
*/
101129
function cpus() {
102130
// [] is a bugfix for a regression introduced in 51cea61
103131
const data = getCPUs() || [];
@@ -119,16 +147,25 @@ function cpus() {
119147
return result;
120148
}
121149

150+
/**
151+
* @returns {string}
152+
*/
122153
function arch() {
123154
return process.arch;
124155
}
125156
arch[SymbolToPrimitive] = () => process.arch;
126157

158+
/**
159+
* @returns {string}
160+
*/
127161
function platform() {
128162
return process.platform;
129163
}
130164
platform[SymbolToPrimitive] = () => process.platform;
131165

166+
/**
167+
* @returns {string}
168+
*/
132169
function tmpdir() {
133170
var path;
134171
if (isWindows) {
@@ -150,6 +187,9 @@ function tmpdir() {
150187
}
151188
tmpdir[SymbolToPrimitive] = () => tmpdir();
152189

190+
/**
191+
* @returns {'BE' | 'LE'}
192+
*/
153193
function endianness() {
154194
return kEndianness;
155195
}
@@ -199,6 +239,17 @@ function getCIDR(address, netmask, family) {
199239
return `${address}/${ones}`;
200240
}
201241

242+
/**
243+
* @returns {Record<string, Array<{
244+
* address: string
245+
* netmask: string
246+
* family: 'IPv4' | 'IPv6'
247+
* mac: string
248+
* internal: boolean
249+
* scopeid: number
250+
* cidr: string | null
251+
* }>>}
252+
*/
202253
function networkInterfaces() {
203254
const data = getInterfaceAddresses();
204255
const result = {};
@@ -229,6 +280,11 @@ function networkInterfaces() {
229280
return result;
230281
}
231282

283+
/**
284+
* @param {number} pid
285+
* @param {number} priority
286+
* @returns {void}
287+
*/
232288
function setPriority(pid, priority) {
233289
if (priority === undefined) {
234290
priority = pid;
@@ -244,6 +300,10 @@ function setPriority(pid, priority) {
244300
throw new ERR_SYSTEM_ERROR(ctx);
245301
}
246302

303+
/**
304+
* @param {number} pid
305+
* @returns {number}
306+
*/
247307
function getPriority(pid) {
248308
if (pid === undefined)
249309
pid = 0;
@@ -259,6 +319,18 @@ function getPriority(pid) {
259319
return priority;
260320
}
261321

322+
/**
323+
* @param {{ encoding?: string }} options If `encoding` is set to `'buffer'`,
324+
* the `username`, `shell`, and `homedir` values will be `Buffer` instances.
325+
* Default: `'utf8'`
326+
* @returns {{
327+
* uid: number
328+
* gid: number
329+
* username: string
330+
* homedir: string
331+
* shell: string | null
332+
* }}
333+
*/
262334
function userInfo(options) {
263335
if (typeof options !== 'object')
264336
options = null;

0 commit comments

Comments
 (0)