You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.8 KiB

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