@synnaxlabs/x 0.44.2 → 0.44.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/.turbo/turbo-build.log +15 -15
- package/dist/bounds-8OC_obRs.js +186 -0
- package/dist/bounds-CRK04jp7.cjs +1 -0
- package/dist/bounds.cjs +1 -1
- package/dist/bounds.js +1 -1
- package/dist/deep.cjs +1 -1
- package/dist/deep.js +1 -1
- package/dist/{external-Birv9jaY.js → external-BM_NS5yM.js} +6 -6
- package/dist/external-E3ErJeeM.cjs +1 -0
- package/dist/index.cjs +3 -3
- package/dist/index.js +235 -229
- package/dist/{path-DVFrKaNI.js → path-Blh4wJuA.js} +24 -21
- package/dist/path-CPSfCjde.cjs +1 -0
- package/dist/{scale-C6qKDbRb.cjs → scale-C3fEtXxW.cjs} +1 -1
- package/dist/{scale-EWNUk-bn.js → scale-Db1Gunj0.js} +1 -1
- package/dist/scale.cjs +1 -1
- package/dist/scale.js +1 -1
- package/dist/series-BcF7A8Je.cjs +6 -0
- package/dist/{series-EA1uaEDj.js → series-Cl3Vh_u-.js} +588 -471
- package/dist/spatial.cjs +1 -1
- package/dist/spatial.js +2 -2
- package/dist/src/breaker/breaker.d.ts +2 -1
- package/dist/src/breaker/breaker.d.ts.map +1 -1
- package/dist/src/deep/path.d.ts.map +1 -1
- package/dist/src/id/id.d.ts +3 -1
- package/dist/src/id/id.d.ts.map +1 -1
- package/dist/src/math/math.d.ts +2 -1
- package/dist/src/math/math.d.ts.map +1 -1
- package/dist/src/status/status.d.ts +1 -0
- package/dist/src/status/status.d.ts.map +1 -1
- package/dist/src/strings/strings.d.ts +1 -1
- package/dist/src/strings/strings.d.ts.map +1 -1
- package/dist/src/telem/series.d.ts +7 -0
- package/dist/src/telem/series.d.ts.map +1 -1
- package/dist/src/telem/telem.d.ts +78 -1
- package/dist/src/telem/telem.d.ts.map +1 -1
- package/dist/src/zod/util.d.ts.map +1 -1
- package/dist/telem.cjs +1 -1
- package/dist/telem.js +1 -1
- package/dist/zod.cjs +1 -1
- package/dist/zod.js +1 -1
- package/package.json +3 -3
- package/src/breaker/breaker.ts +4 -0
- package/src/deep/path.spec.ts +14 -0
- package/src/deep/path.ts +9 -2
- package/src/id/id.ts +8 -4
- package/src/math/math.spec.ts +20 -0
- package/src/math/math.ts +32 -29
- package/src/spatial/bounds/bounds.ts +1 -1
- package/src/status/status.ts +11 -0
- package/src/strings/strings.spec.ts +3 -0
- package/src/strings/strings.ts +2 -1
- package/src/telem/series.spec.ts +543 -2
- package/src/telem/series.ts +28 -9
- package/src/telem/telem.spec.ts +556 -0
- package/src/telem/telem.ts +118 -5
- package/src/zod/util.ts +5 -3
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/bounds-D6e9xoHt.cjs +0 -1
- package/dist/bounds-Dj9nG39I.js +0 -174
- package/dist/external-DsmsSN1Y.cjs +0 -1
- package/dist/path-BeMr8xWN.cjs +0 -1
- package/dist/series-CcA_WjbJ.cjs +0 -6
package/src/math/math.ts
CHANGED
|
@@ -10,27 +10,38 @@
|
|
|
10
10
|
/** A numeric value is either a a number, or a bigint. */
|
|
11
11
|
export type Numeric = number | bigint;
|
|
12
12
|
|
|
13
|
+
const multiCoercedOp =
|
|
14
|
+
(func: (a: number, b: number) => Numeric) =>
|
|
15
|
+
<V extends Numeric>(a: V, b: Numeric): V => {
|
|
16
|
+
if (typeof a === "bigint") {
|
|
17
|
+
if (isInteger(b))
|
|
18
|
+
return func(a as unknown as number, BigInt(b) as unknown as number) as V;
|
|
19
|
+
const res = func(Number(a), Number(b)) as number;
|
|
20
|
+
if (typeof res === "number") return BigInt(Math.round(res)) as V;
|
|
21
|
+
return res;
|
|
22
|
+
}
|
|
23
|
+
return func(Number(a), Number(b)) as V;
|
|
24
|
+
};
|
|
25
|
+
|
|
13
26
|
/**
|
|
14
27
|
* @returns the product of a and b, coercing b to the type of a if necessary. */
|
|
15
|
-
export const sub =
|
|
16
|
-
if (typeof a === "bigint") return (a - BigInt(b)) as V;
|
|
17
|
-
return (a - Number(b)) as V;
|
|
18
|
-
};
|
|
28
|
+
export const sub = multiCoercedOp((a, b) => a - b);
|
|
19
29
|
|
|
20
30
|
/** @returns the sum of a and b, coercing b to the type of a if necessary. */
|
|
21
|
-
export const add =
|
|
22
|
-
if (typeof a === "bigint") return (a + BigInt(b)) as V;
|
|
23
|
-
return ((a as unknown as number) + Number(b)) as V;
|
|
24
|
-
};
|
|
31
|
+
export const add = multiCoercedOp((a, b) => a + b);
|
|
25
32
|
|
|
26
33
|
/** @returns true if a is close to b within epsilon. */
|
|
27
34
|
export const closeTo = (a: number, b: number, epsilon = 0.0001): boolean =>
|
|
28
35
|
Math.abs(a - b) < epsilon;
|
|
29
36
|
|
|
30
37
|
/** @returns true if a is equal to b, coercing b to the type of a if necessary. */
|
|
31
|
-
export const equal =
|
|
32
|
-
|
|
33
|
-
|
|
38
|
+
export const equal = (a: Numeric, b: Numeric): boolean => {
|
|
39
|
+
const aIsBigInt = typeof a === "bigint";
|
|
40
|
+
const bIsBigInt = typeof b === "bigint";
|
|
41
|
+
if (aIsBigInt && bIsBigInt) return a === b;
|
|
42
|
+
if (aIsBigInt && isInteger(b)) return a === BigInt(b);
|
|
43
|
+
if (bIsBigInt && isInteger(a)) return b === BigInt(a);
|
|
44
|
+
return a === b;
|
|
34
45
|
};
|
|
35
46
|
|
|
36
47
|
/**
|
|
@@ -45,32 +56,24 @@ export const roundToNearestMagnitude = (num: number): number => {
|
|
|
45
56
|
};
|
|
46
57
|
|
|
47
58
|
/** @returns the minimum of a and b, coercing b to the type of a if necessary. */
|
|
48
|
-
export const min =
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
59
|
+
export const min = multiCoercedOp((a, b) => (a <= b ? a : b));
|
|
60
|
+
|
|
61
|
+
export const isInteger = (a: Numeric): boolean => {
|
|
62
|
+
if (typeof a === "bigint") return true;
|
|
63
|
+
return Number.isInteger(a);
|
|
52
64
|
};
|
|
53
65
|
|
|
54
66
|
/** @returns the maximum of a and b, coercing b to the type of a if necessary. */
|
|
55
|
-
export const max =
|
|
56
|
-
if (typeof a === "bigint") return (a >= b ? a : BigInt(b)) as V;
|
|
57
|
-
return (a >= b ? a : Number(b)) as V;
|
|
58
|
-
};
|
|
67
|
+
export const max = multiCoercedOp((a, b) => (a >= b ? a : b));
|
|
59
68
|
|
|
60
69
|
/** @returns the absolute value of a. */
|
|
61
70
|
export const abs = <V extends Numeric>(a: V): V => {
|
|
62
|
-
if (a
|
|
63
|
-
return a;
|
|
71
|
+
if (typeof a === "bigint") return (a < 0n ? -a : a) as V;
|
|
72
|
+
return (a < 0 ? -a : a) as V;
|
|
64
73
|
};
|
|
65
74
|
|
|
66
75
|
/** @returns the multiplication of a and b, coercing b to the type of a if necessary. */
|
|
67
|
-
export const mult =
|
|
68
|
-
if (typeof a === "bigint") return (a * BigInt(b)) as V;
|
|
69
|
-
return (a * Number(b)) as V;
|
|
70
|
-
};
|
|
76
|
+
export const mult = multiCoercedOp((a, b) => a * b);
|
|
71
77
|
|
|
72
78
|
/** @returns the division of a and b, coercing b to the type of a if necessary. */
|
|
73
|
-
export const div =
|
|
74
|
-
if (typeof a === "bigint") return (a / BigInt(b)) as V;
|
|
75
|
-
return (a / Number(b)) as V;
|
|
76
|
-
};
|
|
79
|
+
export const div = multiCoercedOp((a, b) => a / b);
|
|
@@ -615,7 +615,7 @@ export const traverse = <T extends numeric.Value = number>(
|
|
|
615
615
|
currentPosition,
|
|
616
616
|
dir > 0 ? moveDist : -moveDist,
|
|
617
617
|
) as T;
|
|
618
|
-
remainingDist = math.sub(remainingDist, dir > 0 ? moveDist : -moveDist);
|
|
618
|
+
remainingDist = math.sub<T>(remainingDist, dir > 0 ? moveDist : -moveDist);
|
|
619
619
|
|
|
620
620
|
// If we've exhausted the distance, return the current position
|
|
621
621
|
if (math.equal(remainingDist, 0)) return currentPosition as T;
|
package/src/status/status.ts
CHANGED
|
@@ -89,3 +89,14 @@ export const create = <D = undefined, V extends Variant = Variant>(
|
|
|
89
89
|
time: TimeStamp.now(),
|
|
90
90
|
...spec,
|
|
91
91
|
}) as unknown as Status<D, V>;
|
|
92
|
+
|
|
93
|
+
export const filterVariant = (
|
|
94
|
+
variant: Variant,
|
|
95
|
+
only: Variant | Variant[] = [],
|
|
96
|
+
): Variant | undefined => {
|
|
97
|
+
if (Array.isArray(only)) {
|
|
98
|
+
if (only.includes(variant)) return variant;
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
return only === variant ? variant : undefined;
|
|
102
|
+
};
|
|
@@ -15,6 +15,9 @@ describe("naturalLanguageJoin", () => {
|
|
|
15
15
|
it("should return an empty string for an empty array", () =>
|
|
16
16
|
expect(strings.naturalLanguageJoin([])).toBe(""));
|
|
17
17
|
|
|
18
|
+
it("should return the string for a single string", () =>
|
|
19
|
+
expect(strings.naturalLanguageJoin("apple")).toBe("apple"));
|
|
20
|
+
|
|
18
21
|
it("should return the zeroLength string for an empty array if provided", () =>
|
|
19
22
|
expect(strings.naturalLanguageJoin([], "No items")).toBe("No items"));
|
|
20
23
|
|
package/src/strings/strings.ts
CHANGED
|
@@ -24,9 +24,10 @@
|
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
26
|
export const naturalLanguageJoin = (
|
|
27
|
-
strings: string[],
|
|
27
|
+
strings: string | string[],
|
|
28
28
|
zeroLength: string = "",
|
|
29
29
|
): string => {
|
|
30
|
+
if (typeof strings === "string") return strings;
|
|
30
31
|
const length = strings.length;
|
|
31
32
|
if (length === 0) return zeroLength;
|
|
32
33
|
if (length === 1) return strings[0];
|