summaryrefslogtreecommitdiff
path: root/src/compiler/utils/trim.ts
blob: 406a8c97f71ea107648d307a9a8475d2ff3dc201 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import { whitespace } from './patterns.js';

export function trim_start(str: string) {
  let i = 0;
  while (whitespace.test(str[i])) i += 1;

  return str.slice(i);
}

export function trim_end(str: string) {
  let i = str.length;
  while (whitespace.test(str[i - 1])) i -= 1;

  return str.slice(0, i);
}