diff options
Diffstat (limited to 'node_modules/remove-trailing-separator')
4 files changed, 17 insertions, 9 deletions
diff --git a/node_modules/remove-trailing-separator/history.md b/node_modules/remove-trailing-separator/history.md index d379cccc2..e15e8a462 100644 --- a/node_modules/remove-trailing-separator/history.md +++ b/node_modules/remove-trailing-separator/history.md @@ -1,5 +1,9 @@ ## History +### 1.1.0 - 16th Aug 2017 + +- [f4576e3](https://github.com/darsain/remove-trailing-separator/commit/f4576e3638c39b794998b533fffb27854dcbee01) Implement faster slash slicing + ### 1.0.2 - 07th Jun 2017 - [8e13ecb](https://github.com/darsain/remove-trailing-separator/commit/8e13ecbfd7b9f5fdf97c5d5ff923e4718b874e31) ES5 compatibility 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 === '\\')); } diff --git a/node_modules/remove-trailing-separator/package.json b/node_modules/remove-trailing-separator/package.json index 8d4125de3..47ef27a2e 100644 --- a/node_modules/remove-trailing-separator/package.json +++ b/node_modules/remove-trailing-separator/package.json @@ -1,6 +1,6 @@ { "name": "remove-trailing-separator", - "version": "1.0.2", + "version": "1.1.0", "description": "Removes separators from the end of the string.", "main": "index.js", "files": [ diff --git a/node_modules/remove-trailing-separator/readme.md b/node_modules/remove-trailing-separator/readme.md index 612fe3de4..747086af8 100644 --- a/node_modules/remove-trailing-separator/readme.md +++ b/node_modules/remove-trailing-separator/readme.md @@ -26,7 +26,7 @@ removeTrailingSeparator('///') // '/' removeTrailingSeparator('') // '' ``` -## Backslash, or win32 separator +## Notable backslash, or win32 separator behavior `\` is considered a separator only on WIN32 systems. All POSIX compliant systems see backslash as a valid file name character, so it would break POSIX compliance @@ -35,7 +35,7 @@ to remove it there. In practice, this means that this code will return different things depending on what system it runs on: -``` +```js removeTrailingSeparator('\\foo\\') // UNIX => '\\foo\\' // WIN32 => '\\foo' |