@axi-engine/utils 0.1.7 → 0.1.9

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 (50) hide show
  1. package/README.md +1 -4
  2. package/dist/arrays.d.ts +72 -0
  3. package/dist/arrays.d.ts.map +1 -0
  4. package/dist/arrays.js +115 -0
  5. package/dist/arrays.js.map +1 -0
  6. package/dist/assertion.d.ts +31 -0
  7. package/dist/assertion.d.ts.map +1 -0
  8. package/dist/assertion.js +41 -0
  9. package/dist/assertion.js.map +1 -0
  10. package/dist/config.d.ts +10 -0
  11. package/dist/config.d.ts.map +1 -0
  12. package/dist/config.js +12 -0
  13. package/dist/config.js.map +1 -0
  14. package/dist/constructor-registry.d.ts +40 -0
  15. package/dist/constructor-registry.d.ts.map +1 -0
  16. package/dist/constructor-registry.js +52 -0
  17. package/dist/constructor-registry.js.map +1 -0
  18. package/dist/emitter.d.ts +32 -0
  19. package/dist/emitter.d.ts.map +1 -0
  20. package/dist/emitter.js +43 -0
  21. package/dist/emitter.js.map +1 -0
  22. package/dist/guards.d.ts +12 -0
  23. package/dist/guards.d.ts.map +1 -0
  24. package/dist/guards.js +24 -0
  25. package/dist/guards.js.map +1 -0
  26. package/dist/index.d.ts +12 -293
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +12 -285
  29. package/dist/index.js.map +1 -0
  30. package/dist/math.d.ts +17 -0
  31. package/dist/math.d.ts.map +1 -0
  32. package/dist/math.js +26 -0
  33. package/dist/math.js.map +1 -0
  34. package/dist/misc.d.ts +7 -0
  35. package/dist/misc.d.ts.map +1 -0
  36. package/dist/misc.js +9 -0
  37. package/dist/misc.js.map +1 -0
  38. package/dist/path.d.ts +10 -0
  39. package/dist/path.d.ts.map +1 -0
  40. package/dist/path.js +14 -0
  41. package/dist/path.js.map +1 -0
  42. package/dist/random.d.ts +14 -0
  43. package/dist/random.d.ts.map +1 -0
  44. package/dist/random.js +21 -0
  45. package/dist/random.js.map +1 -0
  46. package/dist/types.d.ts +50 -0
  47. package/dist/types.d.ts.map +1 -0
  48. package/dist/types.js +2 -0
  49. package/dist/types.js.map +1 -0
  50. package/package.json +7 -2
package/dist/path.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { PathType } from "./types";
2
+ /**
3
+ * Ensures that the given path is returned as an array of segments.
4
+ */
5
+ export declare function ensurePathArray(path: PathType, separator?: string): string[];
6
+ /**
7
+ * Ensures that the given path is returned as a single string.
8
+ */
9
+ export declare function ensurePathString(path: PathType, separator?: string): string;
10
+ //# sourceMappingURL=path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../src/path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,SAAS,CAAC;AAGjC;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,SAA4B,GAAG,MAAM,EAAE,CAE/F;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,SAA4B,GAAG,MAAM,CAE9F"}
package/dist/path.js ADDED
@@ -0,0 +1,14 @@
1
+ import { axiSettings } from './config';
2
+ /**
3
+ * Ensures that the given path is returned as an array of segments.
4
+ */
5
+ export function ensurePathArray(path, separator = axiSettings.pathSeparator) {
6
+ return Array.isArray(path) ? [...path] : path.split(separator);
7
+ }
8
+ /**
9
+ * Ensures that the given path is returned as a single string.
10
+ */
11
+ export function ensurePathString(path, separator = axiSettings.pathSeparator) {
12
+ return !Array.isArray(path) ? path : path.join(separator);
13
+ }
14
+ //# sourceMappingURL=path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.js","sourceRoot":"","sources":["../src/path.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,WAAW,EAAC,MAAM,UAAU,CAAC;AAErC;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,IAAc,EAAE,SAAS,GAAG,WAAW,CAAC,aAAa;IACnF,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AACjE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAc,EAAE,SAAS,GAAG,WAAW,CAAC,aAAa;IACpF,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AAC5D,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Returns a random integer between min (inclusive) and max (exclusive).
3
+ * @param min The minimum integer (inclusive).
4
+ * @param max The maximum integer (exclusive).
5
+ * @returns A random integer.
6
+ * @example randInt(1, 5); // returns 1, 2, 3, or 4
7
+ */
8
+ export declare function randInt(min: number, max: number): number;
9
+ /**
10
+ * Generates a unique identifier using uuidv4.
11
+ * @returns A unique string ID.
12
+ */
13
+ export declare function randId(): string;
14
+ //# sourceMappingURL=random.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAIxD;AAED;;;GAGG;AACH,wBAAgB,MAAM,WAErB"}
package/dist/random.js ADDED
@@ -0,0 +1,21 @@
1
+ import { v4 as uuidv4 } from 'uuid';
2
+ /**
3
+ * Returns a random integer between min (inclusive) and max (exclusive).
4
+ * @param min The minimum integer (inclusive).
5
+ * @param max The maximum integer (exclusive).
6
+ * @returns A random integer.
7
+ * @example randInt(1, 5); // returns 1, 2, 3, or 4
8
+ */
9
+ export function randInt(min, max) {
10
+ min = Math.ceil(min);
11
+ max = Math.floor(max);
12
+ return Math.floor(Math.random() * (max - min) + min);
13
+ }
14
+ /**
15
+ * Generates a unique identifier using uuidv4.
16
+ * @returns A unique string ID.
17
+ */
18
+ export function randId() {
19
+ return uuidv4();
20
+ }
21
+ //# sourceMappingURL=random.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"random.js","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAC,GAAW,EAAE,GAAW;IAC9C,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrB,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACtB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC;AACvD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,MAAM;IACpB,OAAO,MAAM,EAAE,CAAC;AAClB,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Represents a path that can be provided as a single string
3
+ * or an array of segments.
4
+ * @example
5
+ * 'player/stats/health'
6
+ * ['player', 'stats', 'health']
7
+ */
8
+ export type PathType = string | string[];
9
+ /**
10
+ * Represents a generic constructor for any class.
11
+ *
12
+ * This utility type is essential for implementing higher-order patterns
13
+ * like mixins, where a function takes a class as an argument and returns
14
+ * a new, extended class.
15
+ *
16
+ * The `...args: any[]` signature allows it to represent constructors
17
+ * with any number and type of arguments, making it universally applicable.
18
+ *
19
+ * @template T - The type of the instance created by the constructor. Defaults to `{}`.
20
+ *
21
+ * @example
22
+ * // Used as a constraint for a base class in a mixin
23
+ * function Timestamped<TBase extends Constructor>(Base: TBase) {
24
+ * return class extends Base {
25
+ * timestamp = new Date();
26
+ * };
27
+ * }
28
+ *
29
+ * class User {}
30
+ * const TimestampedUser = Timestamped(User);
31
+ * const userInstance = new TimestampedUser();
32
+ * console.log(userInstance.timestamp); // Logs the current date
33
+ */
34
+ export type Constructor<T = {}> = new (...args: any[]) => T;
35
+ /**
36
+ * Defines the public, read-only contract for an event emitter.
37
+ * It allows subscribing to an event but not emitting it.
38
+ * @template T A tuple representing the types of the event arguments.
39
+ */
40
+ export type Subscribable<T extends any[]> = {
41
+ readonly listenerCount: number;
42
+ /**
43
+ * Subscribes a listener to this event.
44
+ * @returns A function to unsubscribe the listener.
45
+ */
46
+ subscribe(listener: (...args: T) => void): () => void;
47
+ unsubscribe(listener: (...args: T) => void): boolean;
48
+ clear(): void;
49
+ };
50
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,EAAE,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAE5D;;;;GAIG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI;IAC1C,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAE/B;;;OAGG;IACH,SAAS,CAAC,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAEtD,WAAW,CAAC,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC;IAErD,KAAK,IAAI,IAAI,CAAC;CACf,CAAA"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,8 +1,13 @@
1
1
  {
2
2
  "name": "@axi-engine/utils",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Core utility library for Axi Engine, providing common functions for arrays, math, type guards, and more.",
5
5
  "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/axijs/engine.git",
9
+ "directory": "packages/utils"
10
+ },
6
11
  "keywords": [
7
12
  "axi-engine",
8
13
  "typescript",
@@ -20,7 +25,7 @@
20
25
  }
21
26
  },
22
27
  "scripts": {
23
- "build": "tsup src/index.ts --format cjs,esm --dts --clean",
28
+ "build": "tsup",
24
29
  "docs": "typedoc src/index.ts --out docs/api --options ../../typedoc.json",
25
30
  "test": "echo 'No tests yet for @axi-engine/utils'"
26
31
  },