@alextheman/utility 5.19.2 → 5.20.0

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.
@@ -102,6 +102,53 @@ function range(start, stop, step = 1) {
102
102
  return numbers;
103
103
  }
104
104
  //#endregion
105
+ //#region src/root/functions/typeAssertions/isNonNullableObject.ts
106
+ /**
107
+ * Determines if the given input is a non-nullable object, narrowing the type down as such if it is
108
+ *
109
+ * @category Type Assertions
110
+ *
111
+ * @param input - The input to check
112
+ *
113
+ * @returns `true` if the input is a non-nullable object, and `false` otherwise. The input type will also be narrowed down to be a non-nullable object.
114
+ */
115
+ function isNonNullableObject(input) {
116
+ return typeof input === "object" && input !== null;
117
+ }
118
+ //#endregion
119
+ //#region src/root/functions/typeAssertions/objectContainsKeys.ts
120
+ /**
121
+ * Determines if the given object contains all of the keys provided.
122
+ *
123
+ * @category Type Assertions
124
+ *
125
+ * @param input - The input object to check.
126
+ * @param keys - The keys expected to be in the input object.
127
+ *
128
+ * @returns `true` if the input object contains all provided keys, and `false` otherwise. The input type will also be narrowed down to be a record with the provided keys with an unknown value type.
129
+ */
130
+ function objectContainsKeys(input, keys) {
131
+ const expectedKeys = Array.isArray(keys) ? keys : [keys];
132
+ if (expectedKeys.length === 0) return false;
133
+ for (const key of expectedKeys) if (!(key in input)) return false;
134
+ return true;
135
+ }
136
+ //#endregion
137
+ //#region src/root/functions/typeAssertions/containsKeys.ts
138
+ /**
139
+ * Determines if the given input is a non-nullable object, and if that object contains all of the keys provided.
140
+ *
141
+ * @category Type Assertions
142
+ *
143
+ * @param input - The input to check.
144
+ * @param keys - The keys expected to be in the input if it's an object.
145
+ *
146
+ * @returns `true` if the input is an object containing all provided keys, and `false` otherwise. The input type will also be narrowed down to be a record with the provided keys, each with an unknown value type.
147
+ */
148
+ function containsKeys(input, keys) {
149
+ return isNonNullableObject(input) && objectContainsKeys(input, keys);
150
+ }
151
+ //#endregion
105
152
  //#region src/root/functions/arrayHelpers/fillArray.ts
106
153
  /**
107
154
  * Creates a new array where each element is the result of the provided callback.
@@ -129,7 +176,7 @@ function fillArray(callback, length = 1, options) {
129
176
  return callback(index);
130
177
  });
131
178
  if (outputArray.some((item) => {
132
- return item instanceof Promise || typeof item === "object" && item !== null && "then" in item && typeof item.then === "function";
179
+ return item instanceof Promise || containsKeys(item, "then") && typeof item.then === "function";
133
180
  })) return Promise.all(outputArray);
134
181
  return outputArray;
135
182
  }
@@ -236,7 +283,7 @@ function reduceLines(lines, { preserveTabs = true }) {
236
283
  * @returns An additional function to invoke, or a new string with the strings and interpolations from the template applied, and extraneous indents removed.
237
284
  */
238
285
  function normaliseIndents(first, ...args) {
239
- if (typeof first === "object" && first !== null && !Array.isArray(first)) {
286
+ if (isNonNullableObject(first) && !Array.isArray(first)) {
240
287
  const options = first;
241
288
  return (strings, ...interpolations) => {
242
289
  return normaliseIndents(strings, ...interpolations, options);
@@ -279,7 +326,7 @@ var CodeError = class CodeError extends Error {
279
326
  */
280
327
  static check(input) {
281
328
  if (input instanceof CodeError) return true;
282
- return typeof input === "object" && input !== null && "message" in input && typeof input.message === "string" && "code" in input && typeof input.code === "string";
329
+ return containsKeys(input, ["message", "code"]) && typeof input.message === "string" && typeof input.code === "string";
283
330
  }
284
331
  static checkCaughtError(error, options) {
285
332
  if (this.check(error)) {
@@ -392,7 +439,11 @@ var DataError = class DataError extends CodeError {
392
439
  */
393
440
  static check(input) {
394
441
  if (input instanceof DataError) return true;
395
- return typeof input === "object" && input !== null && "message" in input && typeof input.message === "string" && "code" in input && typeof input.code === "string" && "data" in input && typeof input.data === "object" && input.data !== null;
442
+ return containsKeys(input, [
443
+ "data",
444
+ "code",
445
+ "message"
446
+ ]) && typeof input.message === "string" && typeof input.code === "string" && isNonNullableObject(input.data);
396
447
  }
397
448
  /**
398
449
  * Check a `DataError` against its error code
@@ -78,6 +78,53 @@ function range(start, stop, step = 1) {
78
78
  return numbers;
79
79
  }
80
80
  //#endregion
81
+ //#region src/root/functions/typeAssertions/isNonNullableObject.ts
82
+ /**
83
+ * Determines if the given input is a non-nullable object, narrowing the type down as such if it is
84
+ *
85
+ * @category Type Assertions
86
+ *
87
+ * @param input - The input to check
88
+ *
89
+ * @returns `true` if the input is a non-nullable object, and `false` otherwise. The input type will also be narrowed down to be a non-nullable object.
90
+ */
91
+ function isNonNullableObject(input) {
92
+ return typeof input === "object" && input !== null;
93
+ }
94
+ //#endregion
95
+ //#region src/root/functions/typeAssertions/objectContainsKeys.ts
96
+ /**
97
+ * Determines if the given object contains all of the keys provided.
98
+ *
99
+ * @category Type Assertions
100
+ *
101
+ * @param input - The input object to check.
102
+ * @param keys - The keys expected to be in the input object.
103
+ *
104
+ * @returns `true` if the input object contains all provided keys, and `false` otherwise. The input type will also be narrowed down to be a record with the provided keys with an unknown value type.
105
+ */
106
+ function objectContainsKeys(input, keys) {
107
+ const expectedKeys = Array.isArray(keys) ? keys : [keys];
108
+ if (expectedKeys.length === 0) return false;
109
+ for (const key of expectedKeys) if (!(key in input)) return false;
110
+ return true;
111
+ }
112
+ //#endregion
113
+ //#region src/root/functions/typeAssertions/containsKeys.ts
114
+ /**
115
+ * Determines if the given input is a non-nullable object, and if that object contains all of the keys provided.
116
+ *
117
+ * @category Type Assertions
118
+ *
119
+ * @param input - The input to check.
120
+ * @param keys - The keys expected to be in the input if it's an object.
121
+ *
122
+ * @returns `true` if the input is an object containing all provided keys, and `false` otherwise. The input type will also be narrowed down to be a record with the provided keys, each with an unknown value type.
123
+ */
124
+ function containsKeys(input, keys) {
125
+ return isNonNullableObject(input) && objectContainsKeys(input, keys);
126
+ }
127
+ //#endregion
81
128
  //#region src/root/functions/arrayHelpers/fillArray.ts
82
129
  /**
83
130
  * Creates a new array where each element is the result of the provided callback.
@@ -105,7 +152,7 @@ function fillArray(callback, length = 1, options) {
105
152
  return callback(index);
106
153
  });
107
154
  if (outputArray.some((item) => {
108
- return item instanceof Promise || typeof item === "object" && item !== null && "then" in item && typeof item.then === "function";
155
+ return item instanceof Promise || containsKeys(item, "then") && typeof item.then === "function";
109
156
  })) return Promise.all(outputArray);
110
157
  return outputArray;
111
158
  }
@@ -212,7 +259,7 @@ function reduceLines(lines, { preserveTabs = true }) {
212
259
  * @returns An additional function to invoke, or a new string with the strings and interpolations from the template applied, and extraneous indents removed.
213
260
  */
214
261
  function normaliseIndents(first, ...args) {
215
- if (typeof first === "object" && first !== null && !Array.isArray(first)) {
262
+ if (isNonNullableObject(first) && !Array.isArray(first)) {
216
263
  const options = first;
217
264
  return (strings, ...interpolations) => {
218
265
  return normaliseIndents(strings, ...interpolations, options);
@@ -255,7 +302,7 @@ var CodeError = class CodeError extends Error {
255
302
  */
256
303
  static check(input) {
257
304
  if (input instanceof CodeError) return true;
258
- return typeof input === "object" && input !== null && "message" in input && typeof input.message === "string" && "code" in input && typeof input.code === "string";
305
+ return containsKeys(input, ["message", "code"]) && typeof input.message === "string" && typeof input.code === "string";
259
306
  }
260
307
  static checkCaughtError(error, options) {
261
308
  if (this.check(error)) {
@@ -368,7 +415,11 @@ var DataError = class DataError extends CodeError {
368
415
  */
369
416
  static check(input) {
370
417
  if (input instanceof DataError) return true;
371
- return typeof input === "object" && input !== null && "message" in input && typeof input.message === "string" && "code" in input && typeof input.code === "string" && "data" in input && typeof input.data === "object" && input.data !== null;
418
+ return containsKeys(input, [
419
+ "data",
420
+ "code",
421
+ "message"
422
+ ]) && typeof input.message === "string" && typeof input.code === "string" && isNonNullableObject(input.data);
372
423
  }
373
424
  /**
374
425
  * Check a `DataError` against its error code
package/dist/v6/index.cjs CHANGED
@@ -38,6 +38,53 @@ function range(start, stop, step = 1) {
38
38
  return numbers;
39
39
  }
40
40
  //#endregion
41
+ //#region src/root/functions/typeAssertions/isNonNullableObject.ts
42
+ /**
43
+ * Determines if the given input is a non-nullable object, narrowing the type down as such if it is
44
+ *
45
+ * @category Type Assertions
46
+ *
47
+ * @param input - The input to check
48
+ *
49
+ * @returns `true` if the input is a non-nullable object, and `false` otherwise. The input type will also be narrowed down to be a non-nullable object.
50
+ */
51
+ function isNonNullableObject(input) {
52
+ return typeof input === "object" && input !== null;
53
+ }
54
+ //#endregion
55
+ //#region src/root/functions/typeAssertions/objectContainsKeys.ts
56
+ /**
57
+ * Determines if the given object contains all of the keys provided.
58
+ *
59
+ * @category Type Assertions
60
+ *
61
+ * @param input - The input object to check.
62
+ * @param keys - The keys expected to be in the input object.
63
+ *
64
+ * @returns `true` if the input object contains all provided keys, and `false` otherwise. The input type will also be narrowed down to be a record with the provided keys with an unknown value type.
65
+ */
66
+ function objectContainsKeys(input, keys) {
67
+ const expectedKeys = Array.isArray(keys) ? keys : [keys];
68
+ if (expectedKeys.length === 0) return false;
69
+ for (const key of expectedKeys) if (!(key in input)) return false;
70
+ return true;
71
+ }
72
+ //#endregion
73
+ //#region src/root/functions/typeAssertions/containsKeys.ts
74
+ /**
75
+ * Determines if the given input is a non-nullable object, and if that object contains all of the keys provided.
76
+ *
77
+ * @category Type Assertions
78
+ *
79
+ * @param input - The input to check.
80
+ * @param keys - The keys expected to be in the input if it's an object.
81
+ *
82
+ * @returns `true` if the input is an object containing all provided keys, and `false` otherwise. The input type will also be narrowed down to be a record with the provided keys, each with an unknown value type.
83
+ */
84
+ function containsKeys(input, keys) {
85
+ return isNonNullableObject(input) && objectContainsKeys(input, keys);
86
+ }
87
+ //#endregion
41
88
  //#region src/root/functions/arrayHelpers/fillArray.ts
42
89
  /**
43
90
  * Creates a new array where each element is the result of the provided callback.
@@ -65,7 +112,7 @@ function fillArray(callback, length = 1, options) {
65
112
  return callback(index);
66
113
  });
67
114
  if (outputArray.some((item) => {
68
- return item instanceof Promise || typeof item === "object" && item !== null && "then" in item && typeof item.then === "function";
115
+ return item instanceof Promise || containsKeys(item, "then") && typeof item.then === "function";
69
116
  })) return Promise.all(outputArray);
70
117
  return outputArray;
71
118
  }
@@ -172,7 +219,7 @@ function reduceLines(lines, { preserveTabs = true }) {
172
219
  * @returns An additional function to invoke, or a new string with the strings and interpolations from the template applied, and extraneous indents removed.
173
220
  */
174
221
  function normaliseIndents(first, ...args) {
175
- if (typeof first === "object" && first !== null && !Array.isArray(first)) {
222
+ if (isNonNullableObject(first) && !Array.isArray(first)) {
176
223
  const options = first;
177
224
  return (strings, ...interpolations) => {
178
225
  return normaliseIndents(strings, ...interpolations, options);
@@ -215,7 +262,7 @@ var CodeError = class CodeError extends Error {
215
262
  */
216
263
  static check(input) {
217
264
  if (input instanceof CodeError) return true;
218
- return typeof input === "object" && input !== null && "message" in input && typeof input.message === "string" && "code" in input && typeof input.code === "string";
265
+ return containsKeys(input, ["message", "code"]) && typeof input.message === "string" && typeof input.code === "string";
219
266
  }
220
267
  static checkCaughtError(error, options) {
221
268
  if (this.check(error)) {
@@ -339,7 +386,11 @@ var APIError = class APIError extends CodeError {
339
386
  */
340
387
  static check(input) {
341
388
  if (input instanceof APIError) return true;
342
- return typeof input === "object" && input !== null && "status" in input && typeof input.status === "number" && "code" in input && typeof input.code === "string" && "message" in input && typeof input.message === "string" && (!("data" in input) || input.data === void 0 || typeof input.data === "object" && input.data !== null);
389
+ return containsKeys(input, [
390
+ "status",
391
+ "code",
392
+ "message"
393
+ ]) && typeof input.status === "number" && typeof input.code === "string" && typeof input.message === "string" && (!objectContainsKeys(input, "data") || input.data === void 0 || isNonNullableObject(input.data));
343
394
  }
344
395
  /**
345
396
  * Check an `APIError` against its error code
@@ -446,7 +497,11 @@ var DataError = class DataError extends CodeError {
446
497
  */
447
498
  static check(input) {
448
499
  if (input instanceof DataError) return true;
449
- return typeof input === "object" && input !== null && "message" in input && typeof input.message === "string" && "code" in input && typeof input.code === "string" && "data" in input && typeof input.data === "object" && input.data !== null;
500
+ return containsKeys(input, [
501
+ "data",
502
+ "code",
503
+ "message"
504
+ ]) && typeof input.message === "string" && typeof input.code === "string" && isNonNullableObject(input.data);
450
505
  }
451
506
  /**
452
507
  * Check a `DataError` against its error code
package/dist/v6/index.js CHANGED
@@ -37,6 +37,53 @@ function range(start, stop, step = 1) {
37
37
  return numbers;
38
38
  }
39
39
  //#endregion
40
+ //#region src/root/functions/typeAssertions/isNonNullableObject.ts
41
+ /**
42
+ * Determines if the given input is a non-nullable object, narrowing the type down as such if it is
43
+ *
44
+ * @category Type Assertions
45
+ *
46
+ * @param input - The input to check
47
+ *
48
+ * @returns `true` if the input is a non-nullable object, and `false` otherwise. The input type will also be narrowed down to be a non-nullable object.
49
+ */
50
+ function isNonNullableObject(input) {
51
+ return typeof input === "object" && input !== null;
52
+ }
53
+ //#endregion
54
+ //#region src/root/functions/typeAssertions/objectContainsKeys.ts
55
+ /**
56
+ * Determines if the given object contains all of the keys provided.
57
+ *
58
+ * @category Type Assertions
59
+ *
60
+ * @param input - The input object to check.
61
+ * @param keys - The keys expected to be in the input object.
62
+ *
63
+ * @returns `true` if the input object contains all provided keys, and `false` otherwise. The input type will also be narrowed down to be a record with the provided keys with an unknown value type.
64
+ */
65
+ function objectContainsKeys(input, keys) {
66
+ const expectedKeys = Array.isArray(keys) ? keys : [keys];
67
+ if (expectedKeys.length === 0) return false;
68
+ for (const key of expectedKeys) if (!(key in input)) return false;
69
+ return true;
70
+ }
71
+ //#endregion
72
+ //#region src/root/functions/typeAssertions/containsKeys.ts
73
+ /**
74
+ * Determines if the given input is a non-nullable object, and if that object contains all of the keys provided.
75
+ *
76
+ * @category Type Assertions
77
+ *
78
+ * @param input - The input to check.
79
+ * @param keys - The keys expected to be in the input if it's an object.
80
+ *
81
+ * @returns `true` if the input is an object containing all provided keys, and `false` otherwise. The input type will also be narrowed down to be a record with the provided keys, each with an unknown value type.
82
+ */
83
+ function containsKeys(input, keys) {
84
+ return isNonNullableObject(input) && objectContainsKeys(input, keys);
85
+ }
86
+ //#endregion
40
87
  //#region src/root/functions/arrayHelpers/fillArray.ts
41
88
  /**
42
89
  * Creates a new array where each element is the result of the provided callback.
@@ -64,7 +111,7 @@ function fillArray(callback, length = 1, options) {
64
111
  return callback(index);
65
112
  });
66
113
  if (outputArray.some((item) => {
67
- return item instanceof Promise || typeof item === "object" && item !== null && "then" in item && typeof item.then === "function";
114
+ return item instanceof Promise || containsKeys(item, "then") && typeof item.then === "function";
68
115
  })) return Promise.all(outputArray);
69
116
  return outputArray;
70
117
  }
@@ -171,7 +218,7 @@ function reduceLines(lines, { preserveTabs = true }) {
171
218
  * @returns An additional function to invoke, or a new string with the strings and interpolations from the template applied, and extraneous indents removed.
172
219
  */
173
220
  function normaliseIndents(first, ...args) {
174
- if (typeof first === "object" && first !== null && !Array.isArray(first)) {
221
+ if (isNonNullableObject(first) && !Array.isArray(first)) {
175
222
  const options = first;
176
223
  return (strings, ...interpolations) => {
177
224
  return normaliseIndents(strings, ...interpolations, options);
@@ -214,7 +261,7 @@ var CodeError = class CodeError extends Error {
214
261
  */
215
262
  static check(input) {
216
263
  if (input instanceof CodeError) return true;
217
- return typeof input === "object" && input !== null && "message" in input && typeof input.message === "string" && "code" in input && typeof input.code === "string";
264
+ return containsKeys(input, ["message", "code"]) && typeof input.message === "string" && typeof input.code === "string";
218
265
  }
219
266
  static checkCaughtError(error, options) {
220
267
  if (this.check(error)) {
@@ -338,7 +385,11 @@ var APIError = class APIError extends CodeError {
338
385
  */
339
386
  static check(input) {
340
387
  if (input instanceof APIError) return true;
341
- return typeof input === "object" && input !== null && "status" in input && typeof input.status === "number" && "code" in input && typeof input.code === "string" && "message" in input && typeof input.message === "string" && (!("data" in input) || input.data === void 0 || typeof input.data === "object" && input.data !== null);
388
+ return containsKeys(input, [
389
+ "status",
390
+ "code",
391
+ "message"
392
+ ]) && typeof input.status === "number" && typeof input.code === "string" && typeof input.message === "string" && (!objectContainsKeys(input, "data") || input.data === void 0 || isNonNullableObject(input.data));
342
393
  }
343
394
  /**
344
395
  * Check an `APIError` against its error code
@@ -445,7 +496,11 @@ var DataError = class DataError extends CodeError {
445
496
  */
446
497
  static check(input) {
447
498
  if (input instanceof DataError) return true;
448
- return typeof input === "object" && input !== null && "message" in input && typeof input.message === "string" && "code" in input && typeof input.code === "string" && "data" in input && typeof input.data === "object" && input.data !== null;
499
+ return containsKeys(input, [
500
+ "data",
501
+ "code",
502
+ "message"
503
+ ]) && typeof input.message === "string" && typeof input.code === "string" && isNonNullableObject(input.data);
449
504
  }
450
505
  /**
451
506
  * Check a `DataError` against its error code
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alextheman/utility",
3
- "version": "5.19.2",
3
+ "version": "5.20.0",
4
4
  "description": "Helpful utility functions.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -40,27 +40,27 @@
40
40
  "execa": "9.6.1"
41
41
  },
42
42
  "devDependencies": {
43
- "@alextheman/eslint-plugin": "5.16.1",
43
+ "@alextheman/eslint-plugin": "5.17.0",
44
44
  "@types/node": "25.9.1",
45
- "alex-c-line": "2.8.1",
45
+ "alex-c-line": "2.9.1",
46
46
  "cross-env": "10.1.0",
47
47
  "dotenv-cli": "11.0.0",
48
- "eslint": "10.4.0",
48
+ "eslint": "10.4.1",
49
49
  "globals": "17.6.0",
50
50
  "husky": "9.1.7",
51
51
  "jsdom": "29.1.1",
52
52
  "markdownlint-cli2": "0.22.1",
53
53
  "prettier": "3.8.3",
54
54
  "tempy": "3.2.0",
55
- "tsdown": "0.22.1",
56
- "tsx": "4.22.3",
55
+ "tsdown": "0.22.2",
56
+ "tsx": "4.22.4",
57
57
  "typedoc": "0.28.19",
58
- "typedoc-plugin-markdown": "4.11.0",
58
+ "typedoc-plugin-markdown": "4.12.0",
59
59
  "typedoc-rhineai-theme": "1.2.0",
60
60
  "typescript": "6.0.3",
61
- "typescript-eslint": "8.60.0",
62
- "vite": "8.0.14",
63
- "vitest": "4.1.7",
61
+ "typescript-eslint": "8.60.1",
62
+ "vite": "8.0.16",
63
+ "vitest": "4.1.8",
64
64
  "zod": "4.4.3"
65
65
  },
66
66
  "engines": {