Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fd5c26b

Browse filesBrowse files
Trottdanielleadams
authored andcommitted
path: change basename() argument from ext to suffix
Closes: #44773 PR-URL: #44774 Fixes: #44773 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent e9d572a commit fd5c26b
Copy full SHA for fd5c26b

File tree

Expand file treeCollapse file tree

2 files changed

+21
-21
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+21
-21
lines changed
Open diff view settings
Collapse file

‎doc/api/path.md‎

Copy file name to clipboardExpand all lines: doc/api/path.md
+5-5Lines changed: 5 additions & 5 deletions
  • Display the source diff
  • Display the rich diff
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`
Collapse file

‎lib/path.js‎

Copy file name to clipboardExpand all lines: lib/path.js
+16-16Lines changed: 16 additions & 16 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.