Skip to content

Commit

Permalink
fs: replace magic numbers by named constants
Browse files Browse the repository at this point in the history
PR-URL: #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>
  • Loading branch information
daynin authored and Matheus Marchini committed Feb 16, 2018
1 parent 759a083 commit d8d84ee
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ const {
assertEncoding,
stringToFlags
} = internalFS;
const {
CHAR_FORWARD_SLASH,
CHAR_BACKWARD_SLASH,
} = require('internal/constants');

Object.defineProperty(exports, 'constants', {
configurable: false,
Expand Down Expand Up @@ -1796,7 +1800,7 @@ if (isWindows) {
} else {
splitRoot = function splitRoot(str) {
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;
Expand All @@ -1820,7 +1824,9 @@ if (isWindows) {
nextPart = function nextPart(p, i) {
for (; i < p.length; ++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 -1;
Expand Down

0 comments on commit d8d84ee

Please sign in to comment.