```ts
/** The text with a character removed from both of its ends. */
export function stripEnds(text: string, mark: string): string {
  if (!text || !mark) {
    throw new Error('Both text and mark must be provided');
  }

  let out = text;
  while (out.startsWith(mark)) {
    out = out.slice(1);
  }
  while (out.endsWith(mark)) {
    out = out.slice(0, -1);
  }

  return out;
}
```