@axi-engine/utils 0.2.0 → 0.2.2

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 (51) hide show
  1. package/dist/index.d.mts +35 -1
  2. package/dist/index.d.ts +327 -12
  3. package/dist/index.js +296 -12
  4. package/dist/index.mjs +9 -0
  5. package/package.json +1 -1
  6. package/dist/arrays.d.ts +0 -72
  7. package/dist/arrays.d.ts.map +0 -1
  8. package/dist/arrays.js +0 -115
  9. package/dist/arrays.js.map +0 -1
  10. package/dist/assertion.d.ts +0 -31
  11. package/dist/assertion.d.ts.map +0 -1
  12. package/dist/assertion.js +0 -41
  13. package/dist/assertion.js.map +0 -1
  14. package/dist/config.d.ts +0 -10
  15. package/dist/config.d.ts.map +0 -1
  16. package/dist/config.js +0 -12
  17. package/dist/config.js.map +0 -1
  18. package/dist/constructor-registry.d.ts +0 -40
  19. package/dist/constructor-registry.d.ts.map +0 -1
  20. package/dist/constructor-registry.js +0 -52
  21. package/dist/constructor-registry.js.map +0 -1
  22. package/dist/emitter.d.ts +0 -32
  23. package/dist/emitter.d.ts.map +0 -1
  24. package/dist/emitter.js +0 -43
  25. package/dist/emitter.js.map +0 -1
  26. package/dist/guards.d.ts +0 -12
  27. package/dist/guards.d.ts.map +0 -1
  28. package/dist/guards.js +0 -24
  29. package/dist/guards.js.map +0 -1
  30. package/dist/index.d.ts.map +0 -1
  31. package/dist/index.js.map +0 -1
  32. package/dist/math.d.ts +0 -17
  33. package/dist/math.d.ts.map +0 -1
  34. package/dist/math.js +0 -26
  35. package/dist/math.js.map +0 -1
  36. package/dist/misc.d.ts +0 -7
  37. package/dist/misc.d.ts.map +0 -1
  38. package/dist/misc.js +0 -9
  39. package/dist/misc.js.map +0 -1
  40. package/dist/path.d.ts +0 -10
  41. package/dist/path.d.ts.map +0 -1
  42. package/dist/path.js +0 -14
  43. package/dist/path.js.map +0 -1
  44. package/dist/random.d.ts +0 -14
  45. package/dist/random.d.ts.map +0 -1
  46. package/dist/random.js +0 -21
  47. package/dist/random.js.map +0 -1
  48. package/dist/types.d.ts +0 -50
  49. package/dist/types.d.ts.map +0 -1
  50. package/dist/types.js +0 -2
  51. package/dist/types.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,12 +1,296 @@
1
- //
2
- export * from './arrays';
3
- export * from './assertion';
4
- export * from './config';
5
- export * from './constructor-registry';
6
- export * from './emitter';
7
- export * from './guards';
8
- export * from './math';
9
- export * from './misc';
10
- export * from './path';
11
- export * from './random';
12
- //# sourceMappingURL=index.js.map
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ ConstructorRegistry: () => ConstructorRegistry,
24
+ Emitter: () => Emitter,
25
+ areArraysEqual: () => areArraysEqual,
26
+ axiSettings: () => axiSettings,
27
+ clampNumber: () => clampNumber,
28
+ configure: () => configure,
29
+ ensurePathArray: () => ensurePathArray,
30
+ ensurePathString: () => ensurePathString,
31
+ firstKeyOf: () => firstKeyOf,
32
+ genArray: () => genArray,
33
+ getPercentOf: () => getPercentOf,
34
+ getRandomElement: () => getRandomElement,
35
+ haveSameElements: () => haveSameElements,
36
+ isBoolean: () => isBoolean,
37
+ isNull: () => isNull,
38
+ isNullOrUndefined: () => isNullOrUndefined,
39
+ isNumber: () => isNumber,
40
+ isPercentageString: () => isPercentageString,
41
+ isScalar: () => isScalar,
42
+ isSequentialStart: () => isSequentialStart,
43
+ isString: () => isString,
44
+ isUndefined: () => isUndefined,
45
+ last: () => last,
46
+ randId: () => randId,
47
+ randInt: () => randInt,
48
+ shuffleArray: () => shuffleArray,
49
+ throwIf: () => throwIf,
50
+ throwIfEmpty: () => throwIfEmpty,
51
+ unique: () => unique
52
+ });
53
+ module.exports = __toCommonJS(index_exports);
54
+
55
+ // src/arrays.ts
56
+ function genArray(length) {
57
+ return Array.from({ length }, (_v, i) => i);
58
+ }
59
+ function shuffleArray(array) {
60
+ const result = [...array];
61
+ for (let i = result.length - 1; i > 0; i--) {
62
+ const j = Math.floor(Math.random() * (i + 1));
63
+ [result[i], result[j]] = [result[j], result[i]];
64
+ }
65
+ return result;
66
+ }
67
+ function isSequentialStart(arr1, arr2) {
68
+ if (arr1.length > arr2.length) {
69
+ return false;
70
+ }
71
+ return arr1.every((element, index) => element === arr2[index]);
72
+ }
73
+ function haveSameElements(arr1, arr2) {
74
+ if (!arr1 && !arr2) return true;
75
+ if (!arr1 || !arr2) return false;
76
+ if (arr1.length !== arr2.length) return false;
77
+ const sortedArr1 = [...arr1].sort();
78
+ const sortedArr2 = [...arr2].sort();
79
+ return sortedArr1.every((value, index) => value === sortedArr2[index]);
80
+ }
81
+ function areArraysEqual(arr1, arr2) {
82
+ if (!arr1 && !arr2) return true;
83
+ if (!arr1 || !arr2) return false;
84
+ if (arr1.length !== arr2.length) return false;
85
+ return arr1.every((value, index) => value === arr2[index]);
86
+ }
87
+ function last(array) {
88
+ return array[array.length - 1];
89
+ }
90
+ function unique(array) {
91
+ return [...new Set(array)];
92
+ }
93
+ function getRandomElement(array) {
94
+ if (array.length === 0) {
95
+ return void 0;
96
+ }
97
+ const index = Math.floor(Math.random() * array.length);
98
+ return array[index];
99
+ }
100
+
101
+ // src/guards.ts
102
+ function isScalar(value) {
103
+ const type = typeof value;
104
+ return type === "string" || type === "number" || type === "boolean";
105
+ }
106
+ function isNullOrUndefined(val) {
107
+ return val === void 0 || val === null;
108
+ }
109
+ function isUndefined(val) {
110
+ return typeof val === "undefined";
111
+ }
112
+ function isNumber(val) {
113
+ return typeof val === "number";
114
+ }
115
+ function isBoolean(val) {
116
+ return typeof val === "boolean";
117
+ }
118
+ function isString(val) {
119
+ return typeof val === "string";
120
+ }
121
+ function isNull(val) {
122
+ return val === null;
123
+ }
124
+ function isPercentageString(val) {
125
+ return typeof val === "string" && val.endsWith("%");
126
+ }
127
+
128
+ // src/assertion.ts
129
+ function throwIf(conditionForThrow, exceptionMessage) {
130
+ if (conditionForThrow) {
131
+ throw new Error(exceptionMessage);
132
+ }
133
+ }
134
+ function throwIfEmpty(value, exceptionMessage) {
135
+ const isArrayAndEmpty = Array.isArray(value) && value.length === 0;
136
+ if (isNullOrUndefined(value) || isArrayAndEmpty) {
137
+ throw new Error(exceptionMessage);
138
+ }
139
+ }
140
+
141
+ // src/config.ts
142
+ var defaultConfig = {
143
+ pathSeparator: "/"
144
+ };
145
+ var axiSettings = { ...defaultConfig };
146
+ function configure(newConfig) {
147
+ Object.assign(axiSettings, newConfig);
148
+ }
149
+
150
+ // src/constructor-registry.ts
151
+ var ConstructorRegistry = class {
152
+ items = /* @__PURE__ */ new Map();
153
+ /**
154
+ * Registers a constructor with a unique string identifier.
155
+ *
156
+ * @param typeId - The unique identifier for the constructor (e.g., a static `typeName` property from a class).
157
+ * @param ctor - The class constructor to register.
158
+ * @returns The registry instance for chainable calls.
159
+ * @throws If a constructor with the same `typeId` is already registered.
160
+ */
161
+ register(typeId, ctor) {
162
+ throwIf(this.items.has(typeId), `A constructor with typeId '${typeId}' is already registered.`);
163
+ this.items.set(typeId, ctor);
164
+ return this;
165
+ }
166
+ /**
167
+ * Retrieves a constructor by its identifier.
168
+ *
169
+ * @param typeId - The identifier of the constructor to retrieve.
170
+ * @returns The found class constructor.
171
+ * @throws If no constructor is found for the given `typeId`.
172
+ */
173
+ get(typeId) {
174
+ const Ctor = this.items.get(typeId);
175
+ throwIfEmpty(Ctor, `No constructor found for typeId '${typeId}'`);
176
+ return Ctor;
177
+ }
178
+ /**
179
+ * Checks if a constructor for a given identifier is registered.
180
+ * @param typeId - The identifier to check.
181
+ * @returns `true` if a constructor is registered, otherwise `false`.
182
+ */
183
+ has(typeId) {
184
+ return this.items.has(typeId);
185
+ }
186
+ /**
187
+ * Clears all registered constructors from the registry.
188
+ */
189
+ clear() {
190
+ this.items.clear();
191
+ }
192
+ };
193
+
194
+ // src/emitter.ts
195
+ var Emitter = class {
196
+ listeners = /* @__PURE__ */ new Set();
197
+ /**
198
+ * Returns the number of listeners.
199
+ */
200
+ get listenerCount() {
201
+ return this.listeners.size;
202
+ }
203
+ /**
204
+ * Subscribes a listener to this event.
205
+ * @returns A function to unsubscribe the listener.
206
+ */
207
+ subscribe(listener) {
208
+ this.listeners.add(listener);
209
+ return () => this.listeners.delete(listener);
210
+ }
211
+ /**
212
+ * Manually unsubscribe by listener
213
+ * @returns returns true if an listener has been removed, or false if the listener does not exist.
214
+ */
215
+ unsubscribe(listener) {
216
+ return this.listeners.delete(listener);
217
+ }
218
+ /**
219
+ * Dispatches the event to all subscribed listeners.
220
+ */
221
+ emit(...args) {
222
+ this.listeners.forEach((listener) => listener(...args));
223
+ }
224
+ /**
225
+ * Clears all listeners.
226
+ */
227
+ clear() {
228
+ this.listeners.clear();
229
+ }
230
+ };
231
+
232
+ // src/math.ts
233
+ function clampNumber(val, min, max) {
234
+ if (!isNullOrUndefined(min)) val = Math.max(val, min);
235
+ if (!isNullOrUndefined(max)) val = Math.min(val, max);
236
+ return val;
237
+ }
238
+ function getPercentOf(val, percents) {
239
+ return percents / 100 * val;
240
+ }
241
+
242
+ // src/misc.ts
243
+ function firstKeyOf(obj) {
244
+ return Object.keys(obj)[0];
245
+ }
246
+
247
+ // src/path.ts
248
+ function ensurePathArray(path, separator = axiSettings.pathSeparator) {
249
+ return Array.isArray(path) ? [...path] : path.split(separator);
250
+ }
251
+ function ensurePathString(path, separator = axiSettings.pathSeparator) {
252
+ return !Array.isArray(path) ? path : path.join(separator);
253
+ }
254
+
255
+ // src/random.ts
256
+ var import_uuid = require("uuid");
257
+ function randInt(min, max) {
258
+ min = Math.ceil(min);
259
+ max = Math.floor(max);
260
+ return Math.floor(Math.random() * (max - min) + min);
261
+ }
262
+ function randId() {
263
+ return (0, import_uuid.v4)();
264
+ }
265
+ // Annotate the CommonJS export names for ESM import in node:
266
+ 0 && (module.exports = {
267
+ ConstructorRegistry,
268
+ Emitter,
269
+ areArraysEqual,
270
+ axiSettings,
271
+ clampNumber,
272
+ configure,
273
+ ensurePathArray,
274
+ ensurePathString,
275
+ firstKeyOf,
276
+ genArray,
277
+ getPercentOf,
278
+ getRandomElement,
279
+ haveSameElements,
280
+ isBoolean,
281
+ isNull,
282
+ isNullOrUndefined,
283
+ isNumber,
284
+ isPercentageString,
285
+ isScalar,
286
+ isSequentialStart,
287
+ isString,
288
+ isUndefined,
289
+ last,
290
+ randId,
291
+ randInt,
292
+ shuffleArray,
293
+ throwIf,
294
+ throwIfEmpty,
295
+ unique
296
+ });
package/dist/index.mjs CHANGED
@@ -45,6 +45,10 @@ function getRandomElement(array) {
45
45
  }
46
46
 
47
47
  // src/guards.ts
48
+ function isScalar(value) {
49
+ const type = typeof value;
50
+ return type === "string" || type === "number" || type === "boolean";
51
+ }
48
52
  function isNullOrUndefined(val) {
49
53
  return val === void 0 || val === null;
50
54
  }
@@ -60,6 +64,9 @@ function isBoolean(val) {
60
64
  function isString(val) {
61
65
  return typeof val === "string";
62
66
  }
67
+ function isNull(val) {
68
+ return val === null;
69
+ }
63
70
  function isPercentageString(val) {
64
71
  return typeof val === "string" && val.endsWith("%");
65
72
  }
@@ -216,9 +223,11 @@ export {
216
223
  getRandomElement,
217
224
  haveSameElements,
218
225
  isBoolean,
226
+ isNull,
219
227
  isNullOrUndefined,
220
228
  isNumber,
221
229
  isPercentageString,
230
+ isScalar,
222
231
  isSequentialStart,
223
232
  isString,
224
233
  isUndefined,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axi-engine/utils",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Core utility library for Axi Engine, providing common functions for arrays, math, type guards, and more.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/dist/arrays.d.ts DELETED
@@ -1,72 +0,0 @@
1
- /**
2
- * Generates an array of numbers from 0 to length-1.
3
- * @param length The desired length of the array.
4
- * @returns An array of sequential numbers.
5
- * @example genArray(3); // returns [0, 1, 2]
6
- */
7
- export declare function genArray(length: number): number[];
8
- /**
9
- * Creates a new array with its elements shuffled in a random order.
10
- * This function does not mutate the original array.
11
- * @template T The type of elements in the array.
12
- * @param array The array to shuffle.
13
- * @returns A new, shuffled array.
14
- */
15
- export declare function shuffleArray<T>(array: T[]): T[];
16
- /**
17
- * Checks if the first array is a sequential starting subset of the second array.
18
- * @param arr1 The potential subset array.
19
- * @param arr2 The array to check against.
20
- * @returns `true` if arr1 is a sequential start of arr2, otherwise `false`.
21
- * @example
22
- * isSequentialStart([1, 2], [1, 2, 3]); // true
23
- * isSequentialStart([1, 3], [1, 2, 3]); // false
24
- */
25
- export declare function isSequentialStart<T>(arr1: T[], arr2: T[]): boolean;
26
- /**
27
- * Checks if two arrays contain the same elements, ignoring order.
28
- * Works for arrays of primitives like strings or numbers.
29
- * @template T The type of elements in the array.
30
- * @param arr1 The first array.
31
- * @param arr2 The second array.
32
- * @returns `true` if both arrays contain the same elements, otherwise `false`.
33
- * @example
34
- * haveSameElements(['a', 'b'], ['b', 'a']); // true
35
- * haveSameElements([1, 2, 3], [3, 1, 2]); // true
36
- * haveSameElements(['a', 'b'], ['a', 'c']); // false
37
- */
38
- export declare function haveSameElements<T>(arr1?: T[], arr2?: T[]): boolean;
39
- /**
40
- * Checks if two arrays are strictly equal (same elements in the same order).
41
- * @template T The type of elements in the array.
42
- * @param arr1 The first array.
43
- * @param arr2 The second array.
44
- * @returns `true` if the arrays are strictly equal, otherwise `false`.
45
- * @example
46
- * areArraysEqual(['a', 'b'], ['a', 'b']); // true
47
- * areArraysEqual(['a', 'b'], ['b', 'a']); // false
48
- * areArraysEqual([1, 2], [1, 2, 3]); // false
49
- */
50
- export declare function areArraysEqual<T>(arr1?: T[], arr2?: T[]): boolean;
51
- /**
52
- * Gets the last element of an array.
53
- * @template T The type of elements in the array.
54
- * @param array The array to query.
55
- * @returns The last element of the array, or `undefined` if the array is empty.
56
- */
57
- export declare function last<T>(array: T[]): T | undefined;
58
- /**
59
- * Creates a duplicate-free version of an array.
60
- * @template T The type of elements in the array.
61
- * @param array The array to process.
62
- * @returns A new array with only unique elements.
63
- */
64
- export declare function unique<T>(array: T[]): T[];
65
- /**
66
- * Gets a random element from an array.
67
- * @template T The type of elements in the array.
68
- * @param array The array to choose from.
69
- * @returns A random element from the array, or `undefined` if the array is empty.
70
- */
71
- export declare function getRandomElement<T>(array: T[]): T | undefined;
72
- //# sourceMappingURL=arrays.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"arrays.d.ts","sourceRoot":"","sources":["../src/arrays.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,YAEtC;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAO/C;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,OAAO,CAKlE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,GAAG,OAAO,CAUnE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,GAAG,OAAO,CAMjE;AAED;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,SAAS,CAEjD;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAEzC;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,SAAS,CAM7D"}
package/dist/arrays.js DELETED
@@ -1,115 +0,0 @@
1
- /**
2
- * Generates an array of numbers from 0 to length-1.
3
- * @param length The desired length of the array.
4
- * @returns An array of sequential numbers.
5
- * @example genArray(3); // returns [0, 1, 2]
6
- */
7
- export function genArray(length) {
8
- return Array.from({ length }, (_v, i) => i);
9
- }
10
- /**
11
- * Creates a new array with its elements shuffled in a random order.
12
- * This function does not mutate the original array.
13
- * @template T The type of elements in the array.
14
- * @param array The array to shuffle.
15
- * @returns A new, shuffled array.
16
- */
17
- export function shuffleArray(array) {
18
- const result = [...array];
19
- for (let i = result.length - 1; i > 0; i--) {
20
- const j = Math.floor(Math.random() * (i + 1));
21
- [result[i], result[j]] = [result[j], result[i]];
22
- }
23
- return result;
24
- }
25
- /**
26
- * Checks if the first array is a sequential starting subset of the second array.
27
- * @param arr1 The potential subset array.
28
- * @param arr2 The array to check against.
29
- * @returns `true` if arr1 is a sequential start of arr2, otherwise `false`.
30
- * @example
31
- * isSequentialStart([1, 2], [1, 2, 3]); // true
32
- * isSequentialStart([1, 3], [1, 2, 3]); // false
33
- */
34
- export function isSequentialStart(arr1, arr2) {
35
- if (arr1.length > arr2.length) {
36
- return false;
37
- }
38
- return arr1.every((element, index) => element === arr2[index]);
39
- }
40
- /**
41
- * Checks if two arrays contain the same elements, ignoring order.
42
- * Works for arrays of primitives like strings or numbers.
43
- * @template T The type of elements in the array.
44
- * @param arr1 The first array.
45
- * @param arr2 The second array.
46
- * @returns `true` if both arrays contain the same elements, otherwise `false`.
47
- * @example
48
- * haveSameElements(['a', 'b'], ['b', 'a']); // true
49
- * haveSameElements([1, 2, 3], [3, 1, 2]); // true
50
- * haveSameElements(['a', 'b'], ['a', 'c']); // false
51
- */
52
- export function haveSameElements(arr1, arr2) {
53
- if (!arr1 && !arr2)
54
- return true;
55
- if (!arr1 || !arr2)
56
- return false;
57
- if (arr1.length !== arr2.length)
58
- return false;
59
- // Create sorted copies to compare
60
- const sortedArr1 = [...arr1].sort();
61
- const sortedArr2 = [...arr2].sort();
62
- return sortedArr1.every((value, index) => value === sortedArr2[index]);
63
- }
64
- /**
65
- * Checks if two arrays are strictly equal (same elements in the same order).
66
- * @template T The type of elements in the array.
67
- * @param arr1 The first array.
68
- * @param arr2 The second array.
69
- * @returns `true` if the arrays are strictly equal, otherwise `false`.
70
- * @example
71
- * areArraysEqual(['a', 'b'], ['a', 'b']); // true
72
- * areArraysEqual(['a', 'b'], ['b', 'a']); // false
73
- * areArraysEqual([1, 2], [1, 2, 3]); // false
74
- */
75
- export function areArraysEqual(arr1, arr2) {
76
- if (!arr1 && !arr2)
77
- return true;
78
- if (!arr1 || !arr2)
79
- return false;
80
- if (arr1.length !== arr2.length)
81
- return false;
82
- return arr1.every((value, index) => value === arr2[index]);
83
- }
84
- /**
85
- * Gets the last element of an array.
86
- * @template T The type of elements in the array.
87
- * @param array The array to query.
88
- * @returns The last element of the array, or `undefined` if the array is empty.
89
- */
90
- export function last(array) {
91
- return array[array.length - 1];
92
- }
93
- /**
94
- * Creates a duplicate-free version of an array.
95
- * @template T The type of elements in the array.
96
- * @param array The array to process.
97
- * @returns A new array with only unique elements.
98
- */
99
- export function unique(array) {
100
- return [...new Set(array)];
101
- }
102
- /**
103
- * Gets a random element from an array.
104
- * @template T The type of elements in the array.
105
- * @param array The array to choose from.
106
- * @returns A random element from the array, or `undefined` if the array is empty.
107
- */
108
- export function getRandomElement(array) {
109
- if (array.length === 0) {
110
- return undefined;
111
- }
112
- const index = Math.floor(Math.random() * array.length);
113
- return array[index];
114
- }
115
- //# sourceMappingURL=arrays.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"arrays.js","sourceRoot":"","sources":["../src/arrays.ts"],"names":[],"mappings":"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"}
@@ -1,31 +0,0 @@
1
- /**
2
- * Throws an error if the condition is true.
3
- * @param conditionForThrow - If true, an error will be thrown.
4
- * @param exceptionMessage - The message for the error.
5
- * @throws {Error} if the value is true
6
- */
7
- export declare function throwIf(conditionForThrow: boolean, exceptionMessage: string): void | never;
8
- /**
9
- * Throws an error if the value is null, undefined, or an empty array.
10
- *
11
- * @template T The type of the value being checked.
12
- * @param value The value to check.
13
- * @param exceptionMessage The message for the error.
14
- * @throws {Error} if the value is null, undefined, or an empty array.
15
- *
16
- * @example
17
- * // Example with a potentially undefined variable
18
- * const user: { name: string } | undefined = findUser();
19
- * throwIfEmpty(user, 'User not found');
20
- * // From here, TypeScript knows `user` is not undefined.
21
- * console.log(user.name);
22
- *
23
- * @example
24
- * // Example with an array
25
- * const items: string[] = getItems();
26
- * throwIfEmpty(items, 'Items array cannot be empty');
27
- * // From here, you can safely access items[0] without checking for an empty array again.
28
- * console.log('First item:', items[0]);
29
- */
30
- export declare function throwIfEmpty<T>(value: T, exceptionMessage: string): asserts value is NonNullable<T>;
31
- //# sourceMappingURL=assertion.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"assertion.d.ts","sourceRoot":"","sources":["../src/assertion.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,iBAAiB,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,GAAG,IAAI,GAAG,KAAK,CAI1F;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC5B,KAAK,EAAE,CAAC,EACR,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,KAAK,IAAI,WAAW,CAAC,CAAC,CAAC,CAMjC"}
package/dist/assertion.js DELETED
@@ -1,41 +0,0 @@
1
- import { isNullOrUndefined } from './guards';
2
- /**
3
- * Throws an error if the condition is true.
4
- * @param conditionForThrow - If true, an error will be thrown.
5
- * @param exceptionMessage - The message for the error.
6
- * @throws {Error} if the value is true
7
- */
8
- export function throwIf(conditionForThrow, exceptionMessage) {
9
- if (conditionForThrow) {
10
- throw new Error(exceptionMessage);
11
- }
12
- }
13
- /**
14
- * Throws an error if the value is null, undefined, or an empty array.
15
- *
16
- * @template T The type of the value being checked.
17
- * @param value The value to check.
18
- * @param exceptionMessage The message for the error.
19
- * @throws {Error} if the value is null, undefined, or an empty array.
20
- *
21
- * @example
22
- * // Example with a potentially undefined variable
23
- * const user: { name: string } | undefined = findUser();
24
- * throwIfEmpty(user, 'User not found');
25
- * // From here, TypeScript knows `user` is not undefined.
26
- * console.log(user.name);
27
- *
28
- * @example
29
- * // Example with an array
30
- * const items: string[] = getItems();
31
- * throwIfEmpty(items, 'Items array cannot be empty');
32
- * // From here, you can safely access items[0] without checking for an empty array again.
33
- * console.log('First item:', items[0]);
34
- */
35
- export function throwIfEmpty(value, exceptionMessage) {
36
- const isArrayAndEmpty = Array.isArray(value) && value.length === 0;
37
- if (isNullOrUndefined(value) || isArrayAndEmpty) {
38
- throw new Error(exceptionMessage);
39
- }
40
- }
41
- //# sourceMappingURL=assertion.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"assertion.js","sourceRoot":"","sources":["../src/assertion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAC,MAAM,UAAU,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAC,iBAA0B,EAAE,gBAAwB;IAC1E,IAAI,iBAAiB,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;IACpC,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,YAAY,CAC1B,KAAQ,EACR,gBAAwB;IAExB,MAAM,eAAe,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;IAEnE,IAAI,iBAAiB,CAAC,KAAK,CAAC,IAAI,eAAe,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;IACpC,CAAC;AACH,CAAC"}
package/dist/config.d.ts DELETED
@@ -1,10 +0,0 @@
1
- export interface AxiEngineConfig {
2
- pathSeparator: string;
3
- }
4
- export declare const axiSettings: AxiEngineConfig;
5
- /**
6
- * set up global configuration for axi-engine.
7
- * @param newConfig - configuration object
8
- */
9
- export declare function configure(newConfig: Partial<AxiEngineConfig>): void;
10
- //# sourceMappingURL=config.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,aAAa,EAAE,MAAM,CAAC;CAKvB;AAMD,eAAO,MAAM,WAAW,EAAE,eAAsC,CAAC;AAEjE;;;GAGG;AACH,wBAAgB,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,IAAI,CAEnE"}
package/dist/config.js DELETED
@@ -1,12 +0,0 @@
1
- const defaultConfig = {
2
- pathSeparator: '/'
3
- };
4
- export const axiSettings = { ...defaultConfig };
5
- /**
6
- * set up global configuration for axi-engine.
7
- * @param newConfig - configuration object
8
- */
9
- export function configure(newConfig) {
10
- Object.assign(axiSettings, newConfig);
11
- }
12
- //# sourceMappingURL=config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAQA,MAAM,aAAa,GAAoB;IACrC,aAAa,EAAE,GAAG;CACnB,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAoB,EAAE,GAAG,aAAa,EAAE,CAAC;AAEjE;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,SAAmC;IAC3D,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;AACxC,CAAC"}