@axi-engine/utils 0.2.6 → 0.2.7

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/dist/index.d.mts CHANGED
@@ -270,12 +270,64 @@ declare class Emitter<T extends any[]> implements Subscribable<T> {
270
270
  * @returns True if the value is a string, number, or boolean.
271
271
  */
272
272
  declare function isScalar(value: unknown): value is ScalarType;
273
- declare function isNullOrUndefined(val: unknown): val is null | undefined;
273
+ /**
274
+ * Type guard that checks if a value is `null`.
275
+ * @param val The value to check.
276
+ * @returns {boolean} `true` if the value is `null`, otherwise `false`.
277
+ */
278
+ declare function isNull(val: unknown): val is null;
279
+ /**
280
+ * Type guard that checks if a value is `undefined`.
281
+ * @param val The value to check.
282
+ * @returns {boolean} `true` if the value is `undefined`, otherwise `false`.
283
+ */
274
284
  declare function isUndefined(val: unknown): val is undefined;
285
+ /**
286
+ * Type guard that checks if a value is either `null` or `undefined`.
287
+ * @param val The value to check.
288
+ * @returns {boolean} `true` if the value is `null` or `undefined`, otherwise `false`.
289
+ */
290
+ declare function isNullOrUndefined(val: unknown): val is null | undefined;
291
+ /**
292
+ * Type guard that checks if a value is a `number`.
293
+ * @param val The value to check.
294
+ * @returns {boolean} `true` if the value is a `number`, otherwise `false`.
295
+ */
275
296
  declare function isNumber(val: unknown): val is number;
297
+ /**
298
+ * Type guard that checks if a value is a `boolean`.
299
+ * @param val The value to check.
300
+ * @returns {boolean} `true` if the value is a `boolean`, otherwise `false`.
301
+ */
276
302
  declare function isBoolean(val: unknown): val is boolean;
303
+ /**
304
+ * Type guard that checks if a value is a `string`.
305
+ * @param val The value to check.
306
+ * @returns {boolean} `true` if the value is a `string`, otherwise `false`.
307
+ */
277
308
  declare function isString(val: unknown): val is string;
278
- declare function isNull(val: unknown): val is null;
309
+ /**
310
+ * Check if a value is a plain object.
311
+ * Correctly handles `null` and arrays, returning `false` for them.
312
+ *
313
+ * @param value The value to check.
314
+ * @returns {boolean} `true` if the value is a non-null, non-array object.
315
+ */
316
+ declare function isObject(value: unknown): value is Record<PropertyKey, unknown>;
317
+ /**
318
+ * Type guard that checks if a value is a function.
319
+ *
320
+ * @param value The value to check.
321
+ * @returns {boolean} `true` if the value is a function.
322
+ */
323
+ declare function isFunction(value: unknown): value is (...args: any[]) => any;
324
+ /**
325
+ * Type guard that checks if a value is a Promise-like object.
326
+ *
327
+ * @param value The value to check.
328
+ * @returns {boolean} `true` if the value has a `then` function.
329
+ */
330
+ declare function isPromise(value: unknown): value is Promise<unknown>;
279
331
  /**
280
332
  * Type guard to check if a value is a string that ends with '%'.
281
333
  * @param val The value to check.
@@ -338,7 +390,7 @@ declare function randId(): string;
338
390
  * @template K - The type of the key (must be a string).
339
391
  * @template V - The type of the value being stored.
340
392
  */
341
- declare class Registry<K extends string, V> {
393
+ declare class Registry<K extends PropertyKey, V> {
342
394
  protected readonly items: Map<K, V>;
343
395
  /**
344
396
  * Registers an item with a specific key.
@@ -372,4 +424,4 @@ declare class Registry<K extends string, V> {
372
424
  clear(): void;
373
425
  }
374
426
 
375
- export { type AxiEngineConfig, type Constructor, type DataSink, type DataSource, type DataStorage, Emitter, type PathType, Registry, type ScalarType, type Subscribable, areArraysEqual, axiSettings, clampNumber, configure, ensurePathArray, ensurePathString, firstKeyOf, genArray, getPercentOf, getRandomElement, haveSameElements, isBoolean, isNull, isNullOrUndefined, isNumber, isPercentageString, isScalar, isSequentialStart, isString, isUndefined, last, randId, randInt, shuffleArray, throwError, throwIf, throwIfEmpty, unique };
427
+ export { type AxiEngineConfig, type Constructor, type DataSink, type DataSource, type DataStorage, Emitter, type PathType, Registry, type ScalarType, type Subscribable, areArraysEqual, axiSettings, clampNumber, configure, ensurePathArray, ensurePathString, firstKeyOf, genArray, getPercentOf, getRandomElement, haveSameElements, isBoolean, isFunction, isNull, isNullOrUndefined, isNumber, isObject, isPercentageString, isPromise, isScalar, isSequentialStart, isString, isUndefined, last, randId, randInt, shuffleArray, throwError, throwIf, throwIfEmpty, unique };
package/dist/index.d.ts CHANGED
@@ -270,12 +270,64 @@ declare class Emitter<T extends any[]> implements Subscribable<T> {
270
270
  * @returns True if the value is a string, number, or boolean.
271
271
  */
272
272
  declare function isScalar(value: unknown): value is ScalarType;
273
- declare function isNullOrUndefined(val: unknown): val is null | undefined;
273
+ /**
274
+ * Type guard that checks if a value is `null`.
275
+ * @param val The value to check.
276
+ * @returns {boolean} `true` if the value is `null`, otherwise `false`.
277
+ */
278
+ declare function isNull(val: unknown): val is null;
279
+ /**
280
+ * Type guard that checks if a value is `undefined`.
281
+ * @param val The value to check.
282
+ * @returns {boolean} `true` if the value is `undefined`, otherwise `false`.
283
+ */
274
284
  declare function isUndefined(val: unknown): val is undefined;
285
+ /**
286
+ * Type guard that checks if a value is either `null` or `undefined`.
287
+ * @param val The value to check.
288
+ * @returns {boolean} `true` if the value is `null` or `undefined`, otherwise `false`.
289
+ */
290
+ declare function isNullOrUndefined(val: unknown): val is null | undefined;
291
+ /**
292
+ * Type guard that checks if a value is a `number`.
293
+ * @param val The value to check.
294
+ * @returns {boolean} `true` if the value is a `number`, otherwise `false`.
295
+ */
275
296
  declare function isNumber(val: unknown): val is number;
297
+ /**
298
+ * Type guard that checks if a value is a `boolean`.
299
+ * @param val The value to check.
300
+ * @returns {boolean} `true` if the value is a `boolean`, otherwise `false`.
301
+ */
276
302
  declare function isBoolean(val: unknown): val is boolean;
303
+ /**
304
+ * Type guard that checks if a value is a `string`.
305
+ * @param val The value to check.
306
+ * @returns {boolean} `true` if the value is a `string`, otherwise `false`.
307
+ */
277
308
  declare function isString(val: unknown): val is string;
278
- declare function isNull(val: unknown): val is null;
309
+ /**
310
+ * Check if a value is a plain object.
311
+ * Correctly handles `null` and arrays, returning `false` for them.
312
+ *
313
+ * @param value The value to check.
314
+ * @returns {boolean} `true` if the value is a non-null, non-array object.
315
+ */
316
+ declare function isObject(value: unknown): value is Record<PropertyKey, unknown>;
317
+ /**
318
+ * Type guard that checks if a value is a function.
319
+ *
320
+ * @param value The value to check.
321
+ * @returns {boolean} `true` if the value is a function.
322
+ */
323
+ declare function isFunction(value: unknown): value is (...args: any[]) => any;
324
+ /**
325
+ * Type guard that checks if a value is a Promise-like object.
326
+ *
327
+ * @param value The value to check.
328
+ * @returns {boolean} `true` if the value has a `then` function.
329
+ */
330
+ declare function isPromise(value: unknown): value is Promise<unknown>;
279
331
  /**
280
332
  * Type guard to check if a value is a string that ends with '%'.
281
333
  * @param val The value to check.
@@ -338,7 +390,7 @@ declare function randId(): string;
338
390
  * @template K - The type of the key (must be a string).
339
391
  * @template V - The type of the value being stored.
340
392
  */
341
- declare class Registry<K extends string, V> {
393
+ declare class Registry<K extends PropertyKey, V> {
342
394
  protected readonly items: Map<K, V>;
343
395
  /**
344
396
  * Registers an item with a specific key.
@@ -372,4 +424,4 @@ declare class Registry<K extends string, V> {
372
424
  clear(): void;
373
425
  }
374
426
 
375
- export { type AxiEngineConfig, type Constructor, type DataSink, type DataSource, type DataStorage, Emitter, type PathType, Registry, type ScalarType, type Subscribable, areArraysEqual, axiSettings, clampNumber, configure, ensurePathArray, ensurePathString, firstKeyOf, genArray, getPercentOf, getRandomElement, haveSameElements, isBoolean, isNull, isNullOrUndefined, isNumber, isPercentageString, isScalar, isSequentialStart, isString, isUndefined, last, randId, randInt, shuffleArray, throwError, throwIf, throwIfEmpty, unique };
427
+ export { type AxiEngineConfig, type Constructor, type DataSink, type DataSource, type DataStorage, Emitter, type PathType, Registry, type ScalarType, type Subscribable, areArraysEqual, axiSettings, clampNumber, configure, ensurePathArray, ensurePathString, firstKeyOf, genArray, getPercentOf, getRandomElement, haveSameElements, isBoolean, isFunction, isNull, isNullOrUndefined, isNumber, isObject, isPercentageString, isPromise, isScalar, isSequentialStart, isString, isUndefined, last, randId, randInt, shuffleArray, throwError, throwIf, throwIfEmpty, unique };
package/dist/index.js CHANGED
@@ -34,10 +34,13 @@ __export(index_exports, {
34
34
  getRandomElement: () => getRandomElement,
35
35
  haveSameElements: () => haveSameElements,
36
36
  isBoolean: () => isBoolean,
37
+ isFunction: () => isFunction,
37
38
  isNull: () => isNull,
38
39
  isNullOrUndefined: () => isNullOrUndefined,
39
40
  isNumber: () => isNumber,
41
+ isObject: () => isObject,
40
42
  isPercentageString: () => isPercentageString,
43
+ isPromise: () => isPromise,
41
44
  isScalar: () => isScalar,
42
45
  isSequentialStart: () => isSequentialStart,
43
46
  isString: () => isString,
@@ -104,11 +107,14 @@ function isScalar(value) {
104
107
  const type = typeof value;
105
108
  return type === "string" || type === "number" || type === "boolean";
106
109
  }
107
- function isNullOrUndefined(val) {
108
- return val === void 0 || val === null;
110
+ function isNull(val) {
111
+ return val === null;
109
112
  }
110
113
  function isUndefined(val) {
111
- return typeof val === "undefined";
114
+ return val === void 0;
115
+ }
116
+ function isNullOrUndefined(val) {
117
+ return val === null || val === void 0;
112
118
  }
113
119
  function isNumber(val) {
114
120
  return typeof val === "number";
@@ -119,8 +125,14 @@ function isBoolean(val) {
119
125
  function isString(val) {
120
126
  return typeof val === "string";
121
127
  }
122
- function isNull(val) {
123
- return val === null;
128
+ function isObject(value) {
129
+ return value !== null && !Array.isArray(value) && typeof value === "object";
130
+ }
131
+ function isFunction(value) {
132
+ return typeof value === "function";
133
+ }
134
+ function isPromise(value) {
135
+ return value != null && typeof value.then === "function";
124
136
  }
125
137
  function isPercentageString(val) {
126
138
  return typeof val === "string" && val.endsWith("%");
@@ -233,7 +245,7 @@ var Registry = class {
233
245
  * @param value The item to register.
234
246
  */
235
247
  register(key, value) {
236
- throwIf(this.items.has(key), `An item with the key '${key}' is already registered and will be overwritten.`);
248
+ throwIf(this.items.has(key), `An item with the key '${String(key)}' is already registered and will be overwritten.`);
237
249
  this.items.set(key, value);
238
250
  }
239
251
  /**
@@ -259,7 +271,7 @@ var Registry = class {
259
271
  */
260
272
  getOrThrow(key) {
261
273
  const item = this.get(key);
262
- throwIfEmpty(item, `No item registered for the key '${key}'.`);
274
+ throwIfEmpty(item, `No item registered for the key '${String(key)}'.`);
263
275
  return item;
264
276
  }
265
277
  delete(key) {
@@ -288,10 +300,13 @@ var Registry = class {
288
300
  getRandomElement,
289
301
  haveSameElements,
290
302
  isBoolean,
303
+ isFunction,
291
304
  isNull,
292
305
  isNullOrUndefined,
293
306
  isNumber,
307
+ isObject,
294
308
  isPercentageString,
309
+ isPromise,
295
310
  isScalar,
296
311
  isSequentialStart,
297
312
  isString,
package/dist/index.mjs CHANGED
@@ -49,11 +49,14 @@ function isScalar(value) {
49
49
  const type = typeof value;
50
50
  return type === "string" || type === "number" || type === "boolean";
51
51
  }
52
- function isNullOrUndefined(val) {
53
- return val === void 0 || val === null;
52
+ function isNull(val) {
53
+ return val === null;
54
54
  }
55
55
  function isUndefined(val) {
56
- return typeof val === "undefined";
56
+ return val === void 0;
57
+ }
58
+ function isNullOrUndefined(val) {
59
+ return val === null || val === void 0;
57
60
  }
58
61
  function isNumber(val) {
59
62
  return typeof val === "number";
@@ -64,8 +67,14 @@ function isBoolean(val) {
64
67
  function isString(val) {
65
68
  return typeof val === "string";
66
69
  }
67
- function isNull(val) {
68
- return val === null;
70
+ function isObject(value) {
71
+ return value !== null && !Array.isArray(value) && typeof value === "object";
72
+ }
73
+ function isFunction(value) {
74
+ return typeof value === "function";
75
+ }
76
+ function isPromise(value) {
77
+ return value != null && typeof value.then === "function";
69
78
  }
70
79
  function isPercentageString(val) {
71
80
  return typeof val === "string" && val.endsWith("%");
@@ -178,7 +187,7 @@ var Registry = class {
178
187
  * @param value The item to register.
179
188
  */
180
189
  register(key, value) {
181
- throwIf(this.items.has(key), `An item with the key '${key}' is already registered and will be overwritten.`);
190
+ throwIf(this.items.has(key), `An item with the key '${String(key)}' is already registered and will be overwritten.`);
182
191
  this.items.set(key, value);
183
192
  }
184
193
  /**
@@ -204,7 +213,7 @@ var Registry = class {
204
213
  */
205
214
  getOrThrow(key) {
206
215
  const item = this.get(key);
207
- throwIfEmpty(item, `No item registered for the key '${key}'.`);
216
+ throwIfEmpty(item, `No item registered for the key '${String(key)}'.`);
208
217
  return item;
209
218
  }
210
219
  delete(key) {
@@ -232,10 +241,13 @@ export {
232
241
  getRandomElement,
233
242
  haveSameElements,
234
243
  isBoolean,
244
+ isFunction,
235
245
  isNull,
236
246
  isNullOrUndefined,
237
247
  isNumber,
248
+ isObject,
238
249
  isPercentageString,
250
+ isPromise,
239
251
  isScalar,
240
252
  isSequentialStart,
241
253
  isString,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axi-engine/utils",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
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": {