• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// this is the only approach that was significantly faster than using
2// str.replace(/\/+$/, '') for strings ending with a lot of / chars and
3// containing multiple / chars.
4const batchStrings = [
5  '/'.repeat(1024),
6  '/'.repeat(512),
7  '/'.repeat(256),
8  '/'.repeat(128),
9  '/'.repeat(64),
10  '/'.repeat(32),
11  '/'.repeat(16),
12  '/'.repeat(8),
13  '/'.repeat(4),
14  '/'.repeat(2),
15  '/',
16]
17
18module.exports = str => {
19  for (const s of batchStrings) {
20    while (str.length >= s.length && str.slice(-1 * s.length) === s)
21      str = str.slice(0, -1 * s.length)
22  }
23  return str
24}
25