Sunny-117 / js-challenges

✨✨✨ Challenge your JavaScript programming limits step by step

Home Page:https://juejin.cn/column/7244788137410560055

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Trim

lhp96 opened this issue · comments

// 实现Trim 处理字符串前后的空格、换行
type Trim<S extends string> = 
  S extends `${' ' | '\n' | '\t'}${infer T}` | `${infer T}${' ' | '\n' | '\t'}` 
    ? Trim<T> 
    : S


type trimmed = Trim<'  Hello World  '> // expected to be 'Hello World'
type c = Trim<'   \n\t foo bar \t'>  // 'foo bar'