@@ -33,12 +33,7 @@ const {
3333 CHAR_COLON,
3434 CHAR_QUESTION_MARK,
3535} = require('internal/constants');
36-
37- function assertPath(path) {
38- if (typeof path !== 'string') {
39- throw new ERR_INVALID_ARG_TYPE('path', 'string', path);
40- }
41- }
36+ const { validateString } = require('internal/validators');
4237
4338function isPathSeparator(code) {
4439 return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
@@ -163,7 +158,7 @@ const win32 = {
163158 }
164159 }
165160
166- assertPath (path);
161+ validateString (path, 'path' );
167162
168163 // Skip empty entries
169164 if (path.length === 0) {
@@ -282,7 +277,7 @@ const win32 = {
282277 },
283278
284279 normalize: function normalize(path) {
285- assertPath (path);
280+ validateString (path, 'path' );
286281 const len = path.length;
287282 if (len === 0)
288283 return '.';
@@ -401,7 +396,7 @@ const win32 = {
401396
402397
403398 isAbsolute: function isAbsolute(path) {
404- assertPath (path);
399+ validateString (path, 'path' );
405400 const len = path.length;
406401 if (len === 0)
407402 return false;
@@ -429,7 +424,7 @@ const win32 = {
429424 var firstPart;
430425 for (var i = 0; i < arguments.length; ++i) {
431426 var arg = arguments[i];
432- assertPath (arg);
427+ validateString (arg, 'path' );
433428 if (arg.length > 0) {
434429 if (joined === undefined)
435430 joined = firstPart = arg;
@@ -494,8 +489,8 @@ const win32 = {
494489 // to = 'C:\\orandea\\impl\\bbb'
495490 // The output of the function should be: '..\\..\\impl\\bbb'
496491 relative: function relative(from, to) {
497- assertPath (from);
498- assertPath (to);
492+ validateString (from, 'from' );
493+ validateString (to, 'to' );
499494
500495 if (from === to)
501496 return '';
@@ -648,7 +643,7 @@ const win32 = {
648643 },
649644
650645 dirname: function dirname(path) {
651- assertPath (path);
646+ validateString (path, 'path' );
652647 const len = path.length;
653648 if (len === 0)
654649 return '.';
@@ -744,9 +739,9 @@ const win32 = {
744739
745740
746741 basename: function basename(path, ext) {
747- if (ext !== undefined && typeof ext !== 'string' )
748- throw new ERR_INVALID_ARG_TYPE(' ext' , 'string', ext);
749- assertPath (path);
742+ if (ext !== undefined)
743+ validateString( ext, 'ext' );
744+ validateString (path, 'path' );
750745 var start = 0;
751746 var end = -1;
752747 var matchedSlash = true;
@@ -832,7 +827,7 @@ const win32 = {
832827
833828
834829 extname: function extname(path) {
835- assertPath (path);
830+ validateString (path, 'path' );
836831 var start = 0;
837832 var startDot = -1;
838833 var startPart = 0;
@@ -905,7 +900,7 @@ const win32 = {
905900
906901
907902 parse: function parse(path) {
908- assertPath (path);
903+ validateString (path, 'path' );
909904
910905 var ret = { root: '', dir: '', base: '', ext: '', name: '' };
911906 if (path.length === 0)
@@ -1082,7 +1077,7 @@ const posix = {
10821077 path = process.cwd();
10831078 }
10841079
1085- assertPath (path);
1080+ validateString (path, 'path' );
10861081
10871082 // Skip empty entries
10881083 if (path.length === 0) {
@@ -1114,7 +1109,7 @@ const posix = {
11141109
11151110
11161111 normalize: function normalize(path) {
1117- assertPath (path);
1112+ validateString (path, 'path' );
11181113
11191114 if (path.length === 0)
11201115 return '.';
@@ -1138,7 +1133,7 @@ const posix = {
11381133
11391134
11401135 isAbsolute: function isAbsolute(path) {
1141- assertPath (path);
1136+ validateString (path, 'path' );
11421137 return path.length > 0 && path.charCodeAt(0) === CHAR_FORWARD_SLASH;
11431138 },
11441139
@@ -1149,7 +1144,7 @@ const posix = {
11491144 var joined;
11501145 for (var i = 0; i < arguments.length; ++i) {
11511146 var arg = arguments[i];
1152- assertPath (arg);
1147+ validateString (arg, 'path' );
11531148 if (arg.length > 0) {
11541149 if (joined === undefined)
11551150 joined = arg;
@@ -1164,8 +1159,8 @@ const posix = {
11641159
11651160
11661161 relative: function relative(from, to) {
1167- assertPath (from);
1168- assertPath (to);
1162+ validateString (from, 'from' );
1163+ validateString (to, 'to' );
11691164
11701165 if (from === to)
11711166 return '';
@@ -1262,7 +1257,7 @@ const posix = {
12621257 },
12631258
12641259 dirname: function dirname(path) {
1265- assertPath (path);
1260+ validateString (path, 'path' );
12661261 if (path.length === 0)
12671262 return '.';
12681263 const hasRoot = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
@@ -1289,9 +1284,9 @@ const posix = {
12891284
12901285
12911286 basename: function basename(path, ext) {
1292- if (ext !== undefined && typeof ext !== 'string' )
1293- throw new ERR_INVALID_ARG_TYPE(' ext' , 'string', ext);
1294- assertPath (path);
1287+ if (ext !== undefined)
1288+ validateString( ext, 'ext' );
1289+ validateString (path, 'path' );
12951290
12961291 var start = 0;
12971292 var end = -1;
@@ -1367,7 +1362,7 @@ const posix = {
13671362
13681363
13691364 extname: function extname(path) {
1370- assertPath (path);
1365+ validateString (path, 'path' );
13711366 var startDot = -1;
13721367 var startPart = 0;
13731368 var end = -1;
@@ -1428,7 +1423,7 @@ const posix = {
14281423
14291424
14301425 parse: function parse(path) {
1431- assertPath (path);
1426+ validateString (path, 'path' );
14321427
14331428 var ret = { root: '', dir: '', base: '', ext: '', name: '' };
14341429 if (path.length === 0)
0 commit comments