string.ts 333 B

12345678910111213141516171819
  1. export function trimEnd(s: string, end = " ") {
  2. if (end.length === 0) return s;
  3. while (s.endsWith(end)) {
  4. s = s.slice(0, -end.length);
  5. }
  6. return s;
  7. }
  8. export function trimStart(s: string, start = " ") {
  9. if (start.length === 0) return s;
  10. while (s.endsWith(start)) {
  11. s = s.slice(start.length);
  12. }
  13. return s;
  14. }