@inglorious/utils 3.5.1 → 3.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inglorious/utils",
3
- "version": "3.5.1",
3
+ "version": "3.5.3",
4
4
  "description": "A set of general-purpose utility functions designed with functional programming principles in mind.",
5
5
  "author": "IceOnFire <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
6
6
  "license": "MIT",
package/src/v.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * @typedef {import("../types/math").Vector} Vector
3
3
  */
4
4
 
5
- import { isArray } from "./data-structures/array"
5
+ import { isArray } from "./data-structures/array.js"
6
6
 
7
7
  /**
8
8
  * Ensures that a given value is a vector.
package/types/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./algorithms"
2
2
  export * from "./data-structures"
3
3
  export * from "./math"
4
+ export * from "./v"
package/types/v.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ import { Vector } from "./math"
2
+
3
+ /**
4
+ * Ensures that a given value is a vector.
5
+ *
6
+ * If the value is an array of finite numbers but not already a vector (i.e., it lacks the `__isVector__` property),
7
+ * this function converts it into a vector by calling `v()`. If the value is already a vector or not a numeric array,
8
+ * it is returned unchanged. This is particularly useful for ensuring that the results of standard array operations
9
+ * (like `.map()` or `.filter()`) which return a new array are correctly re-tagged as vectors.
10
+ *
11
+ * @template T
12
+ * @param {T} value The value to check and potentially convert.
13
+ * @returns {T extends number[] ? Vector : T} The value as a vector, or the original value if no conversion was needed.
14
+ */
15
+ export function ensureV<T>(value: T): T extends number[] ? Vector : T
16
+
17
+ /**
18
+ * A utility function to create a vector from a list of coordinates.
19
+ * This is a shorthand for `[x, y, z, ...]`.
20
+ * It also tags the array with a non-enumerable `__isVector__` property for
21
+ * efficient type checking.
22
+ * @param {...number} coords - The coordinates of the vector.
23
+ * @returns {Vector} The created vector.
24
+ */
25
+ export function v(...coords: number[]): Vector