import type {WhitespaceCharacter} from './whitespace-character.d.ts'; import type {UnwrapBrandedPrimitive} from './unwrap-branded-primitive.d.ts'; /** Remove spaces from the left side. */ // Inspect one character instead of matching every whitespace alternative at each step. type TrimLeft = Value extends `${infer First}${infer Rest}` ? First extends WhitespaceCharacter ? TrimLeft : Value : Value; /** Remove spaces from the right side. */ type TrimRight = V extends `${infer R}${WhitespaceCharacter}` ? TrimRight : V; /** Remove leading and trailing spaces from a string. @example ``` import type {Trim} from 'type-fest'; type Example = Trim<' foo '>; //=> 'foo' ``` @category String @category Template literal */ export type Trim = TrimLeft : V>>; export {};