GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — path: the dot will be added(path.format) if it is not specified in `ext` · nodejs/node@22c39b1

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • path.md
  • lib
    • path.js
  • test/parallel
    • test-path-parse-format.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/path.md‎

Copy file name to clipboardExpand all lines: doc/api/path.md
+12Lines changed: 12 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ A [`TypeError`][] is thrown if `path` is not a string.
206206

207207
<!-- YAML
208208
added: v0.11.15
209+
changes:
210+
- version: REPLACEME
211+
pr-url: https://github.com/nodejs/node/pull/44349
212+
description: The dot will be added if it is not specified in `ext`.
209213
-->
210214

211215
* `pathObject` {Object} Any JavaScript object having the following properties:
@@ -255,6 +259,14 @@ path.format({
255259
ext: '.txt'
256260
});
257261
// Returns: '/file.txt'
262+
263+
// The dot will be added if it is not specified in `ext`.
264+
path.format({
265+
root: '/',
266+
name: 'file',
267+
ext: 'txt'
268+
});
269+
// Returns: '/file.txt'
258270
```
259271

260272
On Windows:
Collapse file

‎lib/path.js‎

Copy file name to clipboardExpand all lines: lib/path.js
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
127127
return res;
128128
}
129129

130+
function formatExt(ext) {
131+
return ext ? `${ext[0] === '.' ? '' : '.'}${ext}` : '';
132+
}
133+
130134
/**
131135
* @param {string} sep
132136
* @param {{
@@ -142,7 +146,7 @@ function _format(sep, pathObject) {
142146
validateObject(pathObject, 'pathObject');
143147
const dir = pathObject.dir || pathObject.root;
144148
const base = pathObject.base ||
145-
`${pathObject.name || ''}${pathObject.ext || ''}`;
149+
`${pathObject.name || ''}${formatExt(pathObject.ext)}`;
146150
if (!dir) {
147151
return base;
148152
}
Collapse file

‎test/parallel/test-path-parse-format.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-path-parse-format.js
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,7 @@ function checkFormat(path, testCases) {
224224
});
225225
});
226226
}
227+
228+
// See https://github.com/nodejs/node/issues/44343
229+
assert.strictEqual(path.format({ name: 'x', ext: 'png' }), 'x.png');
230+
assert.strictEqual(path.format({ name: 'x', ext: '.png' }), 'x.png');

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.