typebox 1.3.2 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/guard/guard.mjs
CHANGED
|
@@ -92,7 +92,7 @@ export function IsMultipleOf(dividend, divisor) {
|
|
|
92
92
|
if (IsInteger(dividend) && (1 / divisor) % 1 === 0)
|
|
93
93
|
return true;
|
|
94
94
|
const mod = dividend % divisor;
|
|
95
|
-
return Math.min(Math.abs(mod), Math.abs(mod - divisor)) < tolerance;
|
|
95
|
+
return Math.min(Math.abs(mod), Math.abs(mod - divisor), Math.abs(mod + divisor)) < tolerance;
|
|
96
96
|
}
|
|
97
97
|
// ------------------------------------------------------------------
|
|
98
98
|
// IsClassInstance
|
|
@@ -4,17 +4,17 @@ type TComparer<Left extends TSchema, Right extends TSchema, CompareResult extend
|
|
|
4
4
|
type TInsert<Type extends TSchema, Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TComparer<Type, Left> extends 1 ? TInsert<Type, Right, [...Result, Left]> : [...Result, Type, ...Types] : [...Result, Type]);
|
|
5
5
|
type TSort<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TSort<Right, TInsert<Left, Result>> : Result);
|
|
6
6
|
/**
|
|
7
|
-
* Priority sorts types in sequence of narrowest to broadest using
|
|
8
|
-
* This function is typically used to sequence types for union variant
|
|
9
|
-
* that values are checked against the most narrow types before
|
|
10
|
-
* turn helps ensure order-independent checking.
|
|
7
|
+
* Priority sorts types in sequence of narrowest to broadest using an Insertion Sort
|
|
8
|
+
* algorithm. This function is typically used to sequence types for union variant
|
|
9
|
+
* checks to ensure that values are checked against the most narrow types before
|
|
10
|
+
* the broadest, which in turn helps ensure order-independent Union checking.
|
|
11
11
|
*/
|
|
12
12
|
export type TPriority<Types extends TSchema[], Result extends TSchema[] = TSort<Types>> = Result;
|
|
13
13
|
/**
|
|
14
|
-
* Priority sorts types in sequence of narrowest to broadest using
|
|
15
|
-
* This function is typically used to sequence types for union variant
|
|
16
|
-
* that values are checked against the most narrow types before
|
|
17
|
-
* turn helps ensure order-independent checking.
|
|
14
|
+
* Priority sorts types in sequence of narrowest to broadest using an Insertion Sort
|
|
15
|
+
* algorithm. This function is typically used to sequence types for union variant
|
|
16
|
+
* checks to ensure that values are checked against the most narrow types before
|
|
17
|
+
* the broadest, which in turn helps ensure order-independent Union checking.
|
|
18
18
|
*/
|
|
19
19
|
export declare function Priority<Types extends TSchema[]>(types: [...Types]): TPriority<Types>;
|
|
20
20
|
export {};
|
|
@@ -17,10 +17,10 @@ function Sort(types, result = []) {
|
|
|
17
17
|
return Guard.ShiftLeft(types, (left, right) => Sort(right, Insert(left, result)), () => result);
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
* Priority sorts types in sequence of narrowest to broadest using
|
|
21
|
-
* This function is typically used to sequence types for union variant
|
|
22
|
-
* that values are checked against the most narrow types before
|
|
23
|
-
* turn helps ensure order-independent checking.
|
|
20
|
+
* Priority sorts types in sequence of narrowest to broadest using an Insertion Sort
|
|
21
|
+
* algorithm. This function is typically used to sequence types for union variant
|
|
22
|
+
* checks to ensure that values are checked against the most narrow types before
|
|
23
|
+
* the broadest, which in turn helps ensure order-independent Union checking.
|
|
24
24
|
*/
|
|
25
25
|
export function Priority(types) {
|
|
26
26
|
const result = Sort(types);
|