@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.
Files changed (63) hide show
  1. package/.turbo/turbo-build.log +15 -15
  2. package/dist/bounds-8OC_obRs.js +186 -0
  3. package/dist/bounds-CRK04jp7.cjs +1 -0
  4. package/dist/bounds.cjs +1 -1
  5. package/dist/bounds.js +1 -1
  6. package/dist/deep.cjs +1 -1
  7. package/dist/deep.js +1 -1
  8. package/dist/{external-Birv9jaY.js → external-BM_NS5yM.js} +6 -6
  9. package/dist/external-E3ErJeeM.cjs +1 -0
  10. package/dist/index.cjs +3 -3
  11. package/dist/index.js +235 -229
  12. package/dist/{path-DVFrKaNI.js → path-Blh4wJuA.js} +24 -21
  13. package/dist/path-CPSfCjde.cjs +1 -0
  14. package/dist/{scale-C6qKDbRb.cjs → scale-C3fEtXxW.cjs} +1 -1
  15. package/dist/{scale-EWNUk-bn.js → scale-Db1Gunj0.js} +1 -1
  16. package/dist/scale.cjs +1 -1
  17. package/dist/scale.js +1 -1
  18. package/dist/series-BcF7A8Je.cjs +6 -0
  19. package/dist/{series-EA1uaEDj.js → series-Cl3Vh_u-.js} +588 -471
  20. package/dist/spatial.cjs +1 -1
  21. package/dist/spatial.js +2 -2
  22. package/dist/src/breaker/breaker.d.ts +2 -1
  23. package/dist/src/breaker/breaker.d.ts.map +1 -1
  24. package/dist/src/deep/path.d.ts.map +1 -1
  25. package/dist/src/id/id.d.ts +3 -1
  26. package/dist/src/id/id.d.ts.map +1 -1
  27. package/dist/src/math/math.d.ts +2 -1
  28. package/dist/src/math/math.d.ts.map +1 -1
  29. package/dist/src/status/status.d.ts +1 -0
  30. package/dist/src/status/status.d.ts.map +1 -1
  31. package/dist/src/strings/strings.d.ts +1 -1
  32. package/dist/src/strings/strings.d.ts.map +1 -1
  33. package/dist/src/telem/series.d.ts +7 -0
  34. package/dist/src/telem/series.d.ts.map +1 -1
  35. package/dist/src/telem/telem.d.ts +78 -1
  36. package/dist/src/telem/telem.d.ts.map +1 -1
  37. package/dist/src/zod/util.d.ts.map +1 -1
  38. package/dist/telem.cjs +1 -1
  39. package/dist/telem.js +1 -1
  40. package/dist/zod.cjs +1 -1
  41. package/dist/zod.js +1 -1
  42. package/package.json +3 -3
  43. package/src/breaker/breaker.ts +4 -0
  44. package/src/deep/path.spec.ts +14 -0
  45. package/src/deep/path.ts +9 -2
  46. package/src/id/id.ts +8 -4
  47. package/src/math/math.spec.ts +20 -0
  48. package/src/math/math.ts +32 -29
  49. package/src/spatial/bounds/bounds.ts +1 -1
  50. package/src/status/status.ts +11 -0
  51. package/src/strings/strings.spec.ts +3 -0
  52. package/src/strings/strings.ts +2 -1
  53. package/src/telem/series.spec.ts +543 -2
  54. package/src/telem/series.ts +28 -9
  55. package/src/telem/telem.spec.ts +556 -0
  56. package/src/telem/telem.ts +118 -5
  57. package/src/zod/util.ts +5 -3
  58. package/tsconfig.tsbuildinfo +1 -1
  59. package/dist/bounds-D6e9xoHt.cjs +0 -1
  60. package/dist/bounds-Dj9nG39I.js +0 -174
  61. package/dist/external-DsmsSN1Y.cjs +0 -1
  62. package/dist/path-BeMr8xWN.cjs +0 -1
  63. 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 = <V extends Numeric>(a: V, b: Numeric): V => {
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 = <V extends Numeric>(a: V, b: Numeric): V => {
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 = <V extends Numeric>(a: V, b: Numeric): boolean => {
32
- if (typeof a === "bigint") return a === BigInt(b);
33
- return a === Number(b);
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 = <V extends Numeric>(a: V, b: Numeric): V => {
49
- if (a <= b) return a;
50
- if (typeof a === "bigint") return (a <= b ? a : BigInt(b)) as V;
51
- return (a <= b ? a : Number(b)) as V;
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 = <V extends Numeric>(a: V, b: Numeric): V => {
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 < 0) return -a as V;
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 = <V extends Numeric>(a: V, b: Numeric): V => {
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 = <V extends Numeric>(a: V, b: Numeric): V => {
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;
@@ -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
 
@@ -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];