@alextheman/utility 4.3.0 → 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 +124 -36
- package/dist/index.d.cts +130 -23
- package/dist/index.d.ts +130 -23
- package/dist/index.js +124 -36
- package/package.json +6 -4
package/dist/index.d.cts
CHANGED
|
@@ -44,6 +44,8 @@ type ParallelTuple<A, B> = [A, B | undefined];
|
|
|
44
44
|
* If `secondArray` is shorter than `firstArray`, the second position in the tuple
|
|
45
45
|
* will be `undefined`. Iteration always uses the length of the first array.
|
|
46
46
|
*
|
|
47
|
+
* @category Array Helpers
|
|
48
|
+
*
|
|
47
49
|
* @template FirstArrayItem
|
|
48
50
|
* @template SecondArrayItem
|
|
49
51
|
*
|
|
@@ -58,6 +60,8 @@ declare function paralleliseArrays<FirstArrayItem, SecondArrayItem>(firstArray:
|
|
|
58
60
|
/**
|
|
59
61
|
* Randomises the order of a given array and returns the result in a new array without mutating the original.
|
|
60
62
|
*
|
|
63
|
+
* @category Array Helpers
|
|
64
|
+
*
|
|
61
65
|
* @template ItemType - The type of the array items.
|
|
62
66
|
*
|
|
63
67
|
* @param array - The array to randomise.
|
|
@@ -73,6 +77,8 @@ declare function randomiseArray<ItemType>(array: ItemType[]): ItemType[];
|
|
|
73
77
|
* - The range is inclusive of `start` and exclusive of `stop`.
|
|
74
78
|
* - The sign of `step` must match the direction of the range.
|
|
75
79
|
*
|
|
80
|
+
* @category Array Helpers
|
|
81
|
+
*
|
|
76
82
|
* @param start - The number to start at (inclusive).
|
|
77
83
|
* @param stop - The number to stop at (exclusive).
|
|
78
84
|
* @param step - The step size between numbers, defaulting to 1.
|
|
@@ -88,6 +94,8 @@ declare function range(start: number, stop: number, step?: number): number[];
|
|
|
88
94
|
/**
|
|
89
95
|
* Removes duplicate values from an array.
|
|
90
96
|
*
|
|
97
|
+
* @category Array Helpers
|
|
98
|
+
*
|
|
91
99
|
* @template ItemType - The type of the array items.
|
|
92
100
|
*
|
|
93
101
|
* @param array - The array to remove duplicates from.
|
|
@@ -100,6 +108,8 @@ declare function removeDuplicates<ItemType>(array: ItemType[] | readonly ItemTyp
|
|
|
100
108
|
/**
|
|
101
109
|
* Adds a given number of days to the provided date, returning the result as a new instance of Date.
|
|
102
110
|
*
|
|
111
|
+
* @category Date
|
|
112
|
+
*
|
|
103
113
|
* @param currentDate - The starting date (defaults to today).
|
|
104
114
|
* @param dayIncrement - The amount of days you want to add (defaults to 1)
|
|
105
115
|
*
|
|
@@ -111,6 +121,8 @@ declare function addDaysToDate(currentDate?: Date, dayIncrement?: number): Date;
|
|
|
111
121
|
/**
|
|
112
122
|
* Creates a human-readable string with information about the input date.
|
|
113
123
|
*
|
|
124
|
+
* @category Date
|
|
125
|
+
*
|
|
114
126
|
* @param inputDate - The date to base the string on.
|
|
115
127
|
*
|
|
116
128
|
* @returns A new string with information about the given date.
|
|
@@ -125,6 +137,8 @@ declare function formatDateAndTime(inputDate: Date): string;
|
|
|
125
137
|
/**
|
|
126
138
|
* Checks if the provided dates are exactly a whole number of years apart.
|
|
127
139
|
*
|
|
140
|
+
* @category Date
|
|
141
|
+
*
|
|
128
142
|
* @param firstDate - The first date to compare.
|
|
129
143
|
* @param secondDate - The second date to compare.
|
|
130
144
|
*
|
|
@@ -136,6 +150,8 @@ declare function isAnniversary(firstDate: Date, secondDate: Date): boolean;
|
|
|
136
150
|
/**
|
|
137
151
|
* Checks if the provided year is a leap year.
|
|
138
152
|
*
|
|
153
|
+
* @category Date
|
|
154
|
+
*
|
|
139
155
|
* @param year - The year to check as a number.
|
|
140
156
|
*
|
|
141
157
|
* @throws {TypeError} If the year provided is not an integer.
|
|
@@ -148,6 +164,8 @@ declare function isLeapYear(year: number): boolean;
|
|
|
148
164
|
/**
|
|
149
165
|
* Checks if the provided dates are exactly a whole number of months apart.
|
|
150
166
|
*
|
|
167
|
+
* @category Date
|
|
168
|
+
*
|
|
151
169
|
* @param firstDate - The first date to compare.
|
|
152
170
|
* @param secondDate - The second date to compare.
|
|
153
171
|
*
|
|
@@ -159,6 +177,8 @@ declare function isMonthlyMultiple(firstDate: Date, secondDate: Date): boolean;
|
|
|
159
177
|
/**
|
|
160
178
|
* Checks if the provided dates happen on the exact same day, month, and year.
|
|
161
179
|
*
|
|
180
|
+
* @category Date
|
|
181
|
+
*
|
|
162
182
|
* @param firstDate - The first date to compare.
|
|
163
183
|
* @param secondDate - The second date to compare.
|
|
164
184
|
*
|
|
@@ -170,6 +190,8 @@ declare function isSameDate(firstDate: Date, secondDate: Date): boolean;
|
|
|
170
190
|
/**
|
|
171
191
|
* Asynchronously converts a file to a base 64 string
|
|
172
192
|
*
|
|
193
|
+
* @category Miscellaneous
|
|
194
|
+
*
|
|
173
195
|
* @param file - The file to convert.
|
|
174
196
|
*
|
|
175
197
|
* @throws {Error} If the file reader gives an error.
|
|
@@ -181,7 +203,11 @@ declare function convertFileToBase64(file: File): Promise<string>;
|
|
|
181
203
|
//#region src/types/APIError.d.ts
|
|
182
204
|
type HTTPErrorCode = 400 | 401 | 403 | 404 | 418 | 500;
|
|
183
205
|
declare const httpErrorCodeLookup: Record<HTTPErrorCode, string>;
|
|
184
|
-
/**
|
|
206
|
+
/**
|
|
207
|
+
* Represents common errors you may get from a HTTP API request.
|
|
208
|
+
*
|
|
209
|
+
* @category Types
|
|
210
|
+
*/
|
|
185
211
|
declare class APIError extends Error {
|
|
186
212
|
status: number;
|
|
187
213
|
/**
|
|
@@ -201,10 +227,14 @@ declare class APIError extends Error {
|
|
|
201
227
|
}
|
|
202
228
|
//#endregion
|
|
203
229
|
//#region src/types/DataError.d.ts
|
|
204
|
-
/**
|
|
230
|
+
/**
|
|
231
|
+
* Represents errors you may get that may've been caused by a specific piece of data.
|
|
232
|
+
*
|
|
233
|
+
* @category Types
|
|
234
|
+
*/
|
|
205
235
|
declare class DataError extends Error {
|
|
206
|
-
data: unknown;
|
|
207
236
|
code: string;
|
|
237
|
+
data: unknown;
|
|
208
238
|
/**
|
|
209
239
|
* @param data - The data that caused the error.
|
|
210
240
|
* @param code - A standardised code (e.g. UNEXPECTED_DATA).
|
|
@@ -223,18 +253,29 @@ declare class DataError extends Error {
|
|
|
223
253
|
}
|
|
224
254
|
//#endregion
|
|
225
255
|
//#region src/types/RecordKey.d.ts
|
|
226
|
-
/**
|
|
256
|
+
/**
|
|
257
|
+
* Represents the native Record's possible key type.
|
|
258
|
+
*
|
|
259
|
+
* @category Types
|
|
260
|
+
*/
|
|
227
261
|
type RecordKey = string | number | symbol;
|
|
228
262
|
//#endregion
|
|
229
263
|
//#region src/types/CreateEnumType.d.ts
|
|
230
264
|
/**
|
|
231
265
|
* Get the value types from a const object so the object can behave similarly to an enum.
|
|
232
266
|
*
|
|
267
|
+
* @category Types
|
|
268
|
+
*
|
|
233
269
|
* @template ObjectType - The type of the object to get the value types for.
|
|
234
270
|
*/
|
|
235
271
|
type CreateEnumType<ObjectType extends Record<RecordKey, unknown>> = ObjectType[keyof ObjectType];
|
|
236
272
|
//#endregion
|
|
237
273
|
//#region src/types/VersionType.d.ts
|
|
274
|
+
/**
|
|
275
|
+
* Represents the three common software version types.
|
|
276
|
+
*
|
|
277
|
+
* @category Types
|
|
278
|
+
*/
|
|
238
279
|
declare const VersionType: {
|
|
239
280
|
readonly MAJOR: "major";
|
|
240
281
|
readonly MINOR: "minor";
|
|
@@ -246,34 +287,39 @@ type VersionType = CreateEnumType<typeof VersionType>;
|
|
|
246
287
|
interface ToStringOptions {
|
|
247
288
|
omitPrefix?: boolean;
|
|
248
289
|
}
|
|
249
|
-
/**
|
|
290
|
+
/**
|
|
291
|
+
* Represents a software version number, considered to be made up of a major, minor, and patch part.
|
|
292
|
+
*
|
|
293
|
+
* @category Types
|
|
294
|
+
*/
|
|
250
295
|
declare class VersionNumber {
|
|
296
|
+
private static readonly NON_NEGATIVE_TUPLE_ERROR;
|
|
251
297
|
/** The major number. Increments when a feature is removed or changed in a way that is not backwards-compatible with the previous release. */
|
|
252
298
|
readonly major: number;
|
|
253
299
|
/** The minor number. Increments when a new feature is added/deprecated and is expected to be backwards-compatible with the previous release. */
|
|
254
300
|
readonly minor: number;
|
|
255
301
|
/** The patch number. Increments when the next release is fixing a bug or doing a small refactor that should not be noticeable in practice. */
|
|
256
302
|
readonly patch: number;
|
|
257
|
-
private static readonly NON_NEGATIVE_TUPLE_ERROR;
|
|
258
303
|
/**
|
|
259
304
|
* @param input - The input to create a new instance of `VersionNumber` from.
|
|
260
305
|
*/
|
|
261
306
|
constructor(input: string | [number, number, number] | VersionNumber);
|
|
262
|
-
private static formatString;
|
|
263
|
-
/**
|
|
264
|
-
* Get a string representation of the current version number.
|
|
265
|
-
*
|
|
266
|
-
* @param options - Extra additional options to apply.
|
|
267
|
-
*
|
|
268
|
-
* @returns A stringified representation of the current version number, leaving out the prefix if `omitPrefix` option was set to true.
|
|
269
|
-
*/
|
|
270
|
-
toString(options?: ToStringOptions): string;
|
|
271
307
|
/**
|
|
272
308
|
* Gets the current version type of the current instance of `VersionNumber`.
|
|
273
309
|
*
|
|
274
310
|
* @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
|
|
275
311
|
*/
|
|
276
312
|
get type(): VersionType;
|
|
313
|
+
private static formatString;
|
|
314
|
+
/**
|
|
315
|
+
* Checks if the provided version numbers have the exact same major, minor, and patch numbers.
|
|
316
|
+
*
|
|
317
|
+
* @param firstVersion - The first version number to compare.
|
|
318
|
+
* @param secondVersion - The second version number to compare.
|
|
319
|
+
*
|
|
320
|
+
* @returns `true` if the provided version numbers have exactly the same major, minor, and patch numbers, and returns `false` otherwise.
|
|
321
|
+
*/
|
|
322
|
+
static isEqual(firstVersion: VersionNumber, secondVersion: VersionNumber): boolean;
|
|
277
323
|
/**
|
|
278
324
|
* Determines whether the current instance of `VersionNumber` is a major, minor, or patch version.
|
|
279
325
|
*
|
|
@@ -286,20 +332,21 @@ declare class VersionNumber {
|
|
|
286
332
|
*/
|
|
287
333
|
increment(incrementType: VersionType): VersionNumber;
|
|
288
334
|
/**
|
|
289
|
-
*
|
|
335
|
+
* Get a string representation of the current version number.
|
|
290
336
|
*
|
|
291
|
-
* @param
|
|
292
|
-
* @param secondVersion - The second version number to compare.
|
|
337
|
+
* @param options - Extra additional options to apply.
|
|
293
338
|
*
|
|
294
|
-
* @returns
|
|
339
|
+
* @returns A stringified representation of the current version number, leaving out the prefix if `omitPrefix` option was set to true.
|
|
295
340
|
*/
|
|
296
|
-
|
|
341
|
+
toString(options?: ToStringOptions): string;
|
|
297
342
|
}
|
|
298
343
|
//#endregion
|
|
299
344
|
//#region src/types/ArrayElement.d.ts
|
|
300
345
|
/**
|
|
301
346
|
* Gets the individual element types from an array type.
|
|
302
347
|
*
|
|
348
|
+
* @category Types
|
|
349
|
+
*
|
|
303
350
|
* @template ArrayType - The type of the array itself.
|
|
304
351
|
*/
|
|
305
352
|
type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
|
|
@@ -308,6 +355,8 @@ type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends read
|
|
|
308
355
|
/**
|
|
309
356
|
* Resolves to an error message type if the type argument could potentially be undefined.
|
|
310
357
|
*
|
|
358
|
+
* @category Types
|
|
359
|
+
*
|
|
311
360
|
* @template InputType - The type to disallow undefined on.
|
|
312
361
|
*/
|
|
313
362
|
type DisallowUndefined<InputType> = undefined extends InputType ? ["Error: Generic type cannot include undefined"] : InputType;
|
|
@@ -316,6 +365,8 @@ type DisallowUndefined<InputType> = undefined extends InputType ? ["Error: Gener
|
|
|
316
365
|
/**
|
|
317
366
|
* Allows case-insensitive variants of a known string type.
|
|
318
367
|
*
|
|
368
|
+
* @category Types
|
|
369
|
+
*
|
|
319
370
|
* @template StringType - The input string type.
|
|
320
371
|
*/
|
|
321
372
|
type IgnoreCase<StringType extends string> = string extends StringType ? string : StringType extends `${infer FirstCharacter}${infer SecondCharacter}${infer Remainder}` ? `${Uppercase<FirstCharacter> | Lowercase<FirstCharacter>}${Uppercase<SecondCharacter> | Lowercase<SecondCharacter>}${IgnoreCase<Remainder>}` : StringType extends `${infer FirstCharacter}${infer Remainder}` ? `${Uppercase<FirstCharacter> | Lowercase<FirstCharacter>}${IgnoreCase<Remainder>}` : "";
|
|
@@ -324,6 +375,8 @@ type IgnoreCase<StringType extends string> = string extends StringType ? string
|
|
|
324
375
|
/**
|
|
325
376
|
* Resolves to `never` if the given type may be undefined.
|
|
326
377
|
*
|
|
378
|
+
* @category Types
|
|
379
|
+
*
|
|
327
380
|
* @template InputType - The type to check.
|
|
328
381
|
*/
|
|
329
382
|
type NonUndefined<InputType> = InputType extends undefined ? never : InputType;
|
|
@@ -332,6 +385,8 @@ type NonUndefined<InputType> = InputType extends undefined ? never : InputType;
|
|
|
332
385
|
/**
|
|
333
386
|
* Resolves to the given type if the first type is `true`, otherwise resolves to `undefined`
|
|
334
387
|
*
|
|
388
|
+
* @category Types
|
|
389
|
+
*
|
|
335
390
|
* @param Condition - The condition to check.
|
|
336
391
|
* @param ResolvedTypeIfTrue - The type to resolve to if the condition may be `true`.
|
|
337
392
|
*/
|
|
@@ -364,6 +419,8 @@ type CreateFormDataOptions<Key extends RecordKey> = CreateFormDataOptionsUndefin
|
|
|
364
419
|
/**
|
|
365
420
|
* Creates FormData from a given object, resolving non-string types as appropriate.
|
|
366
421
|
*
|
|
422
|
+
* @category Miscellaneous
|
|
423
|
+
*
|
|
367
424
|
* @template DataType - The type of the given data.
|
|
368
425
|
*
|
|
369
426
|
* @param data - The data to create FormData from.
|
|
@@ -377,6 +434,8 @@ declare function createFormData<DataType extends Record<RecordKey, unknown>>(dat
|
|
|
377
434
|
/**
|
|
378
435
|
* Gets a random number between the given bounds.
|
|
379
436
|
*
|
|
437
|
+
* @category Miscellaneous
|
|
438
|
+
*
|
|
380
439
|
* @param lowerBound - The lowest number that can be chosen.
|
|
381
440
|
* @param upperBound - The highest number that can be chosen.
|
|
382
441
|
*
|
|
@@ -388,6 +447,8 @@ declare function getRandomNumber(lowerBound: number, upperBound: number): number
|
|
|
388
447
|
/**
|
|
389
448
|
* Checks to see if the given array is sorted in ascending order.
|
|
390
449
|
*
|
|
450
|
+
* @category Miscellaneous
|
|
451
|
+
*
|
|
391
452
|
* @param array - The array to check.
|
|
392
453
|
*
|
|
393
454
|
* @returns `true` if the array is sorted in ascending order, and `false` otherwise.
|
|
@@ -404,6 +465,8 @@ interface StringListToArrayOptions {
|
|
|
404
465
|
/**
|
|
405
466
|
* Converts a stringly-typed list to a proper array.
|
|
406
467
|
*
|
|
468
|
+
* @category Miscellaneous
|
|
469
|
+
*
|
|
407
470
|
* @param stringList - The stringly-typed list to convert.
|
|
408
471
|
* @param options - The options to apply to the conversion.
|
|
409
472
|
* @param options.separator - What each item in the list is separated by.
|
|
@@ -420,6 +483,8 @@ declare function stringListToArray(stringList: string, {
|
|
|
420
483
|
/**
|
|
421
484
|
* Waits for the given number of seconds
|
|
422
485
|
*
|
|
486
|
+
* @category Miscellaneous
|
|
487
|
+
*
|
|
423
488
|
* @param seconds - The number of seconds to wait.
|
|
424
489
|
*
|
|
425
490
|
* @returns A Promise that resolves after the given number of seconds.
|
|
@@ -430,6 +495,8 @@ declare function wait(seconds: number): Promise<void>;
|
|
|
430
495
|
/**
|
|
431
496
|
* Gets the keys from a given record object, properly typed to be an array of the key of the input object's type.
|
|
432
497
|
*
|
|
498
|
+
* @category Object Helpers
|
|
499
|
+
*
|
|
433
500
|
* @template InputRecordType - The type of the input object.
|
|
434
501
|
*
|
|
435
502
|
* @param record - The record to get the keys from.
|
|
@@ -442,6 +509,8 @@ declare function getRecordKeys<InputRecordType extends Record<RecordKey, unknown
|
|
|
442
509
|
/**
|
|
443
510
|
* Omits properties from a given object.
|
|
444
511
|
*
|
|
512
|
+
* @category Object Helpers
|
|
513
|
+
*
|
|
445
514
|
* @template ObjectType - The type of the input object.
|
|
446
515
|
* @template KeysToOmit - A type representing the keys to omit from the object.
|
|
447
516
|
*
|
|
@@ -456,6 +525,8 @@ declare function omitProperties<ObjectType extends Record<string, unknown> | Rea
|
|
|
456
525
|
/**
|
|
457
526
|
* Takes a stringly-typed boolean and converts it to an actual boolean type.
|
|
458
527
|
*
|
|
528
|
+
* @category Parsers
|
|
529
|
+
*
|
|
459
530
|
* @param inputString - The string to parse.
|
|
460
531
|
*
|
|
461
532
|
* @throws {DataError} If the string is not either `true` or `false` (case insensitive).
|
|
@@ -470,11 +541,17 @@ declare const envSchema: z.ZodEnum<{
|
|
|
470
541
|
development: "development";
|
|
471
542
|
production: "production";
|
|
472
543
|
}>;
|
|
473
|
-
/**
|
|
544
|
+
/**
|
|
545
|
+
* Represents the most common development environments
|
|
546
|
+
*
|
|
547
|
+
* @category Types
|
|
548
|
+
*/
|
|
474
549
|
type Env = z.infer<typeof envSchema>;
|
|
475
550
|
/**
|
|
476
551
|
* Parses the input and verifies it matches one of the environments allowed by the Env types ("test" | "development" | "production").
|
|
477
552
|
*
|
|
553
|
+
* @category Parsers
|
|
554
|
+
*
|
|
478
555
|
* @param data - The data to parse.
|
|
479
556
|
*
|
|
480
557
|
* @throws {DataError} If the data does not match one of the environments allowed by the Env types ("test" | "development" | "production").
|
|
@@ -508,6 +585,8 @@ declare function parseFormData(formData: FormData): Record<string, string | Blob
|
|
|
508
585
|
/**
|
|
509
586
|
* Converts a string to an integer and throws an error if it cannot be converted.
|
|
510
587
|
*
|
|
588
|
+
* @category Parsers
|
|
589
|
+
*
|
|
511
590
|
* @param string - A string to convert into a number.
|
|
512
591
|
* @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.
|
|
513
592
|
*
|
|
@@ -521,6 +600,8 @@ declare function parseIntStrict(string: string, radix?: number): number;
|
|
|
521
600
|
/**
|
|
522
601
|
* Parses the input and verifies it is a valid software version type (i.e. `"major" | "minor" | "patch"`)
|
|
523
602
|
*
|
|
603
|
+
* @category Parsers
|
|
604
|
+
*
|
|
524
605
|
* @param data - The data to parse.
|
|
525
606
|
*
|
|
526
607
|
* @throws {DataError} If the data does not match one of the allowed version types (`"major" | "minor" | "patch"`).
|
|
@@ -533,6 +614,8 @@ declare function parseVersionType(data: unknown): VersionType;
|
|
|
533
614
|
/**
|
|
534
615
|
* An alternative function to zodSchema.parse() that can be used to strictly parse Zod schemas.
|
|
535
616
|
*
|
|
617
|
+
* @category Parsers
|
|
618
|
+
*
|
|
536
619
|
* @template Output - The Zod output type.
|
|
537
620
|
* @template Input - The Zod input type.
|
|
538
621
|
* @template Internals - The Zod internal types based on the output and input types.
|
|
@@ -552,6 +635,8 @@ declare function parseZodSchema<Output, Input, Internals extends core.$ZodTypeIn
|
|
|
552
635
|
/**
|
|
553
636
|
* Deeply copies an object or array such that all child objects/arrays are also copied.
|
|
554
637
|
*
|
|
638
|
+
* @category Recursive
|
|
639
|
+
*
|
|
555
640
|
* @template ObjectType - The type of the input object.
|
|
556
641
|
*
|
|
557
642
|
* @param object - The object to copy. May also be an array.
|
|
@@ -567,6 +652,8 @@ declare function deepCopy<ObjectType extends object>(object: ObjectType): Object
|
|
|
567
652
|
* Note that this will also freeze the input itself as well.
|
|
568
653
|
* 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.
|
|
569
654
|
*
|
|
655
|
+
* @category Recursive
|
|
656
|
+
*
|
|
570
657
|
* @template ObjectType - The type of the input object.
|
|
571
658
|
*
|
|
572
659
|
* @param object - The object to freeze. May also be an array.
|
|
@@ -579,6 +666,8 @@ declare function deepFreeze<ObjectType extends object>(object: ObjectType): Read
|
|
|
579
666
|
/**
|
|
580
667
|
* Appends a semicolon to the end of a string, trimming where necessary first.
|
|
581
668
|
*
|
|
669
|
+
* @category String Helpers
|
|
670
|
+
*
|
|
582
671
|
* @param stringToAppendTo - The string to append a semicolon to.
|
|
583
672
|
*
|
|
584
673
|
* @throws {Error} If the string contains multiple lines.
|
|
@@ -595,6 +684,8 @@ interface CamelToKebabOptions {
|
|
|
595
684
|
/**
|
|
596
685
|
* Converts a string from camelCase to kebab-case
|
|
597
686
|
*
|
|
687
|
+
* @category String Helpers
|
|
688
|
+
*
|
|
598
689
|
* @param string - The string to convert.
|
|
599
690
|
* @param options - Options to apply to the conversion.
|
|
600
691
|
*
|
|
@@ -610,6 +701,8 @@ interface KebabToCamelOptions {
|
|
|
610
701
|
/**
|
|
611
702
|
* Converts a string from kebab-case to camelCase
|
|
612
703
|
*
|
|
704
|
+
* @category String Helpers
|
|
705
|
+
*
|
|
613
706
|
* @param string - The string to convert.
|
|
614
707
|
* @param options - Options to apply to the conversion.
|
|
615
708
|
*
|
|
@@ -620,13 +713,14 @@ declare function kebabToCamel(string: string, options?: KebabToCamelOptions): st
|
|
|
620
713
|
//#region src/functions/stringHelpers/normalizeImportPath.d.ts
|
|
621
714
|
/**
|
|
622
715
|
* Normalizes an import path meant for use in an import statement in JavaScript.
|
|
623
|
-
*
|
|
624
716
|
* 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.
|
|
625
717
|
*
|
|
626
718
|
* If the path starts with ./, it is preserved (unlike what would happen with path.posix.normalize() normally).
|
|
627
719
|
*
|
|
628
720
|
* Helpful for custom linter rules that need to check (or fix) import paths.
|
|
629
721
|
*
|
|
722
|
+
* @category String Helpers
|
|
723
|
+
*
|
|
630
724
|
* @param importPath - The import path to normalize.
|
|
631
725
|
*
|
|
632
726
|
* @returns The import path normalized.
|
|
@@ -634,13 +728,14 @@ declare function kebabToCamel(string: string, options?: KebabToCamelOptions): st
|
|
|
634
728
|
declare function normalizeImportPath(importPath: string): string;
|
|
635
729
|
/**
|
|
636
730
|
* Normalises an import path meant for use in an import statement in JavaScript.
|
|
637
|
-
*
|
|
638
731
|
* 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.
|
|
639
732
|
*
|
|
640
733
|
* If the path starts with ./, it is preserved (unlike what would happen with path.posix.normalize() normally).
|
|
641
734
|
*
|
|
642
735
|
* Helpful for custom linter rules that need to check (or fix) import paths.
|
|
643
736
|
*
|
|
737
|
+
* @category String Helpers
|
|
738
|
+
*
|
|
644
739
|
* @param importPath - The import path to normalise.
|
|
645
740
|
*
|
|
646
741
|
* @returns The import path normalised.
|
|
@@ -651,6 +746,8 @@ declare const normaliseImportPath: typeof normalizeImportPath;
|
|
|
651
746
|
/**
|
|
652
747
|
* Truncates a string and appends `...` to the end of it
|
|
653
748
|
*
|
|
749
|
+
* @category String Helpers
|
|
750
|
+
*
|
|
654
751
|
* @param stringToTruncate - The string to truncate.
|
|
655
752
|
* @param maxLength - The length at which to start truncating. Note that this does not include the `...` part that would be appended.
|
|
656
753
|
*
|
|
@@ -662,6 +759,8 @@ declare function truncate(stringToTruncate: string, maxLength?: number): string;
|
|
|
662
759
|
/**
|
|
663
760
|
* Creates a template strings array given a regular array of strings
|
|
664
761
|
*
|
|
762
|
+
* @category Tagged Template
|
|
763
|
+
*
|
|
665
764
|
* @param strings - The array of strings.
|
|
666
765
|
*
|
|
667
766
|
* @returns A template strings array that can be passed as the first argument of any tagged template function.
|
|
@@ -678,6 +777,8 @@ declare function createTemplateStringsArray(strings: readonly string[]): Templat
|
|
|
678
777
|
*
|
|
679
778
|
* In this case, it will be functionally the same as if you just wrote the template string by itself.
|
|
680
779
|
*
|
|
780
|
+
* @category Tagged Template
|
|
781
|
+
*
|
|
681
782
|
* @param strings - The strings from the template to process.
|
|
682
783
|
* @param interpolations - An array of all interpolations from the template.
|
|
683
784
|
*
|
|
@@ -693,6 +794,8 @@ declare function interpolate(strings: TemplateStringsArray, ...interpolations: u
|
|
|
693
794
|
*
|
|
694
795
|
* interpolateObjects`Template string here ${{ my: "object" }}`.
|
|
695
796
|
*
|
|
797
|
+
* @category Tagged Template
|
|
798
|
+
*
|
|
696
799
|
* @param strings - The strings from the template to process.
|
|
697
800
|
* @param interpolations - An array of all interpolations from the template.
|
|
698
801
|
*
|
|
@@ -711,6 +814,8 @@ type NormalizeIndentsFunction = NormaliseIndentsFunction;
|
|
|
711
814
|
/**
|
|
712
815
|
* Provides a new function that removes any extraneous indents from a multi-line template string, with the given options applied.
|
|
713
816
|
*
|
|
817
|
+
* @category Tagged Template
|
|
818
|
+
*
|
|
714
819
|
* @param options - The options to apply.
|
|
715
820
|
*
|
|
716
821
|
* @returns A function that takes a template string, and returns a new string with the strings and interpolations from the template applied, and extraneous indents removed.
|
|
@@ -725,6 +830,8 @@ declare function normaliseIndents(options: NormaliseIndentsOptions): NormaliseIn
|
|
|
725
830
|
* with a new line
|
|
726
831
|
* and another new line`.
|
|
727
832
|
*
|
|
833
|
+
*@category Tagged Template
|
|
834
|
+
*
|
|
728
835
|
* @param strings - The strings from the template to process.
|
|
729
836
|
* @param interpolations - An array of all interpolations from the template.
|
|
730
837
|
*
|