@alextheman/utility 4.2.1 → 4.3.1
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.cjs +130 -31
- package/dist/index.d.cts +134 -18
- package/dist/index.d.ts +134 -18
- package/dist/index.js +130 -31
- package/package.json +6 -5
package/dist/index.js
CHANGED
|
@@ -18,6 +18,8 @@ var VERSION_NUMBER_REGEX_default = VERSION_NUMBER_REGEX;
|
|
|
18
18
|
* If the callback returns at least one Promise, the entire result will be wrapped
|
|
19
19
|
* in a `Promise` and resolved with `Promise.all`. Otherwise, a plain array is returned.
|
|
20
20
|
*
|
|
21
|
+
* @category Array Helpers
|
|
22
|
+
*
|
|
21
23
|
* @template ItemType
|
|
22
24
|
*
|
|
23
25
|
* @param callback - A function invoked with the current index. May return a value or a Promise.
|
|
@@ -44,6 +46,8 @@ var fillArray_default = fillArray;
|
|
|
44
46
|
* If `secondArray` is shorter than `firstArray`, the second position in the tuple
|
|
45
47
|
* will be `undefined`. Iteration always uses the length of the first array.
|
|
46
48
|
*
|
|
49
|
+
* @category Array Helpers
|
|
50
|
+
*
|
|
47
51
|
* @template FirstArrayItem
|
|
48
52
|
* @template SecondArrayItem
|
|
49
53
|
*
|
|
@@ -69,7 +73,11 @@ const httpErrorCodeLookup = {
|
|
|
69
73
|
418: "I_AM_A_TEAPOT",
|
|
70
74
|
500: "INTERNAL_SERVER_ERROR"
|
|
71
75
|
};
|
|
72
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* Represents common errors you may get from a HTTP API request.
|
|
78
|
+
*
|
|
79
|
+
* @category Types
|
|
80
|
+
*/
|
|
73
81
|
var APIError = class extends Error {
|
|
74
82
|
status;
|
|
75
83
|
/**
|
|
@@ -101,10 +109,14 @@ var APIError_default = APIError;
|
|
|
101
109
|
|
|
102
110
|
//#endregion
|
|
103
111
|
//#region src/types/DataError.ts
|
|
104
|
-
/**
|
|
112
|
+
/**
|
|
113
|
+
* Represents errors you may get that may've been caused by a specific piece of data.
|
|
114
|
+
*
|
|
115
|
+
* @category Types
|
|
116
|
+
*/
|
|
105
117
|
var DataError = class extends Error {
|
|
106
|
-
data;
|
|
107
118
|
code;
|
|
119
|
+
data;
|
|
108
120
|
/**
|
|
109
121
|
* @param data - The data that caused the error.
|
|
110
122
|
* @param code - A standardised code (e.g. UNEXPECTED_DATA).
|
|
@@ -136,6 +148,11 @@ var DataError_default = DataError;
|
|
|
136
148
|
|
|
137
149
|
//#endregion
|
|
138
150
|
//#region src/types/VersionType.ts
|
|
151
|
+
/**
|
|
152
|
+
* Represents the three common software version types.
|
|
153
|
+
*
|
|
154
|
+
* @category Types
|
|
155
|
+
*/
|
|
139
156
|
const VersionType = {
|
|
140
157
|
MAJOR: "major",
|
|
141
158
|
MINOR: "minor",
|
|
@@ -144,15 +161,19 @@ const VersionType = {
|
|
|
144
161
|
|
|
145
162
|
//#endregion
|
|
146
163
|
//#region src/types/VersionNumber.ts
|
|
147
|
-
/**
|
|
164
|
+
/**
|
|
165
|
+
* Represents a software version number, considered to be made up of a major, minor, and patch part.
|
|
166
|
+
*
|
|
167
|
+
* @category Types
|
|
168
|
+
*/
|
|
148
169
|
var VersionNumber = class VersionNumber {
|
|
170
|
+
static NON_NEGATIVE_TUPLE_ERROR = "Input array must be a tuple of three non-negative integers.";
|
|
149
171
|
/** The major number. Increments when a feature is removed or changed in a way that is not backwards-compatible with the previous release. */
|
|
150
172
|
major = 0;
|
|
151
173
|
/** The minor number. Increments when a new feature is added/deprecated and is expected to be backwards-compatible with the previous release. */
|
|
152
174
|
minor = 0;
|
|
153
175
|
/** The patch number. Increments when the next release is fixing a bug or doing a small refactor that should not be noticeable in practice. */
|
|
154
176
|
patch = 0;
|
|
155
|
-
static NON_NEGATIVE_TUPLE_ERROR = "Input array must be a tuple of three non-negative integers.";
|
|
156
177
|
/**
|
|
157
178
|
* @param input - The input to create a new instance of `VersionNumber` from.
|
|
158
179
|
*/
|
|
@@ -173,7 +194,7 @@ var VersionNumber = class VersionNumber {
|
|
|
173
194
|
if (input.length !== 3) throw new DataError_default(input, "INVALID_LENGTH", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
|
|
174
195
|
const [major, minor, patch] = input.map((number) => {
|
|
175
196
|
const parsedInteger = parseIntStrict_default(number?.toString());
|
|
176
|
-
if (parsedInteger < 0) throw new DataError_default(input, "
|
|
197
|
+
if (parsedInteger < 0) throw new DataError_default(input, "NEGATIVE_INPUTS", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
|
|
177
198
|
return parsedInteger;
|
|
178
199
|
});
|
|
179
200
|
this.major = major;
|
|
@@ -181,21 +202,6 @@ var VersionNumber = class VersionNumber {
|
|
|
181
202
|
this.patch = patch;
|
|
182
203
|
}
|
|
183
204
|
}
|
|
184
|
-
static formatString(input, options) {
|
|
185
|
-
if (options?.omitPrefix) return input.startsWith("v") ? input.slice(1) : input;
|
|
186
|
-
return input.startsWith("v") ? input : `v${input}`;
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Get a string representation of the current version number.
|
|
190
|
-
*
|
|
191
|
-
* @param options - Extra additional options to apply.
|
|
192
|
-
*
|
|
193
|
-
* @returns A stringified representation of the current version number, leaving out the prefix if `omitPrefix` option was set to true.
|
|
194
|
-
*/
|
|
195
|
-
toString(options) {
|
|
196
|
-
const rawString = `${this.major}.${this.minor}.${this.patch}`;
|
|
197
|
-
return VersionNumber.formatString(rawString, options);
|
|
198
|
-
}
|
|
199
205
|
/**
|
|
200
206
|
* Gets the current version type of the current instance of `VersionNumber`.
|
|
201
207
|
*
|
|
@@ -206,6 +212,21 @@ var VersionNumber = class VersionNumber {
|
|
|
206
212
|
if (this.patch === 0) return VersionType.MINOR;
|
|
207
213
|
return VersionType.PATCH;
|
|
208
214
|
}
|
|
215
|
+
static formatString(input, options) {
|
|
216
|
+
if (options?.omitPrefix) return input.startsWith("v") ? input.slice(1) : input;
|
|
217
|
+
return input.startsWith("v") ? input : `v${input}`;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Checks if the provided version numbers have the exact same major, minor, and patch numbers.
|
|
221
|
+
*
|
|
222
|
+
* @param firstVersion - The first version number to compare.
|
|
223
|
+
* @param secondVersion - The second version number to compare.
|
|
224
|
+
*
|
|
225
|
+
* @returns `true` if the provided version numbers have exactly the same major, minor, and patch numbers, and returns `false` otherwise.
|
|
226
|
+
*/
|
|
227
|
+
static isEqual(firstVersion, secondVersion) {
|
|
228
|
+
return firstVersion.major === secondVersion.major && firstVersion.minor === secondVersion.minor && firstVersion.patch === secondVersion.patch;
|
|
229
|
+
}
|
|
209
230
|
/**
|
|
210
231
|
* Determines whether the current instance of `VersionNumber` is a major, minor, or patch version.
|
|
211
232
|
*
|
|
@@ -217,24 +238,34 @@ var VersionNumber = class VersionNumber {
|
|
|
217
238
|
* @returns A new instance of `VersionNumber` with the increment applied.
|
|
218
239
|
*/
|
|
219
240
|
increment(incrementType) {
|
|
220
|
-
|
|
221
|
-
major: [
|
|
241
|
+
return {
|
|
242
|
+
major: new VersionNumber([
|
|
222
243
|
this.major + 1,
|
|
223
244
|
0,
|
|
224
245
|
0
|
|
225
|
-
],
|
|
226
|
-
minor: [
|
|
246
|
+
]),
|
|
247
|
+
minor: new VersionNumber([
|
|
227
248
|
this.major,
|
|
228
249
|
this.minor + 1,
|
|
229
250
|
0
|
|
230
|
-
],
|
|
231
|
-
patch: [
|
|
251
|
+
]),
|
|
252
|
+
patch: new VersionNumber([
|
|
232
253
|
this.major,
|
|
233
254
|
this.minor,
|
|
234
255
|
this.patch + 1
|
|
235
|
-
]
|
|
256
|
+
])
|
|
236
257
|
}[incrementType];
|
|
237
|
-
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Get a string representation of the current version number.
|
|
261
|
+
*
|
|
262
|
+
* @param options - Extra additional options to apply.
|
|
263
|
+
*
|
|
264
|
+
* @returns A stringified representation of the current version number, leaving out the prefix if `omitPrefix` option was set to true.
|
|
265
|
+
*/
|
|
266
|
+
toString(options) {
|
|
267
|
+
const rawString = `${this.major}.${this.minor}.${this.patch}`;
|
|
268
|
+
return VersionNumber.formatString(rawString, options);
|
|
238
269
|
}
|
|
239
270
|
};
|
|
240
271
|
var VersionNumber_default = VersionNumber;
|
|
@@ -244,6 +275,8 @@ var VersionNumber_default = VersionNumber;
|
|
|
244
275
|
/**
|
|
245
276
|
* Converts a string to an integer and throws an error if it cannot be converted.
|
|
246
277
|
*
|
|
278
|
+
* @category Parsers
|
|
279
|
+
*
|
|
247
280
|
* @param string - A string to convert into a number.
|
|
248
281
|
* @param radix - A value between 2 and 36 that specifies the base of the number in string. If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal. All other strings are considered decimal.
|
|
249
282
|
*
|
|
@@ -275,6 +308,8 @@ var parseIntStrict_default = parseIntStrict;
|
|
|
275
308
|
/**
|
|
276
309
|
* Gets a random number between the given bounds.
|
|
277
310
|
*
|
|
311
|
+
* @category Miscellaneous
|
|
312
|
+
*
|
|
278
313
|
* @param lowerBound - The lowest number that can be chosen.
|
|
279
314
|
* @param upperBound - The highest number that can be chosen.
|
|
280
315
|
*
|
|
@@ -292,6 +327,8 @@ var getRandomNumber_default = getRandomNumber;
|
|
|
292
327
|
/**
|
|
293
328
|
* Randomises the order of a given array and returns the result in a new array without mutating the original.
|
|
294
329
|
*
|
|
330
|
+
* @category Array Helpers
|
|
331
|
+
*
|
|
295
332
|
* @template ItemType - The type of the array items.
|
|
296
333
|
*
|
|
297
334
|
* @param array - The array to randomise.
|
|
@@ -317,6 +354,8 @@ var randomiseArray_default = randomiseArray;
|
|
|
317
354
|
* - The range is inclusive of `start` and exclusive of `stop`.
|
|
318
355
|
* - The sign of `step` must match the direction of the range.
|
|
319
356
|
*
|
|
357
|
+
* @category Array Helpers
|
|
358
|
+
*
|
|
320
359
|
* @param start - The number to start at (inclusive).
|
|
321
360
|
* @param stop - The number to stop at (exclusive).
|
|
322
361
|
* @param step - The step size between numbers, defaulting to 1.
|
|
@@ -345,6 +384,8 @@ var range_default = range;
|
|
|
345
384
|
/**
|
|
346
385
|
* Removes duplicate values from an array.
|
|
347
386
|
*
|
|
387
|
+
* @category Array Helpers
|
|
388
|
+
*
|
|
348
389
|
* @template ItemType - The type of the array items.
|
|
349
390
|
*
|
|
350
391
|
* @param array - The array to remove duplicates from.
|
|
@@ -363,6 +404,8 @@ var removeDuplicates_default = removeDuplicates;
|
|
|
363
404
|
/**
|
|
364
405
|
* Adds a given number of days to the provided date, returning the result as a new instance of Date.
|
|
365
406
|
*
|
|
407
|
+
* @category Date
|
|
408
|
+
*
|
|
366
409
|
* @param currentDate - The starting date (defaults to today).
|
|
367
410
|
* @param dayIncrement - The amount of days you want to add (defaults to 1)
|
|
368
411
|
*
|
|
@@ -380,6 +423,8 @@ var addDaysToDate_default = addDaysToDate;
|
|
|
380
423
|
/**
|
|
381
424
|
* Checks if the provided dates happen on the exact same day, month, and year.
|
|
382
425
|
*
|
|
426
|
+
* @category Date
|
|
427
|
+
*
|
|
383
428
|
* @param firstDate - The first date to compare.
|
|
384
429
|
* @param secondDate - The second date to compare.
|
|
385
430
|
*
|
|
@@ -395,6 +440,8 @@ var isSameDate_default = isSameDate;
|
|
|
395
440
|
/**
|
|
396
441
|
* Creates a human-readable string with information about the input date.
|
|
397
442
|
*
|
|
443
|
+
* @category Date
|
|
444
|
+
*
|
|
398
445
|
* @param inputDate - The date to base the string on.
|
|
399
446
|
*
|
|
400
447
|
* @returns A new string with information about the given date.
|
|
@@ -418,6 +465,8 @@ var formatDateAndTime_default = formatDateAndTime;
|
|
|
418
465
|
/**
|
|
419
466
|
* Checks if the provided year is a leap year.
|
|
420
467
|
*
|
|
468
|
+
* @category Date
|
|
469
|
+
*
|
|
421
470
|
* @param year - The year to check as a number.
|
|
422
471
|
*
|
|
423
472
|
* @throws {TypeError} If the year provided is not an integer.
|
|
@@ -439,6 +488,8 @@ function checkLeapYear(firstDate, secondDate) {
|
|
|
439
488
|
/**
|
|
440
489
|
* Checks if the provided dates are exactly a whole number of years apart.
|
|
441
490
|
*
|
|
491
|
+
* @category Date
|
|
492
|
+
*
|
|
442
493
|
* @param firstDate - The first date to compare.
|
|
443
494
|
* @param secondDate - The second date to compare.
|
|
444
495
|
*
|
|
@@ -485,6 +536,8 @@ function leapYearFebruaryChecks(firstDate, secondDate) {
|
|
|
485
536
|
/**
|
|
486
537
|
* Checks if the provided dates are exactly a whole number of months apart.
|
|
487
538
|
*
|
|
539
|
+
* @category Date
|
|
540
|
+
*
|
|
488
541
|
* @param firstDate - The first date to compare.
|
|
489
542
|
* @param secondDate - The second date to compare.
|
|
490
543
|
*
|
|
@@ -503,6 +556,8 @@ var isMonthlyMultiple_default = isMonthlyMultiple;
|
|
|
503
556
|
/**
|
|
504
557
|
* Asynchronously converts a file to a base 64 string
|
|
505
558
|
*
|
|
559
|
+
* @category Miscellaneous
|
|
560
|
+
*
|
|
506
561
|
* @param file - The file to convert.
|
|
507
562
|
*
|
|
508
563
|
* @throws {Error} If the file reader gives an error.
|
|
@@ -535,6 +590,8 @@ function getNullableResolutionStrategy(key, strategy) {
|
|
|
535
590
|
/**
|
|
536
591
|
* Creates FormData from a given object, resolving non-string types as appropriate.
|
|
537
592
|
*
|
|
593
|
+
* @category Miscellaneous
|
|
594
|
+
*
|
|
538
595
|
* @template DataType - The type of the given data.
|
|
539
596
|
*
|
|
540
597
|
* @param data - The data to create FormData from.
|
|
@@ -600,6 +657,8 @@ var createFormData_default = createFormData;
|
|
|
600
657
|
/**
|
|
601
658
|
* Checks to see if the given array is sorted in ascending order.
|
|
602
659
|
*
|
|
660
|
+
* @category Miscellaneous
|
|
661
|
+
*
|
|
603
662
|
* @param array - The array to check.
|
|
604
663
|
*
|
|
605
664
|
* @returns `true` if the array is sorted in ascending order, and `false` otherwise.
|
|
@@ -617,6 +676,8 @@ var isOrdered_default = isOrdered;
|
|
|
617
676
|
/**
|
|
618
677
|
* Converts a stringly-typed list to a proper array.
|
|
619
678
|
*
|
|
679
|
+
* @category Miscellaneous
|
|
680
|
+
*
|
|
620
681
|
* @param stringList - The stringly-typed list to convert.
|
|
621
682
|
* @param options - The options to apply to the conversion.
|
|
622
683
|
* @param options.separator - What each item in the list is separated by.
|
|
@@ -638,6 +699,8 @@ var stringListToArray_default = stringListToArray;
|
|
|
638
699
|
/**
|
|
639
700
|
* Waits for the given number of seconds
|
|
640
701
|
*
|
|
702
|
+
* @category Miscellaneous
|
|
703
|
+
*
|
|
641
704
|
* @param seconds - The number of seconds to wait.
|
|
642
705
|
*
|
|
643
706
|
* @returns A Promise that resolves after the given number of seconds.
|
|
@@ -656,6 +719,8 @@ var wait_default = wait;
|
|
|
656
719
|
/**
|
|
657
720
|
* Gets the keys from a given record object, properly typed to be an array of the key of the input object's type.
|
|
658
721
|
*
|
|
722
|
+
* @category Object Helpers
|
|
723
|
+
*
|
|
659
724
|
* @template InputRecordType - The type of the input object.
|
|
660
725
|
*
|
|
661
726
|
* @param record - The record to get the keys from.
|
|
@@ -672,6 +737,8 @@ var getRecordKeys_default = getRecordKeys;
|
|
|
672
737
|
/**
|
|
673
738
|
* Omits properties from a given object.
|
|
674
739
|
*
|
|
740
|
+
* @category Object Helpers
|
|
741
|
+
*
|
|
675
742
|
* @template ObjectType - The type of the input object.
|
|
676
743
|
* @template KeysToOmit - A type representing the keys to omit from the object.
|
|
677
744
|
*
|
|
@@ -694,6 +761,8 @@ var omitProperties_default = omitProperties;
|
|
|
694
761
|
/**
|
|
695
762
|
* Takes a stringly-typed boolean and converts it to an actual boolean type.
|
|
696
763
|
*
|
|
764
|
+
* @category Parsers
|
|
765
|
+
*
|
|
697
766
|
* @param inputString - The string to parse.
|
|
698
767
|
*
|
|
699
768
|
* @throws {DataError} If the string is not either `true` or `false` (case insensitive).
|
|
@@ -712,6 +781,8 @@ var parseBoolean_default = parseBoolean;
|
|
|
712
781
|
/**
|
|
713
782
|
* An alternative function to zodSchema.parse() that can be used to strictly parse Zod schemas.
|
|
714
783
|
*
|
|
784
|
+
* @category Parsers
|
|
785
|
+
*
|
|
715
786
|
* @template Output - The Zod output type.
|
|
716
787
|
* @template Input - The Zod input type.
|
|
717
788
|
* @template Internals - The Zod internal types based on the output and input types.
|
|
@@ -742,6 +813,8 @@ const envSchema = z$1.enum([
|
|
|
742
813
|
/**
|
|
743
814
|
* Parses the input and verifies it matches one of the environments allowed by the Env types ("test" | "development" | "production").
|
|
744
815
|
*
|
|
816
|
+
* @category Parsers
|
|
817
|
+
*
|
|
745
818
|
* @param data - The data to parse.
|
|
746
819
|
*
|
|
747
820
|
* @throws {DataError} If the data does not match one of the environments allowed by the Env types ("test" | "development" | "production").
|
|
@@ -758,6 +831,8 @@ var parseEnv_default = parseEnv;
|
|
|
758
831
|
/**
|
|
759
832
|
* Returns an object given FormData and an optional data parser function to call on the resulting object.
|
|
760
833
|
*
|
|
834
|
+
* @category Parsers
|
|
835
|
+
*
|
|
761
836
|
* @template DataType - The type of the resulting object when called from the dataParser.
|
|
762
837
|
*
|
|
763
838
|
* @param formData - The FormData to parse.
|
|
@@ -780,6 +855,8 @@ var parseFormData_default = parseFormData;
|
|
|
780
855
|
/**
|
|
781
856
|
* Parses the input and verifies it is a valid software version type (i.e. `"major" | "minor" | "patch"`)
|
|
782
857
|
*
|
|
858
|
+
* @category Parsers
|
|
859
|
+
*
|
|
783
860
|
* @param data - The data to parse.
|
|
784
861
|
*
|
|
785
862
|
* @throws {DataError} If the data does not match one of the allowed version types (`"major" | "minor" | "patch"`).
|
|
@@ -799,6 +876,8 @@ function callDeepCopy(input) {
|
|
|
799
876
|
/**
|
|
800
877
|
* Deeply copies an object or array such that all child objects/arrays are also copied.
|
|
801
878
|
*
|
|
879
|
+
* @category Recursive
|
|
880
|
+
*
|
|
802
881
|
* @template ObjectType - The type of the input object.
|
|
803
882
|
*
|
|
804
883
|
* @param object - The object to copy. May also be an array.
|
|
@@ -826,6 +905,8 @@ var deepCopy_default = deepCopy;
|
|
|
826
905
|
* Note that this will also freeze the input itself as well.
|
|
827
906
|
* If the intent is to create a newly frozen object with a different reference in memory, pass your object through deepCopy first before passing to deepFreeze.
|
|
828
907
|
*
|
|
908
|
+
* @category Recursive
|
|
909
|
+
*
|
|
829
910
|
* @template ObjectType - The type of the input object.
|
|
830
911
|
*
|
|
831
912
|
* @param object - The object to freeze. May also be an array.
|
|
@@ -846,6 +927,8 @@ var deepFreeze_default = deepFreeze;
|
|
|
846
927
|
/**
|
|
847
928
|
* Appends a semicolon to the end of a string, trimming where necessary first.
|
|
848
929
|
*
|
|
930
|
+
* @category String Helpers
|
|
931
|
+
*
|
|
849
932
|
* @param stringToAppendTo - The string to append a semicolon to.
|
|
850
933
|
*
|
|
851
934
|
* @throws {Error} If the string contains multiple lines.
|
|
@@ -865,6 +948,8 @@ var appendSemicolon_default = appendSemicolon;
|
|
|
865
948
|
/**
|
|
866
949
|
* Converts a string from camelCase to kebab-case
|
|
867
950
|
*
|
|
951
|
+
* @category String Helpers
|
|
952
|
+
*
|
|
868
953
|
* @param string - The string to convert.
|
|
869
954
|
* @param options - Options to apply to the conversion.
|
|
870
955
|
*
|
|
@@ -903,6 +988,8 @@ var camelToKebab_default = camelToKebab;
|
|
|
903
988
|
/**
|
|
904
989
|
* Converts a string from kebab-case to camelCase
|
|
905
990
|
*
|
|
991
|
+
* @category String Helpers
|
|
992
|
+
*
|
|
906
993
|
* @param string - The string to convert.
|
|
907
994
|
* @param options - Options to apply to the conversion.
|
|
908
995
|
*
|
|
@@ -940,13 +1027,14 @@ var kebabToCamel_default = kebabToCamel;
|
|
|
940
1027
|
//#region src/functions/stringHelpers/normalizeImportPath.ts
|
|
941
1028
|
/**
|
|
942
1029
|
* Normalizes an import path meant for use in an import statement in JavaScript.
|
|
943
|
-
*
|
|
944
1030
|
* When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used. If the path is a zero-length string, '.' is returned, representing the current working directory.
|
|
945
1031
|
*
|
|
946
1032
|
* If the path starts with ./, it is preserved (unlike what would happen with path.posix.normalize() normally).
|
|
947
1033
|
*
|
|
948
1034
|
* Helpful for custom linter rules that need to check (or fix) import paths.
|
|
949
1035
|
*
|
|
1036
|
+
* @category String Helpers
|
|
1037
|
+
*
|
|
950
1038
|
* @param importPath - The import path to normalize.
|
|
951
1039
|
*
|
|
952
1040
|
* @returns The import path normalized.
|
|
@@ -958,13 +1046,14 @@ function normalizeImportPath(importPath) {
|
|
|
958
1046
|
}
|
|
959
1047
|
/**
|
|
960
1048
|
* Normalises an import path meant for use in an import statement in JavaScript.
|
|
961
|
-
*
|
|
962
1049
|
* When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used. If the path is a zero-length string, '.' is returned, representing the current working directory.
|
|
963
1050
|
*
|
|
964
1051
|
* If the path starts with ./, it is preserved (unlike what would happen with path.posix.normalize() normally).
|
|
965
1052
|
*
|
|
966
1053
|
* Helpful for custom linter rules that need to check (or fix) import paths.
|
|
967
1054
|
*
|
|
1055
|
+
* @category String Helpers
|
|
1056
|
+
*
|
|
968
1057
|
* @param importPath - The import path to normalise.
|
|
969
1058
|
*
|
|
970
1059
|
* @returns The import path normalised.
|
|
@@ -977,6 +1066,8 @@ var normalizeImportPath_default = normalizeImportPath;
|
|
|
977
1066
|
/**
|
|
978
1067
|
* Truncates a string and appends `...` to the end of it
|
|
979
1068
|
*
|
|
1069
|
+
* @category String Helpers
|
|
1070
|
+
*
|
|
980
1071
|
* @param stringToTruncate - The string to truncate.
|
|
981
1072
|
* @param maxLength - The length at which to start truncating. Note that this does not include the `...` part that would be appended.
|
|
982
1073
|
*
|
|
@@ -992,6 +1083,8 @@ var truncate_default = truncate;
|
|
|
992
1083
|
/**
|
|
993
1084
|
* Creates a template strings array given a regular array of strings
|
|
994
1085
|
*
|
|
1086
|
+
* @category Tagged Template
|
|
1087
|
+
*
|
|
995
1088
|
* @param strings - The array of strings.
|
|
996
1089
|
*
|
|
997
1090
|
* @returns A template strings array that can be passed as the first argument of any tagged template function.
|
|
@@ -1012,6 +1105,8 @@ var createTemplateStringsArray_default = createTemplateStringsArray;
|
|
|
1012
1105
|
*
|
|
1013
1106
|
* In this case, it will be functionally the same as if you just wrote the template string by itself.
|
|
1014
1107
|
*
|
|
1108
|
+
* @category Tagged Template
|
|
1109
|
+
*
|
|
1015
1110
|
* @param strings - The strings from the template to process.
|
|
1016
1111
|
* @param interpolations - An array of all interpolations from the template.
|
|
1017
1112
|
*
|
|
@@ -1033,6 +1128,8 @@ var interpolate_default = interpolate;
|
|
|
1033
1128
|
*
|
|
1034
1129
|
* interpolateObjects`Template string here ${{ my: "object" }}`.
|
|
1035
1130
|
*
|
|
1131
|
+
* @category Tagged Template
|
|
1132
|
+
*
|
|
1036
1133
|
* @param strings - The strings from the template to process.
|
|
1037
1134
|
* @param interpolations - An array of all interpolations from the template.
|
|
1038
1135
|
*
|
|
@@ -1089,6 +1186,8 @@ function reduceLines(lines, { preserveTabs = true }) {
|
|
|
1089
1186
|
* with a new line
|
|
1090
1187
|
* and another new line`.
|
|
1091
1188
|
*
|
|
1189
|
+
*@category Tagged Template
|
|
1190
|
+
*
|
|
1092
1191
|
* @param first - The strings from the template to process, or the options to apply.
|
|
1093
1192
|
* @param args - An array of all interpolations from the template.
|
|
1094
1193
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alextheman/utility",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.1",
|
|
4
4
|
"description": "Helpful utility functions",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -19,17 +19,17 @@
|
|
|
19
19
|
"zod": "^4.2.1"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@alextheman/eslint-plugin": "^5.0
|
|
22
|
+
"@alextheman/eslint-plugin": "^5.2.0",
|
|
23
23
|
"@types/node": "^25.0.3",
|
|
24
24
|
"alex-c-line": "^1.10.0",
|
|
25
25
|
"dotenv-cli": "^11.0.0",
|
|
26
26
|
"eslint": "^9.39.2",
|
|
27
|
-
"eslint-plugin-perfectionist": "^5.0.0",
|
|
28
27
|
"globals": "^16.5.0",
|
|
29
28
|
"husky": "^9.1.7",
|
|
30
29
|
"jsdom": "^27.3.0",
|
|
31
30
|
"prettier": "^3.7.4",
|
|
32
31
|
"tsdown": "^0.18.1",
|
|
32
|
+
"typedoc": "^0.28.15",
|
|
33
33
|
"typescript": "^5.9.3",
|
|
34
34
|
"vite-tsconfig-paths": "^6.0.3",
|
|
35
35
|
"vitest": "^4.0.16"
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "tsdown",
|
|
42
|
+
"create-feature-docs": "typedoc",
|
|
42
43
|
"create-local-package": "pnpm run build && rm -f alextheman-utility-*.tgz && pnpm pack",
|
|
43
44
|
"create-release-note-major": "git pull origin main && alex-c-line create-release-note major",
|
|
44
45
|
"create-release-note-minor": "git pull origin main && alex-c-line create-release-note minor",
|
|
@@ -46,12 +47,12 @@
|
|
|
46
47
|
"format": "pnpm run format-prettier && pnpm run format-eslint",
|
|
47
48
|
"format-eslint": "eslint --fix --suppress-all \"package.json\" \"src/**/*.ts\" \"tests/**/*.ts\" && rm -f eslint-suppressions.json",
|
|
48
49
|
"format-prettier": "pnpm run format-prettier-typescript && pnpm run format-prettier-javascript",
|
|
49
|
-
"format-prettier-javascript": "prettier --write \"./**/*.js\"",
|
|
50
|
+
"format-prettier-javascript": "prettier --write \"./**/*.js\" \"!docs\"",
|
|
50
51
|
"format-prettier-typescript": "prettier --write --parser typescript \"./**/*.ts\"",
|
|
51
52
|
"lint": "pnpm run lint-tsc && pnpm run lint-eslint && pnpm run lint-prettier",
|
|
52
53
|
"lint-eslint": "eslint \"package.json\" \"src/**/*.ts\" \"tests/**/*.ts\"",
|
|
53
54
|
"lint-prettier": "pnpm run lint-prettier-typescript && pnpm run lint-prettier-javascript",
|
|
54
|
-
"lint-prettier-javascript": "prettier --check \"./**/*.js\"",
|
|
55
|
+
"lint-prettier-javascript": "prettier --check \"./**/*.js\" \"!docs\"",
|
|
55
56
|
"lint-prettier-typescript": "prettier --check --parser typescript \"./**/*.ts\"",
|
|
56
57
|
"lint-tsc": "tsc --noEmit",
|
|
57
58
|
"prepare-live-eslint-plugin": "pnpm uninstall @alextheman/eslint-plugin && pnpm install --save-dev @alextheman/eslint-plugin",
|