From 28ac762a801dffef1a5d2ad37229c823c9cec742 Mon Sep 17 00:00:00 2001 From: Sergey Golovin Date: Tue, 13 Feb 2018 14:49:53 +0300 Subject: [PATCH] fs: replace magic numbers by named constants --- lib/fs.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index da718f3f334413..51fa5c70e04a20 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -46,6 +46,10 @@ const { assertEncoding, stringToFlags } = internalFS; +const { + CHAR_FORWARD_SLASH, + CHAR_BACKWARD_SLASH, +} = require('internal/constants'); Object.defineProperty(exports, 'constants', { configurable: false, @@ -1814,7 +1818,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; @@ -1838,7 +1842,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;