strip-trailing-slashes.js 394 B

12345678910111213
  1. // warning: extremely hot code path.
  2. // This has been meticulously optimized for use
  3. // within npm install on large package trees.
  4. // Do not edit without careful benchmarking.
  5. module.exports = str => {
  6. let i = str.length - 1
  7. let slashesStart = -1
  8. while (i > -1 && str.charAt(i) === '/') {
  9. slashesStart = i
  10. i--
  11. }
  12. return slashesStart === -1 ? str : str.slice(0, slashesStart)
  13. }