Skip to content

Commit fd1fff4

Browse files
committed
path: change basename() argument from ext to suffix
Closes: #44773
1 parent abfeed8 commit fd1fff4

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

doc/api/path.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ example, `path.resolve('C:\\')` can potentially return a different result than
6262
`path.resolve('C:')`. For more information, see
6363
[this MSDN page][MSDN-Rel-Path].
6464

65-
## `path.basename(path[, ext])`
65+
## `path.basename(path[, suffix])`
6666

6767
<!-- YAML
6868
added: v0.1.25
@@ -73,12 +73,12 @@ changes:
7373
-->
7474

7575
* `path` {string}
76-
* `ext` {string} An optional file extension
76+
* `suffix` {string} An optional suffix to remove
7777
* Returns: {string}
7878

7979
The `path.basename()` method returns the last portion of a `path`, similar to
80-
the Unix `basename` command. Trailing directory separators are ignored, see
81-
[`path.sep`][].
80+
the Unix `basename` command. Trailing [directory separators][`path.sep`] are
81+
ignored.
8282

8383
```js
8484
path.basename('/foo/bar/baz/asdf/quux.html');
@@ -101,7 +101,7 @@ path.win32.basename('C:\\foo.HTML', '.html');
101101
// Returns: 'foo.HTML'
102102
```
103103

104-
A [`TypeError`][] is thrown if `path` is not a string or if `ext` is given
104+
A [`TypeError`][] is thrown if `path` is not a string or if `suffix` is given
105105
and is not a string.
106106

107107
## `path.delimiter`

lib/path.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -743,12 +743,12 @@ const win32 = {
743743

744744
/**
745745
* @param {string} path
746-
* @param {string} [ext]
746+
* @param {string} [suffix]
747747
* @returns {string}
748748
*/
749-
basename(path, ext) {
750-
if (ext !== undefined)
751-
validateString(ext, 'ext');
749+
basename(path, suffix) {
750+
if (suffix !== undefined)
751+
validateString(suffix, 'ext');
752752
validateString(path, 'path');
753753
let start = 0;
754754
let end = -1;
@@ -763,10 +763,10 @@ const win32 = {
763763
start = 2;
764764
}
765765

766-
if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
767-
if (ext === path)
766+
if (suffix !== undefined && suffix.length > 0 && suffix.length <= path.length) {
767+
if (suffix === path)
768768
return '';
769-
let extIdx = ext.length - 1;
769+
let extIdx = suffix.length - 1;
770770
let firstNonSlashEnd = -1;
771771
for (let i = path.length - 1; i >= start; --i) {
772772
const code = StringPrototypeCharCodeAt(path, i);
@@ -786,7 +786,7 @@ const win32 = {
786786
}
787787
if (extIdx >= 0) {
788788
// Try to match the explicit extension
789-
if (code === StringPrototypeCharCodeAt(ext, extIdx)) {
789+
if (code === StringPrototypeCharCodeAt(suffix, extIdx)) {
790790
if (--extIdx === -1) {
791791
// We matched the extension, so mark this as the end of our path
792792
// component
@@ -1300,22 +1300,22 @@ const posix = {
13001300

13011301
/**
13021302
* @param {string} path
1303-
* @param {string} [ext]
1303+
* @param {string} [suffix]
13041304
* @returns {string}
13051305
*/
1306-
basename(path, ext) {
1307-
if (ext !== undefined)
1308-
validateString(ext, 'ext');
1306+
basename(path, suffix) {
1307+
if (suffix !== undefined)
1308+
validateString(suffix, 'ext');
13091309
validateString(path, 'path');
13101310

13111311
let start = 0;
13121312
let end = -1;
13131313
let matchedSlash = true;
13141314

1315-
if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
1316-
if (ext === path)
1315+
if (suffix !== undefined && suffix.length > 0 && suffix.length <= path.length) {
1316+
if (suffix === path)
13171317
return '';
1318-
let extIdx = ext.length - 1;
1318+
let extIdx = suffix.length - 1;
13191319
let firstNonSlashEnd = -1;
13201320
for (let i = path.length - 1; i >= 0; --i) {
13211321
const code = StringPrototypeCharCodeAt(path, i);
@@ -1335,7 +1335,7 @@ const posix = {
13351335
}
13361336
if (extIdx >= 0) {
13371337
// Try to match the explicit extension
1338-
if (code === StringPrototypeCharCodeAt(ext, extIdx)) {
1338+
if (code === StringPrototypeCharCodeAt(suffix, extIdx)) {
13391339
if (--extIdx === -1) {
13401340
// We matched the extension, so mark this as the end of our path
13411341
// component

0 commit comments

Comments
 (0)