All files / lib/util path.ts

100% Statements 24/24
100% Branches 4/4
100% Functions 2/2
100% Lines 24/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 251x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 285x 285x 18x 18x 285x 285x  
"use strict";
/**
 * Path and URL string helpers.
 *
 * @module util/path
 */
 
/**
 * Remove every trailing `/` from a string.
 *
 * A loop rather than `s.replace(/\/+$/, "")`: that regex retries from every
 * `/` in a run that is not at the end, so a long run of slashes followed by
 * anything else takes quadratic time.
 *
 * @param {String} s - URL, path or path template
 * @return {String} the string without trailing slashes
 */
export function trimTrailingSlashes(s: string): string {
  let end = s.length;
  while (end > 0 && s[end - 1] === "/") {
    end--;
  }
  return s.slice(0, end);
}