diff options
Diffstat (limited to 'node_modules/remove-trailing-separator/index.js')
-rw-r--r-- | node_modules/remove-trailing-separator/index.js | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/node_modules/remove-trailing-separator/index.js b/node_modules/remove-trailing-separator/index.js index 9f0de5334..512306b88 100644 --- a/node_modules/remove-trailing-separator/index.js +++ b/node_modules/remove-trailing-separator/index.js @@ -1,13 +1,17 @@ var isWin = process.platform === 'win32'; module.exports = function (str) { - while (endsInSeparator(str)) { - str = str.slice(0, -1); + var i = str.length - 1; + if (i < 2) { + return str; } - return str; + while (isSeparator(str, i)) { + i--; + } + return str.substr(0, i + 1); }; -function endsInSeparator(str) { - var last = str[str.length - 1]; - return str.length > 1 && (last === '/' || (isWin && last === '\\')); +function isSeparator(str, i) { + var char = str[i]; + return i > 0 && (char === '/' || (isWin && char === '\\')); } |