Skip to content
Onsite

Trim<S>

MediumP2Coding

Implement Trim<S>: remove whitespace (space, newline and tab) from both ends of the string literal type S. Whitespace inside the string is kept.

Tests your type must pass

type cases = [
  Expect<Equal<Trim<'str'>, 'str'>>,
  Expect<Equal<Trim<' str'>, 'str'>>,
  Expect<Equal<Trim<'     str'>, 'str'>>,
  Expect<Equal<Trim<'str   '>, 'str'>>,
  Expect<Equal<Trim<'     str     '>, 'str'>>,
  Expect<Equal<Trim<'   \n\t foo bar \t'>, 'foo bar'>>,
  Expect<Equal<Trim<''>, ''>>,
  Expect<Equal<Trim<' \n\t '>, ''>>,
]

Hints

TypeScript
Run and Submit type-check your solution against the tests.