diff --git a/package.json b/package.json index 547a3b7..74920af 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "safunc", - "version": "0.1.0", + "version": "0.1.1", "private": true, "description": "Create runtime-validated functions with ease, supporting optional parameters and overloaded signatures with smart type inference in TypeScript", "keywords": [ diff --git a/src/tools/name-params.ts b/src/tools/name-params.ts index b9488a2..09b187f 100644 --- a/src/tools/name-params.ts +++ b/src/tools/name-params.ts @@ -73,12 +73,15 @@ interface Otherwise { type Conditions = [...[Condition, _[], _[]][], Otherwise]; -type CountEq = +type CountEq = _CountEq extends infer R extends number ? R : never; +type _CountEq = TS extends [] ? Acc - : CountEq, Eq>, X> extends true ? Inc : Acc>; -type CountEqOneOf = + : _CountEq, Eq>, X> extends true ? Inc : Acc>; +type CountEqOneOf = + _CountEqOneOf extends infer R extends number ? R : never; +type _CountEqOneOf = TS extends [] ? Acc - : CountEqOneOf< + : _CountEqOneOf< XS, TailPart, _EqOneOf>, XS> extends true ? Inc : Acc @@ -89,9 +92,11 @@ type _EqOneOf = true : _EqOneOf : false; -type CountExtends = +type CountExtends = + _CountExtends extends infer R extends number ? R : never; +type _CountExtends = TS extends [] ? Acc - : CountExtends, PartElem> extends X ? Inc : Acc>; + : _CountExtends, PartElem> extends X ? Inc : Acc>; type CountOtherwise = TS extends [] ? Acc diff --git a/src/tools/number.ts b/src/tools/number.ts index d08ec2f..462e183 100644 --- a/src/tools/number.ts +++ b/src/tools/number.ts @@ -1,5 +1,6 @@ import type { CompareStrLength, Reverse, StrToNum } from "./string"; +export type Ordering = LT | EQ | GT; export type EQ = 0; export type GT = 1; export type LT = -1; @@ -74,8 +75,13 @@ type _AddDigit = * Compare two natural numbers. */ export type Compare = - _CompareListLength<_ToChars, _ToChars> extends EQ ? _CompareDigits<_ToChars, _ToChars> - : _CompareListLength<_ToChars, _ToChars>; + ( + _CompareListLength<_ToChars, _ToChars> extends EQ ? + _CompareDigits<_ToChars, _ToChars> + : _CompareListLength<_ToChars, _ToChars> + ) extends infer R extends Ordering ? + R + : never; type _CompareListLength = NS extends [unknown, ...infer ATail extends unknown[]] ? MS extends [unknown, ...infer BTail extends unknown[]] ? diff --git a/yarn.lock b/yarn.lock index abbdcf8..8172fde 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,11 +2,6 @@ # yarn lockfile v1 -"@aashutoshrathi/word-wrap@^1.2.3": - version "1.2.6" - resolved "https://registry.yarnpkg.com/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz#bd9154aec9983f77b3a034ecaa015c2e4201f6cf" - integrity sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA== - "@ampproject/remapping@^2.2.1": version "2.3.0" resolved "https://registry.yarnpkg.com/@ampproject/remapping/-/remapping-2.3.0.tgz#ed441b6fa600072520ce18b43d2c8cc8caecc7f4" @@ -2847,16 +2842,16 @@ onetime@^6.0.0: mimic-fn "^4.0.0" optionator@^0.9.3: - version "0.9.3" - resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.9.3.tgz#007397d44ed1872fdc6ed31360190f81814e2c64" - integrity sha512-JjCoypp+jKn1ttEFExxhetCKeJt9zhAgAve5FXHixTvFDW/5aEktX9bufBKLRRMdU7bNtpLfcGu94B3cdEJgjg== + version "0.9.4" + resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.9.4.tgz#7ea1c1a5d91d764fb282139c88fe11e182a3a734" + integrity sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g== dependencies: - "@aashutoshrathi/word-wrap" "^1.2.3" deep-is "^0.1.3" fast-levenshtein "^2.0.6" levn "^0.4.1" prelude-ls "^1.2.1" type-check "^0.4.0" + word-wrap "^1.2.5" p-event@^5.0.1: version "5.0.1" @@ -3094,9 +3089,9 @@ queue-microtask@^1.2.2: integrity sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A== react-is@^18.0.0: - version "18.3.0" - resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.3.0.tgz#6c2d9b6cdd4c2cffb7c89b1bcb57bc44d12f1993" - integrity sha512-wRiUsea88TjKDc4FBEn+sLvIDesp6brMbGWnJGjew2waAc9evdhja/2LvePc898HJbHw0L+MTWy7NhpnELAvLQ== + version "18.3.1" + resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.3.1.tgz#e83557dc12eae63a99e003a46388b1dcbb44db7e" + integrity sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg== readdirp@~3.6.0: version "3.6.0" @@ -3812,6 +3807,11 @@ why-is-node-running@^2.2.2: siginfo "^2.0.0" stackback "0.0.2" +word-wrap@^1.2.5: + version "1.2.5" + resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34" + integrity sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA== + "wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"