01978
PercentageParser
type ReverseString<S extends string, L extends string = ''> = S extends `${infer First}${infer Rest}` ? ReverseString<Rest,`${First}${L}`> : L;
type FirstChar<S extends string> = S extends `${infer First}${infer Rest}` ? First : S;
type LastChar<S extends string> = FirstChar<ReverseString<S>>;
type CurFirst<S extends string> = S extends `${infer First}${infer Rest}` ? Rest : S;
type CurLast<S extends string> = ReverseString<CurFirst<ReverseString<S>>>;
type PercentageParser<A extends string> =
FirstChar<A> extends "+"|"-"
? LastChar<A> extends "%"
? [FirstChar<A>,CurLast<CurFirst<A>>,LastChar<A>]
: [FirstChar<A>,CurFirst<A>, '']
: LastChar<A> extends "%"
? ['', CurLast<A>,LastChar<A>]
: ['',A,'']