1 | # remove-trailing-separator
|
---|
2 |
|
---|
3 | [![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]
|
---|
4 |
|
---|
5 | Removes all separators from the end of a string.
|
---|
6 |
|
---|
7 | ## Install
|
---|
8 |
|
---|
9 | ```
|
---|
10 | npm install remove-trailing-separator
|
---|
11 | ```
|
---|
12 |
|
---|
13 | ## Examples
|
---|
14 |
|
---|
15 | ```js
|
---|
16 | const removeTrailingSeparator = require('remove-trailing-separator');
|
---|
17 |
|
---|
18 | removeTrailingSeparator('/foo/bar/') // '/foo/bar'
|
---|
19 | removeTrailingSeparator('/foo/bar///') // '/foo/bar'
|
---|
20 |
|
---|
21 | // leaves only/last separator
|
---|
22 | removeTrailingSeparator('/') // '/'
|
---|
23 | removeTrailingSeparator('///') // '/'
|
---|
24 |
|
---|
25 | // returns empty string
|
---|
26 | removeTrailingSeparator('') // ''
|
---|
27 | ```
|
---|
28 |
|
---|
29 | ## Notable backslash, or win32 separator behavior
|
---|
30 |
|
---|
31 | `\` is considered a separator only on WIN32 systems. All POSIX compliant systems
|
---|
32 | see backslash as a valid file name character, so it would break POSIX compliance
|
---|
33 | to remove it there.
|
---|
34 |
|
---|
35 | In practice, this means that this code will return different things depending on
|
---|
36 | what system it runs on:
|
---|
37 |
|
---|
38 | ```js
|
---|
39 | removeTrailingSeparator('\\foo\\')
|
---|
40 | // UNIX => '\\foo\\'
|
---|
41 | // WIN32 => '\\foo'
|
---|
42 | ```
|
---|
43 |
|
---|
44 | [npm-url]: https://npmjs.org/package/remove-trailing-separator
|
---|
45 | [npm-img]: https://badge.fury.io/js/remove-trailing-separator.svg
|
---|
46 | [travis-url]: https://travis-ci.org/darsain/remove-trailing-separator
|
---|
47 | [travis-img]: https://travis-ci.org/darsain/remove-trailing-separator.svg?branch=master
|
---|
48 | [appveyor-url]: https://ci.appveyor.com/project/darsain/remove-trailing-separator/branch/master
|
---|
49 | [appveyor-img]: https://ci.appveyor.com/api/projects/status/wvg9a93rrq95n2xl/branch/master?svg=true
|
---|
50 | [coveralls-url]: https://coveralls.io/github/darsain/remove-trailing-separator?branch=master
|
---|
51 | [coveralls-img]: https://coveralls.io/repos/github/darsain/remove-trailing-separator/badge.svg?branch=master
|
---|