Skip to content

Commit e2c2f2b

Browse files
Skn0tttargos
authored andcommitted
typings: add JSDoc types to lib/path
PR-URL: #38186 Reviewed-By: Bradley Farias <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 08a6d9e commit e2c2f2b

File tree

1 file changed

+105
-6
lines changed

1 file changed

+105
-6
lines changed

lib/path.js

Lines changed: 105 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,17 @@ function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
112112
return res;
113113
}
114114

115+
/**
116+
* @param {string} sep
117+
* @param {{
118+
* dir?: string;
119+
* root?: string;
120+
* base?: string;
121+
* name?: string;
122+
* ext?: string;
123+
* }} pathObject
124+
* @returns {string}
125+
*/
115126
function _format(sep, pathObject) {
116127
if (pathObject === null || typeof pathObject !== 'object') {
117128
throw new ERR_INVALID_ARG_TYPE('pathObject', 'Object', pathObject);
@@ -126,7 +137,11 @@ function _format(sep, pathObject) {
126137
}
127138

128139
const win32 = {
129-
// path.resolve([from ...], to)
140+
/**
141+
* path.resolve([from ...], to)
142+
* @param {...string} args
143+
* @returns {string}
144+
*/
130145
resolve(...args) {
131146
let resolvedDevice = '';
132147
let resolvedTail = '';
@@ -262,6 +277,10 @@ const win32 = {
262277
`${resolvedDevice}${resolvedTail}` || '.';
263278
},
264279

280+
/**
281+
* @param {string} path
282+
* @returns {string}
283+
*/
265284
normalize(path) {
266285
validateString(path, 'path');
267286
const len = path.length;
@@ -349,6 +368,10 @@ const win32 = {
349368
return isAbsolute ? `${device}\\${tail}` : `${device}${tail}`;
350369
},
351370

371+
/**
372+
* @param {string} path
373+
* @returns {boolean}
374+
*/
352375
isAbsolute(path) {
353376
validateString(path, 'path');
354377
const len = path.length;
@@ -364,6 +387,10 @@ const win32 = {
364387
isPathSeparator(path.charCodeAt(2)));
365388
},
366389

390+
/**
391+
* @param {...string} args
392+
* @returns {string}
393+
*/
367394
join(...args) {
368395
if (args.length === 0)
369396
return '.';
@@ -429,10 +456,15 @@ const win32 = {
429456
return win32.normalize(joined);
430457
},
431458

432-
// It will solve the relative path from `from` to `to`, for instance:
433-
// from = 'C:\\orandea\\test\\aaa'
434-
// to = 'C:\\orandea\\impl\\bbb'
435-
// The output of the function should be: '..\\..\\impl\\bbb'
459+
/**
460+
* It will solve the relative path from `from` to `to`, for instancee
461+
* from = 'C:\\orandea\\test\\aaa'
462+
* to = 'C:\\orandea\\impl\\bbb'
463+
* The output of the function should be: '..\\..\\impl\\bbb'
464+
* @param {string} from
465+
* @param {string} to
466+
* @returns {string}
467+
*/
436468
relative(from, to) {
437469
validateString(from, 'from');
438470
validateString(to, 'to');
@@ -579,6 +611,10 @@ const win32 = {
579611
return path;
580612
},
581613

614+
/**
615+
* @param {string} path
616+
* @returns {string}
617+
*/
582618
dirname(path) {
583619
validateString(path, 'path');
584620
const len = path.length;
@@ -665,6 +701,11 @@ const win32 = {
665701
return path.slice(0, end);
666702
},
667703

704+
/**
705+
* @param {string} path
706+
* @param {string} [ext]
707+
* @returns {string}
708+
*/
668709
basename(path, ext) {
669710
if (ext !== undefined)
670711
validateString(ext, 'ext');
@@ -748,6 +789,10 @@ const win32 = {
748789
return path.slice(start, end);
749790
},
750791

792+
/**
793+
* @param {string} path
794+
* @returns {string}
795+
*/
751796
extname(path) {
752797
validateString(path, 'path');
753798
let start = 0;
@@ -814,6 +859,16 @@ const win32 = {
814859

815860
format: _format.bind(null, '\\'),
816861

862+
/**
863+
* @param {string} path
864+
* @returns {{
865+
* dir: string;
866+
* root: string;
867+
* base: string;
868+
* name: string;
869+
* ext: string;
870+
* }}
871+
*/
817872
parse(path) {
818873
validateString(path, 'path');
819874

@@ -969,7 +1024,11 @@ const win32 = {
9691024
};
9701025

9711026
const posix = {
972-
// path.resolve([from ...], to)
1027+
/**
1028+
* path.resolve([from ...], to)
1029+
* @param {...string} args
1030+
* @returns {string}
1031+
*/
9731032
resolve(...args) {
9741033
let resolvedPath = '';
9751034
let resolvedAbsolute = false;
@@ -1001,6 +1060,10 @@ const posix = {
10011060
return resolvedPath.length > 0 ? resolvedPath : '.';
10021061
},
10031062

1063+
/**
1064+
* @param {string} path
1065+
* @returns {string}
1066+
*/
10041067
normalize(path) {
10051068
validateString(path, 'path');
10061069

@@ -1025,11 +1088,19 @@ const posix = {
10251088
return isAbsolute ? `/${path}` : path;
10261089
},
10271090

1091+
/**
1092+
* @param {string} path
1093+
* @returns {boolean}
1094+
*/
10281095
isAbsolute(path) {
10291096
validateString(path, 'path');
10301097
return path.length > 0 && path.charCodeAt(0) === CHAR_FORWARD_SLASH;
10311098
},
10321099

1100+
/**
1101+
* @param {...string} args
1102+
* @returns {string}
1103+
*/
10331104
join(...args) {
10341105
if (args.length === 0)
10351106
return '.';
@@ -1049,6 +1120,11 @@ const posix = {
10491120
return posix.normalize(joined);
10501121
},
10511122

1123+
/**
1124+
* @param {string} from
1125+
* @param {string} to
1126+
* @returns {string}
1127+
*/
10521128
relative(from, to) {
10531129
validateString(from, 'from');
10541130
validateString(to, 'to');
@@ -1124,6 +1200,10 @@ const posix = {
11241200
return path;
11251201
},
11261202

1203+
/**
1204+
* @param {string} path
1205+
* @returns {string}
1206+
*/
11271207
dirname(path) {
11281208
validateString(path, 'path');
11291209
if (path.length === 0)
@@ -1150,6 +1230,11 @@ const posix = {
11501230
return path.slice(0, end);
11511231
},
11521232

1233+
/**
1234+
* @param {string} path
1235+
* @param {string} [ext]
1236+
* @returns {string}
1237+
*/
11531238
basename(path, ext) {
11541239
if (ext !== undefined)
11551240
validateString(ext, 'ext');
@@ -1225,6 +1310,10 @@ const posix = {
12251310
return path.slice(start, end);
12261311
},
12271312

1313+
/**
1314+
* @param {string} path
1315+
* @returns {string}
1316+
*/
12281317
extname(path) {
12291318
validateString(path, 'path');
12301319
let startDot = -1;
@@ -1279,6 +1368,16 @@ const posix = {
12791368

12801369
format: _format.bind(null, '/'),
12811370

1371+
/**
1372+
* @param {string} path
1373+
* @returns {{
1374+
* dir: string;
1375+
* root: string;
1376+
* base: string;
1377+
* name: string;
1378+
* ext: string;
1379+
* }}
1380+
*/
12821381
parse(path) {
12831382
validateString(path, 'path');
12841383

0 commit comments

Comments
 (0)