fs: replace magic numbers by named constants
PR-URL: https://github.com/nodejs/node/pull/18757 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
This commit is contained in:
parent
759a083d44
commit
d8d84eee18
10
lib/fs.js
10
lib/fs.js
@ -46,6 +46,10 @@ const {
|
|||||||
assertEncoding,
|
assertEncoding,
|
||||||
stringToFlags
|
stringToFlags
|
||||||
} = internalFS;
|
} = internalFS;
|
||||||
|
const {
|
||||||
|
CHAR_FORWARD_SLASH,
|
||||||
|
CHAR_BACKWARD_SLASH,
|
||||||
|
} = require('internal/constants');
|
||||||
|
|
||||||
Object.defineProperty(exports, 'constants', {
|
Object.defineProperty(exports, 'constants', {
|
||||||
configurable: false,
|
configurable: false,
|
||||||
@ -1796,7 +1800,7 @@ if (isWindows) {
|
|||||||
} else {
|
} else {
|
||||||
splitRoot = function splitRoot(str) {
|
splitRoot = function splitRoot(str) {
|
||||||
for (var i = 0; i < str.length; ++i) {
|
for (var i = 0; i < str.length; ++i) {
|
||||||
if (str.charCodeAt(i) !== 47/*'/'*/)
|
if (str.charCodeAt(i) !== CHAR_FORWARD_SLASH)
|
||||||
return str.slice(0, i);
|
return str.slice(0, i);
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
@ -1820,7 +1824,9 @@ if (isWindows) {
|
|||||||
nextPart = function nextPart(p, i) {
|
nextPart = function nextPart(p, i) {
|
||||||
for (; i < p.length; ++i) {
|
for (; i < p.length; ++i) {
|
||||||
const ch = p.charCodeAt(i);
|
const ch = p.charCodeAt(i);
|
||||||
if (ch === 92/*'\'*/ || ch === 47/*'/'*/)
|
|
||||||
|
// Check for a separator character
|
||||||
|
if (ch === CHAR_BACKWARD_SLASH || ch === CHAR_FORWARD_SLASH)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user