00274
integers-comparator
enum Comparison {
Greater,
Equal,
Lower,
}
type LengthOfString<S extends Readonly<string>, L extends string[] = []> = S extends '' ? L['length'] : S extends `${infer First}${infer Last}` ? LengthOfString<Last, [First,...L]> : never;
type NotEqualSignCompare<A extends number, B extends number> = IsNegative<NumberToString<A>> extends true ? Comparison.Lower : Comparison.Greater
type NumberToString<T extends number> = `${T}`;
type IsNegative<A extends string> = A extends `-${infer N}` ? true : false;
type EqualSign<A extends number, B extends number> = IsNegative<NumberToString<A>> extends IsNegative<NumberToString<B>> ? true : false;
type EqualDigit<A extends number, B extends number> = EqualSign<A,B> extends true ? LengthOfString<NumberToString<A>> extends LengthOfString<NumberToString<B>> ? true : false : false;
type GetCompareNums<A extends string, B extends string> =
A extends `${infer AFirst}${infer ARest}` ?
B extends `${infer BFirst}${infer BRest}` ?
AFirst extends BFirst ? GetCompareNums<ARest, BRest> : [AFirst, BFirst]
: never
: never
type ALowerThenB<T extends string[]>= T extends [infer F extends string, infer L extends string] ? `${F}${L}` extends LowerCompare ? true : false : never;
type LowerCompare = `0${'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'}` | `1${'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'}` | `2${|'3'|'4'|'5'|'6'|'7'|'8'|'9'}` | `3${'4'|'5'|'6'|'7'|'8'|'9'}` | `4${'5'|'6'|'7'|'8'|'9'}` | `5${'6'|'7'|'8'|'9'}` | `6${'7'|'8'|'9'}` | `7${'8'|'9'}` | `8${'9'}`;
type Comparator<A extends number, B extends number> = A extends B ? Comparison.Equal :
EqualSign<A,B> extends true
? EqualDigit<A,B> extends true
? GetCompareNums<`${A}`,`${B}`> extends [infer F extends string, infer L extends string]
? ALowerThenB<[F,L]> extends true ? IsNegative<`${A}`> extends true
? Comparison.Greater
: Comparison.Lower
: IsNegative<`${A}`> extends true
? Comparison.Lower
: Comparison.Greater
: never
: ALowerThenB<
IsNegative<`${A}`> extends true
? [`${LengthOfString<`${B}`>}`,`${LengthOfString<`${A}`>}`]
: [`${LengthOfString<`${A}`>}`,`${LengthOfString<`${B}`>}`]
> extends true
? Comparison.Lower:Comparison.Greater
: NotEqualSignCompare<A,B>