pax_global_header00006660000000000000000000000064131450012560014507gustar00rootroot0000000000000052 comment=f4e8acca09106efeef5a5164f1ad2192fe97fd69 remove-trailing-separator-1.1.0/000077500000000000000000000000001314500125600166105ustar00rootroot00000000000000remove-trailing-separator-1.1.0/.gitignore000066400000000000000000000000701314500125600205750ustar00rootroot00000000000000.DS_Store *.log *.node node_modules coverage .nyc_outputremove-trailing-separator-1.1.0/.travis.yml000066400000000000000000000003771314500125600207300ustar00rootroot00000000000000language: node_js node_js: - '6' - '5' - '4' - '0.12' - '0.10' before_install: - 'npm install -g npm@latest' after_success: - './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls' notifications: email: falseremove-trailing-separator-1.1.0/appveyor.yml000066400000000000000000000004651314500125600212050ustar00rootroot00000000000000environment: matrix: - nodejs_version: "0.10" - nodejs_version: "0.12" - nodejs_version: "4" - nodejs_version: "5" - nodejs_version: "6" install: - ps: Install-Product node $env:nodejs_version - npm install test_script: - node --version - npm --version - npm test build: offremove-trailing-separator-1.1.0/history.md000066400000000000000000000010721314500125600206330ustar00rootroot00000000000000## 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 ### 1.0.1 - 25th Sep 2016 - [b78606d](https://github.com/darsain/remove-trailing-separator/commit/af90b4e153a4527894741af6c7005acaeb78606d) Remove backslash only on win32 systems ### 1.0.0 - 24th Sep 2016 Initial release. remove-trailing-separator-1.1.0/index.js000066400000000000000000000005021314500125600202520ustar00rootroot00000000000000var isWin = process.platform === 'win32'; module.exports = function (str) { var i = str.length - 1; if (i < 2) { return str; } while (isSeparator(str, i)) { i--; } return str.substr(0, i + 1); }; function isSeparator(str, i) { var char = str[i]; return i > 0 && (char === '/' || (isWin && char === '\\')); } remove-trailing-separator-1.1.0/license000066400000000000000000000012701314500125600201550ustar00rootroot00000000000000Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.remove-trailing-separator-1.1.0/package.json000066400000000000000000000015171314500125600211020ustar00rootroot00000000000000{ "name": "remove-trailing-separator", "version": "1.1.0", "description": "Removes separators from the end of the string.", "main": "index.js", "files": [ "index.js" ], "scripts": { "lint": "xo", "pretest": "npm run lint", "test": "nyc ava", "report": "nyc report --reporter=html" }, "repository": { "type": "git", "url": "git+https://github.com/darsain/remove-trailing-separator.git" }, "keywords": [ "remove", "strip", "trailing", "separator" ], "author": "darsain", "license": "ISC", "bugs": { "url": "https://github.com/darsain/remove-trailing-separator/issues" }, "homepage": "https://github.com/darsain/remove-trailing-separator#readme", "devDependencies": { "ava": "^0.16.0", "coveralls": "^2.11.14", "nyc": "^8.3.0", "xo": "^0.16.0" } } remove-trailing-separator-1.1.0/readme.md000066400000000000000000000034231314500125600203710ustar00rootroot00000000000000# remove-trailing-separator [![NPM version][npm-img]][npm-url] [![Build Status: Linux][travis-img]][travis-url] [![Build Status: Windows][appveyor-img]][appveyor-url] [![Coverage Status][coveralls-img]][coveralls-url] Removes all separators from the end of a string. ## Install ``` npm install remove-trailing-separator ``` ## Examples ```js const removeTrailingSeparator = require('remove-trailing-separator'); removeTrailingSeparator('/foo/bar/') // '/foo/bar' removeTrailingSeparator('/foo/bar///') // '/foo/bar' // leaves only/last separator removeTrailingSeparator('/') // '/' removeTrailingSeparator('///') // '/' // returns empty string removeTrailingSeparator('') // '' ``` ## 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 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' ``` [npm-url]: https://npmjs.org/package/remove-trailing-separator [npm-img]: https://badge.fury.io/js/remove-trailing-separator.svg [travis-url]: https://travis-ci.org/darsain/remove-trailing-separator [travis-img]: https://travis-ci.org/darsain/remove-trailing-separator.svg?branch=master [appveyor-url]: https://ci.appveyor.com/project/darsain/remove-trailing-separator/branch/master [appveyor-img]: https://ci.appveyor.com/api/projects/status/wvg9a93rrq95n2xl/branch/master?svg=true [coveralls-url]: https://coveralls.io/github/darsain/remove-trailing-separator?branch=master [coveralls-img]: https://coveralls.io/repos/github/darsain/remove-trailing-separator/badge.svg?branch=master remove-trailing-separator-1.1.0/test/000077500000000000000000000000001314500125600175675ustar00rootroot00000000000000remove-trailing-separator-1.1.0/test/index.js000066400000000000000000000023751314500125600212430ustar00rootroot00000000000000import test from 'ava'; import removeTrailingSeparator from '..'; const isWin = process.platform === 'win32'; test('strip trailing separator:', t => { t.is(removeTrailingSeparator('foo/'), 'foo'); let platformExpected = isWin ? 'foo' : 'foo\\'; t.is(removeTrailingSeparator('foo\\'), platformExpected); }); test('don\'t strip when it\'s the only char in the string', t => { t.is(removeTrailingSeparator('/'), '/'); t.is(removeTrailingSeparator('\\'), '\\'); }); test('strip only trailing separator:', t => { t.is(removeTrailingSeparator('/test/foo/bar/'), '/test/foo/bar'); let platformExpected = isWin ? '\\test\\foo\\bar' : '\\test\\foo\\bar\\'; t.is(removeTrailingSeparator('\\test\\foo\\bar\\'), platformExpected); }); test('strip multiple trailing separators', t => { t.is(removeTrailingSeparator('/test//'), '/test'); let platformExpected = isWin ? '\\test' : '\\test\\\\'; t.is(removeTrailingSeparator('\\test\\\\'), platformExpected); }); test('leave 1st separator in a string of only separators', t => { t.is(removeTrailingSeparator('////'), '/'); let platformExpected = isWin ? '\\' : '\\\\\\\\'; t.is(removeTrailingSeparator('\\\\\\\\'), platformExpected); }); test('return back empty string', t => { t.is(removeTrailingSeparator(''), ''); });