@alextheman/utility 3.6.0 → 3.8.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.
- package/dist/index.cjs +566 -198
- package/dist/index.d.cts +506 -111
- package/dist/index.d.ts +506 -111
- package/dist/index.js +558 -194
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -3,8 +3,8 @@ import z, { ZodType, core, z as z$1 } from "zod";
|
|
|
3
3
|
//#region src/constants/NAMESPACE_EXPORT_REGEX.d.ts
|
|
4
4
|
declare const NAMESPACE_EXPORT_REGEX = "export\\s+\\*\\s+from";
|
|
5
5
|
//#endregion
|
|
6
|
-
//#region src/
|
|
7
|
-
declare
|
|
6
|
+
//#region src/constants/VERSION_NUMBER_REGEX.d.ts
|
|
7
|
+
declare const VERSION_NUMBER_REGEX: string;
|
|
8
8
|
//#endregion
|
|
9
9
|
//#region src/functions/arrayHelpers/fillArray.d.ts
|
|
10
10
|
/**
|
|
@@ -70,8 +70,8 @@ declare function randomiseArray<ItemType$1>(array: ItemType$1[]): ItemType$1[];
|
|
|
70
70
|
/**
|
|
71
71
|
* Creates an array of numbers within a given range.
|
|
72
72
|
*
|
|
73
|
-
* The range is inclusive of `start` and exclusive of `stop`.
|
|
74
|
-
* The sign of `step` must match the direction of the range.
|
|
73
|
+
* - The range is inclusive of `start` and exclusive of `stop`.
|
|
74
|
+
* - The sign of `step` must match the direction of the range.
|
|
75
75
|
*
|
|
76
76
|
* @param start - The number to start at (inclusive).
|
|
77
77
|
* @param stop - The number to stop at (exclusive).
|
|
@@ -84,22 +84,124 @@ declare function randomiseArray<ItemType$1>(array: ItemType$1[]): ItemType$1[];
|
|
|
84
84
|
*/
|
|
85
85
|
declare function range(start: number, stop: number, step?: number): number[];
|
|
86
86
|
//#endregion
|
|
87
|
-
//#region src/functions/
|
|
88
|
-
|
|
87
|
+
//#region src/functions/arrayHelpers/removeDuplicates.d.ts
|
|
88
|
+
/**
|
|
89
|
+
* Removes duplicate values from an array.
|
|
90
|
+
*
|
|
91
|
+
* @template ItemType - The type of the array items.
|
|
92
|
+
*
|
|
93
|
+
* @param array - The array to remove duplicates from.
|
|
94
|
+
*
|
|
95
|
+
* @returns A new array with a different reference in memory, with the duplicates removed.
|
|
96
|
+
*/
|
|
97
|
+
declare function removeDuplicates<ItemType$1>(array: ItemType$1[] | readonly ItemType$1[]): ItemType$1[];
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/functions/date/addDaysToDate.d.ts
|
|
100
|
+
/**
|
|
101
|
+
* Adds a given number of days to the provided date, returning the result as a new instance of Date.
|
|
102
|
+
*
|
|
103
|
+
* @param currentDate - The starting date (defaults to today).
|
|
104
|
+
* @param dayIncrement - The amount of days you want to add (defaults to 1)
|
|
105
|
+
*
|
|
106
|
+
* @returns A new Date instance with the number of days added to the initially provided date.
|
|
107
|
+
*/
|
|
108
|
+
declare function addDaysToDate(currentDate?: Date, dayIncrement?: number): Date;
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/functions/date/formatDateAndTime.d.ts
|
|
111
|
+
/**
|
|
112
|
+
* Creates a human-readable string with information about the input date.
|
|
113
|
+
*
|
|
114
|
+
* @param inputDate - The date to base the string on.
|
|
115
|
+
*
|
|
116
|
+
* @returns A new string with information about the given date.
|
|
117
|
+
*
|
|
118
|
+
* - If the date given is today, the output will be something like `Today at HH:MM`
|
|
119
|
+
* - If the date given happened yesterday, the output will be something like `Yesterday at HH:MM`
|
|
120
|
+
* - For any other date, the output will be something like `DD/MM/YYYY, HH:MM`
|
|
121
|
+
*/
|
|
122
|
+
declare function formatDateAndTime(inputDate: Date): string;
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region src/functions/date/isAnniversary.d.ts
|
|
125
|
+
/**
|
|
126
|
+
* Checks if the provided dates are exactly a whole number of years apart.
|
|
127
|
+
*
|
|
128
|
+
* @param firstDate - The first date to compare.
|
|
129
|
+
* @param secondDate - The second date to compare.
|
|
130
|
+
*
|
|
131
|
+
* @returns True if the provided dates are exactly a whole number of years apart, and false otherwise.
|
|
132
|
+
*/
|
|
133
|
+
declare function isAnniversary(firstDate: Date, secondDate: Date): boolean;
|
|
89
134
|
//#endregion
|
|
90
|
-
//#region src/functions/
|
|
135
|
+
//#region src/functions/date/isLeapYear.d.ts
|
|
136
|
+
/**
|
|
137
|
+
* Checks if the provided year is a leap year.
|
|
138
|
+
*
|
|
139
|
+
* @param year - The year to check as a number.
|
|
140
|
+
*
|
|
141
|
+
* @throws {TypeError} If the year provided is not an integer.
|
|
142
|
+
*
|
|
143
|
+
* @returns True if the year is a leap year, and false otherwise.
|
|
144
|
+
*/
|
|
145
|
+
declare function isLeapYear(year: number): boolean;
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region src/functions/date/isMonthlyMultiple.d.ts
|
|
148
|
+
/**
|
|
149
|
+
* Checks if the provided dates are exactly a whole number of months apart.
|
|
150
|
+
*
|
|
151
|
+
* @param firstDate - The first date to compare.
|
|
152
|
+
* @param secondDate - The second date to compare.
|
|
153
|
+
*
|
|
154
|
+
* @returns True if the provided dates are exactly a whole number of months apart, and false otherwise.
|
|
155
|
+
*/
|
|
156
|
+
declare function isMonthlyMultiple(firstDate: Date, secondDate: Date): boolean;
|
|
157
|
+
//#endregion
|
|
158
|
+
//#region src/functions/date/isSameDate.d.ts
|
|
159
|
+
/**
|
|
160
|
+
* Checks if the provided dates happen on the exact same day, month, and year.
|
|
161
|
+
*
|
|
162
|
+
* @param firstDate - The first date to compare.
|
|
163
|
+
* @param secondDate - The second date to compare.
|
|
164
|
+
*
|
|
165
|
+
* @returns True if the provided dates occur on exactly the same day, month, and year, and returns false otherwise.
|
|
166
|
+
*/
|
|
167
|
+
declare function isSameDate(firstDate: Date, secondDate: Date): boolean;
|
|
168
|
+
//#endregion
|
|
169
|
+
//#region src/functions/miscellaneous/convertFileToBase64.d.ts
|
|
170
|
+
/**
|
|
171
|
+
* Asynchronously converts a file to a base 64 string
|
|
172
|
+
*
|
|
173
|
+
* @param file - The file to convert.
|
|
174
|
+
*
|
|
175
|
+
* @throws {Error} If the file reader gives an error.
|
|
176
|
+
*
|
|
177
|
+
* @returns A promise that resolves to the encoded base 64 string.
|
|
178
|
+
*/
|
|
91
179
|
declare function convertFileToBase64(file: File): Promise<string>;
|
|
92
180
|
//#endregion
|
|
93
181
|
//#region src/types/APIError.d.ts
|
|
94
182
|
type HTTPErrorCode = 400 | 401 | 403 | 404 | 418 | 500;
|
|
95
183
|
declare const httpErrorCodeLookup: Record<HTTPErrorCode, string>;
|
|
184
|
+
/** Represents common errors you may get from a HTTP API request. */
|
|
96
185
|
declare class APIError extends Error {
|
|
97
186
|
status: number;
|
|
187
|
+
/**
|
|
188
|
+
* @param status - A HTTP status code. Can be any number, but numbers between 400 and 600 are encouraged to fit with HTTP status code conventions.
|
|
189
|
+
* @param message - An error message to display alongside the status code.
|
|
190
|
+
* @param options - Extra options to be passed to super Error constructor.
|
|
191
|
+
*/
|
|
98
192
|
constructor(status?: HTTPErrorCode | number, message?: string, options?: ErrorOptions);
|
|
193
|
+
/**
|
|
194
|
+
* Checks whether the given input may have been caused by an APIError.
|
|
195
|
+
*
|
|
196
|
+
* @param input - The input to check.
|
|
197
|
+
*
|
|
198
|
+
* @returns `true` if the input is an APIError, and `false` otherwise. The type of the input will also be narrowed down to APIError if `true`.
|
|
199
|
+
*/
|
|
99
200
|
static check(input: unknown): input is APIError;
|
|
100
201
|
}
|
|
101
202
|
//#endregion
|
|
102
203
|
//#region src/types/DataError.d.ts
|
|
204
|
+
/** Represents errors you may get that may've been caused by a specific piece of data. */
|
|
103
205
|
declare class DataError extends Error {
|
|
104
206
|
data: unknown;
|
|
105
207
|
code: string;
|
|
@@ -110,6 +212,13 @@ declare class DataError extends Error {
|
|
|
110
212
|
* @param options - Extra options to pass to super Error constructor.
|
|
111
213
|
*/
|
|
112
214
|
constructor(data: unknown, message?: string, code?: string, options?: ErrorOptions);
|
|
215
|
+
/**
|
|
216
|
+
* Checks whether the given input may have been caused by a DataError.
|
|
217
|
+
*
|
|
218
|
+
* @param input - The input to check.
|
|
219
|
+
*
|
|
220
|
+
* @returns `true` if the input is a DataError, and `false` otherwise. The type of the input will also be narrowed down to DataError if `true`.
|
|
221
|
+
*/
|
|
113
222
|
static check(input: unknown): input is DataError;
|
|
114
223
|
}
|
|
115
224
|
//#endregion
|
|
@@ -128,147 +237,179 @@ type UUID = z.infer<typeof uuidSchema>;
|
|
|
128
237
|
declare function parseUUID(UUID: unknown): UUID;
|
|
129
238
|
//#endregion
|
|
130
239
|
//#region src/types/ArrayElement.d.ts
|
|
131
|
-
|
|
240
|
+
/**
|
|
241
|
+
* Gets the individual element types from an array type.
|
|
242
|
+
*
|
|
243
|
+
* @template ArrayType - The type of the array itself.
|
|
244
|
+
*/
|
|
245
|
+
type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
|
|
132
246
|
//#endregion
|
|
133
247
|
//#region src/types/DeepReadonly.d.ts
|
|
248
|
+
/** @deprecated This type did not work with the deepFreeze function as intended and therefore should not be used. */
|
|
134
249
|
type DeepReadonly<T> = T extends ((...args: unknown[]) => unknown) ? T : T extends (infer ItemType)[] ? readonly DeepReadonly<ItemType>[] : T extends object ? { readonly [K in keyof T]: DeepReadonly<T[K]> } : T;
|
|
135
250
|
//#endregion
|
|
136
251
|
//#region src/types/DisallowUndefined.d.ts
|
|
137
|
-
|
|
252
|
+
/**
|
|
253
|
+
* Resolves to an error message type if the type argument could potentially be undefined.
|
|
254
|
+
*
|
|
255
|
+
* @template InputType - The type to disallow undefined on.
|
|
256
|
+
*/
|
|
257
|
+
type DisallowUndefined<InputType> = undefined extends InputType ? ["Error: Generic type cannot include undefined"] : InputType;
|
|
138
258
|
//#endregion
|
|
139
259
|
//#region src/types/IgnoreCase.d.ts
|
|
140
|
-
|
|
260
|
+
/**
|
|
261
|
+
* Allows case-insensitive variants of a known string type.
|
|
262
|
+
*
|
|
263
|
+
* @template StringType - The input string type.
|
|
264
|
+
*/
|
|
265
|
+
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>}` : "";
|
|
141
266
|
//#endregion
|
|
142
267
|
//#region src/types/NonUndefined.d.ts
|
|
143
|
-
|
|
268
|
+
/**
|
|
269
|
+
* Resolves to `never` if the given type may be undefined.
|
|
270
|
+
*
|
|
271
|
+
* @template InputType - The type to check.
|
|
272
|
+
*/
|
|
273
|
+
type NonUndefined<InputType> = InputType extends undefined ? never : InputType;
|
|
144
274
|
//#endregion
|
|
145
275
|
//#region src/types/OptionalOnCondition.d.ts
|
|
146
|
-
|
|
276
|
+
/**
|
|
277
|
+
* Resolves to the given type if the first type is `true`, otherwise resolves to `undefined`
|
|
278
|
+
*
|
|
279
|
+
* @param Condition - The condition to check.
|
|
280
|
+
* @param ResolvedTypeIfTrue - The type to resolve to if the condition may be `true`.
|
|
281
|
+
*/
|
|
282
|
+
type OptionalOnCondition<Condition extends boolean, ResolvedTypeIfTrue> = Condition extends true ? ResolvedTypeIfTrue : ResolvedTypeIfTrue | undefined;
|
|
147
283
|
//#endregion
|
|
148
284
|
//#region src/types/RecordKey.d.ts
|
|
285
|
+
/** Represents the native Record's possible key type. */
|
|
149
286
|
type RecordKey = string | number | symbol;
|
|
150
287
|
//#endregion
|
|
151
|
-
//#region src/functions/createFormData.d.ts
|
|
288
|
+
//#region src/functions/miscellaneous/createFormData.d.ts
|
|
152
289
|
type FormDataNullableResolutionStrategy = "stringify" | "empty" | "omit";
|
|
153
290
|
type FormDataArrayResolutionStrategy = "stringify" | "multiple";
|
|
154
|
-
interface CreateFormDataOptionsBase<
|
|
155
|
-
|
|
291
|
+
interface CreateFormDataOptionsBase<Key extends RecordKey> {
|
|
292
|
+
/** How to resolve any arrays provided in the data (can either stringify them or add them multiple times). */
|
|
293
|
+
arrayResolution?: FormDataArrayResolutionStrategy | Partial<Record<Key, FormDataArrayResolutionStrategy>>;
|
|
156
294
|
}
|
|
157
|
-
interface CreateFormDataOptionsUndefinedOrNullResolution<
|
|
158
|
-
|
|
159
|
-
|
|
295
|
+
interface CreateFormDataOptionsUndefinedOrNullResolution<Key extends RecordKey> extends CreateFormDataOptionsBase<Key> {
|
|
296
|
+
/** How to resolve undefined data (May either stringify to 'undefined', resolve to an empty string, or omit entirely). */
|
|
297
|
+
undefinedResolution?: FormDataNullableResolutionStrategy | Partial<Record<Key, FormDataNullableResolutionStrategy>>;
|
|
298
|
+
/** How to resolve null data (May either stringify to 'null', resolve to an empty string, or omit entirely). */
|
|
299
|
+
nullResolution?: FormDataNullableResolutionStrategy | Partial<Record<Key, FormDataNullableResolutionStrategy>>;
|
|
300
|
+
/** @note This must not be provided at the same time as undefinedResolution and/or nullResolution. */
|
|
160
301
|
nullableResolution?: never;
|
|
161
302
|
}
|
|
162
|
-
interface CreateFormDataOptionsNullableResolution<
|
|
303
|
+
interface CreateFormDataOptionsNullableResolution<Key extends RecordKey> extends CreateFormDataOptionsBase<Key> {
|
|
304
|
+
/** @note This must not be provided at the same time as nullableResolution. */
|
|
163
305
|
undefinedResolution?: never;
|
|
306
|
+
/** @note This must not be provided at the same time as nullableResolution. */
|
|
164
307
|
nullResolution?: never;
|
|
165
|
-
|
|
308
|
+
/** How to resolve nullable data (May either stringify to 'undefined | null', resolve to an empty string, or omit entirely). */
|
|
309
|
+
nullableResolution: FormDataNullableResolutionStrategy | Partial<Record<Key, FormDataNullableResolutionStrategy>>;
|
|
166
310
|
}
|
|
167
|
-
type CreateFormDataOptions<
|
|
168
|
-
declare function createFormData<T extends Record<RecordKey, unknown>>(data: T, options?: CreateFormDataOptions<keyof T>): FormData;
|
|
169
|
-
//#endregion
|
|
170
|
-
//#region src/functions/createTemplateStringsArray.d.ts
|
|
171
|
-
declare function createTemplateStringsArray(strings: readonly string[]): TemplateStringsArray;
|
|
172
|
-
//#endregion
|
|
173
|
-
//#region src/functions/date/addDaysToDate.d.ts
|
|
311
|
+
type CreateFormDataOptions<Key extends RecordKey> = CreateFormDataOptionsUndefinedOrNullResolution<Key> | CreateFormDataOptionsNullableResolution<Key>;
|
|
174
312
|
/**
|
|
175
|
-
*
|
|
313
|
+
* Creates FormData from a given object, resolving non-string types as appropriate.
|
|
176
314
|
*
|
|
177
|
-
* @
|
|
178
|
-
* @param dayIncrement - The amount of days you want to add (defaults to 1)
|
|
315
|
+
* @template DataType - The type of the given data.
|
|
179
316
|
*
|
|
180
|
-
* @
|
|
317
|
+
* @param data - The data to create FormData from.
|
|
318
|
+
* @param options - Options to apply to the conversion.
|
|
319
|
+
*
|
|
320
|
+
* @returns A FormData object with the data applied.
|
|
181
321
|
*/
|
|
182
|
-
declare function
|
|
322
|
+
declare function createFormData<DataType extends Record<RecordKey, unknown>>(data: DataType, options?: CreateFormDataOptions<keyof DataType>): FormData;
|
|
183
323
|
//#endregion
|
|
184
|
-
//#region src/functions/
|
|
324
|
+
//#region src/functions/miscellaneous/getRandomNumber.d.ts
|
|
185
325
|
/**
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
* @param inputDate - The date to base the string on.
|
|
326
|
+
* Gets a random number between the given bounds.
|
|
189
327
|
*
|
|
190
|
-
* @
|
|
328
|
+
* @param lowerBound - The lowest number that can be chosen.
|
|
329
|
+
* @param upperBound - The highest number that can be chosen.
|
|
191
330
|
*
|
|
192
|
-
*
|
|
193
|
-
* - If the date given happened yesterday, the output will be something like `Yesterday at HH:MM`
|
|
194
|
-
* - For any other date, the output will be something like `DD/MM/YYYY, HH:MM`
|
|
331
|
+
* @returns A random number between the provided lower bound and upper bound.
|
|
195
332
|
*/
|
|
196
|
-
declare function
|
|
333
|
+
declare function getRandomNumber(lowerBound: number, upperBound: number): number;
|
|
197
334
|
//#endregion
|
|
198
|
-
//#region src/functions/
|
|
335
|
+
//#region src/functions/miscellaneous/isOrdered.d.ts
|
|
199
336
|
/**
|
|
200
|
-
* Checks if the
|
|
337
|
+
* Checks to see if the given array is sorted in ascending order.
|
|
201
338
|
*
|
|
202
|
-
* @param
|
|
203
|
-
* @param secondDate - The second date to compare.
|
|
339
|
+
* @param array - The array to check.
|
|
204
340
|
*
|
|
205
|
-
* @returns
|
|
341
|
+
* @returns `true` if the array is sorted in ascending order, and `false` otherwise.
|
|
206
342
|
*/
|
|
207
|
-
declare function
|
|
343
|
+
declare function isOrdered(array: readonly number[]): boolean;
|
|
208
344
|
//#endregion
|
|
209
|
-
//#region src/functions/
|
|
345
|
+
//#region src/functions/miscellaneous/stringListToArray.d.ts
|
|
346
|
+
interface StringListToArrayOptions {
|
|
347
|
+
/** What each item in the list is separated by. */
|
|
348
|
+
separator?: string;
|
|
349
|
+
/** An option to trim any extra whitespace. */
|
|
350
|
+
trimWhitespace?: boolean;
|
|
351
|
+
}
|
|
210
352
|
/**
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
* @param year - The year to check as a number.
|
|
353
|
+
* Converts a stringly-typed list to a proper array.
|
|
214
354
|
*
|
|
215
|
-
* @
|
|
355
|
+
* @param stringList - The stringly-typed list to convert.
|
|
356
|
+
* @param options - The options to apply to the conversion.
|
|
357
|
+
* @param options.separator - What each item in the list is separated by.
|
|
358
|
+
* @param options.trimWhitespace - An option to trim any extra whitespace.
|
|
216
359
|
*
|
|
217
|
-
* @returns
|
|
360
|
+
* @returns A new array with each item being an item from the given list.
|
|
218
361
|
*/
|
|
219
|
-
declare function
|
|
362
|
+
declare function stringListToArray(stringList: string, {
|
|
363
|
+
separator,
|
|
364
|
+
trimWhitespace
|
|
365
|
+
}?: StringListToArrayOptions): string[];
|
|
220
366
|
//#endregion
|
|
221
|
-
//#region src/functions/
|
|
367
|
+
//#region src/functions/miscellaneous/wait.d.ts
|
|
222
368
|
/**
|
|
223
|
-
*
|
|
369
|
+
* Waits for the given number of seconds
|
|
224
370
|
*
|
|
225
|
-
* @param
|
|
226
|
-
* @param secondDate - The second date to compare.
|
|
371
|
+
* @param seconds - The number of seconds to wait.
|
|
227
372
|
*
|
|
228
|
-
* @returns
|
|
373
|
+
* @returns A Promise that resolves after the given number of seconds.
|
|
229
374
|
*/
|
|
230
|
-
declare function
|
|
375
|
+
declare function wait(seconds: number): Promise<void>;
|
|
231
376
|
//#endregion
|
|
232
|
-
//#region src/functions/
|
|
377
|
+
//#region src/functions/objectHelpers/getRecordKeys.d.ts
|
|
233
378
|
/**
|
|
234
|
-
*
|
|
379
|
+
* Gets the keys from a given record object, properly typed to be an array of the key of the input object's type.
|
|
235
380
|
*
|
|
236
|
-
* @
|
|
237
|
-
* @param secondDate - The second date to compare.
|
|
381
|
+
* @template InputRecordType - The type of the input object.
|
|
238
382
|
*
|
|
239
|
-
* @
|
|
383
|
+
* @param record - The record to get the keys from.
|
|
384
|
+
*
|
|
385
|
+
* @returns An array with all the keys of the input object in string form, but properly typed as `keyof InputRecordType`.
|
|
240
386
|
*/
|
|
241
|
-
declare function
|
|
242
|
-
//#endregion
|
|
243
|
-
//#region src/functions/deepCopy.d.ts
|
|
244
|
-
declare function deepCopy<T extends object>(object: T): T;
|
|
245
|
-
//#endregion
|
|
246
|
-
//#region src/functions/deepFreeze.d.ts
|
|
247
|
-
declare function deepFreeze<T extends object>(object: T): Readonly<T>;
|
|
248
|
-
//#endregion
|
|
249
|
-
//#region src/functions/getRandomNumber.d.ts
|
|
250
|
-
declare function getRandomNumber(lowerBound: number, upperBound: number): number;
|
|
387
|
+
declare function getRecordKeys<InputRecordType extends Record<RecordKey, unknown>>(record: InputRecordType & object): (keyof InputRecordType)[];
|
|
251
388
|
//#endregion
|
|
252
|
-
//#region src/functions/
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
declare function normalizeImportPath(importPath: string): string;
|
|
266
|
-
declare const normaliseImportPath: typeof normalizeImportPath;
|
|
267
|
-
//#endregion
|
|
268
|
-
//#region src/functions/omitProperties.d.ts
|
|
269
|
-
declare function omitProperties<T extends Record<string, unknown> | Readonly<Record<string, unknown>>, K$1 extends keyof T>(object: T, keysToOmit: K$1 | readonly K$1[]): Omit<T, K$1>;
|
|
389
|
+
//#region src/functions/objectHelpers/omitProperties.d.ts
|
|
390
|
+
/**
|
|
391
|
+
* Omits properties from a given object.
|
|
392
|
+
*
|
|
393
|
+
* @template ObjectType - The type of the input object.
|
|
394
|
+
* @template KeysToOmit - A type representing the keys to omit from the object.
|
|
395
|
+
*
|
|
396
|
+
* @param object - The object to omit properties from.
|
|
397
|
+
* @param keysToOmit - The keys to omit from the object. Can either be a single string to omit one, or an array to omit multiple.
|
|
398
|
+
*
|
|
399
|
+
* @returns An object with a new reference in memory, with the properties omitted.
|
|
400
|
+
*/
|
|
401
|
+
declare function omitProperties<ObjectType extends Record<string, unknown> | Readonly<Record<string, unknown>>, KeysToOmit extends keyof ObjectType>(object: ObjectType, keysToOmit: KeysToOmit | readonly KeysToOmit[]): Omit<ObjectType, KeysToOmit>;
|
|
270
402
|
//#endregion
|
|
271
403
|
//#region src/functions/parsers/parseBoolean.d.ts
|
|
404
|
+
/**
|
|
405
|
+
* Takes a stringly-typed boolean and converts it to an actual boolean type.
|
|
406
|
+
*
|
|
407
|
+
* @param inputString - The string to parse.
|
|
408
|
+
*
|
|
409
|
+
* @throws {TypeError} If the string is not either `true` or `false` (case insensitive).
|
|
410
|
+
*
|
|
411
|
+
* @returns The string parsed as an actual boolean.
|
|
412
|
+
*/
|
|
272
413
|
declare function parseBoolean(inputString: string): boolean;
|
|
273
414
|
/** @deprecated This function has been renamed to parseBoolean. */
|
|
274
415
|
declare const stringToBoolean: typeof parseBoolean;
|
|
@@ -279,47 +420,268 @@ declare const envSchema: z$1.ZodEnum<{
|
|
|
279
420
|
development: "development";
|
|
280
421
|
production: "production";
|
|
281
422
|
}>;
|
|
423
|
+
/** Represents the most common development environments */
|
|
282
424
|
type Env = z$1.infer<typeof envSchema>;
|
|
425
|
+
/**
|
|
426
|
+
* Parses the input and verifies it matches one of the environments allowed by the Env types ("test" | "development" | "production").
|
|
427
|
+
*
|
|
428
|
+
* @param data - The data to parse.
|
|
429
|
+
*
|
|
430
|
+
* @throws {ZodError} If the data does not match one of the environments allowed by the Env types ("test" | "development" | "production").
|
|
431
|
+
*
|
|
432
|
+
* @returns The specified environment if allowed.
|
|
433
|
+
*/
|
|
283
434
|
declare function parseEnv(data: unknown): Env;
|
|
284
435
|
//#endregion
|
|
285
436
|
//#region src/functions/parsers/parseFormData.d.ts
|
|
286
|
-
|
|
437
|
+
/**
|
|
438
|
+
* Returns a parsed object given FormData and a data parser function to call on the resulting object.
|
|
439
|
+
*
|
|
440
|
+
* @template DataType - The type of the resulting object when called from the dataParser.
|
|
441
|
+
*
|
|
442
|
+
* @param formData - The FormData to parse.
|
|
443
|
+
* @param dataParser - A parser to call on the object before it gets returned.
|
|
444
|
+
*
|
|
445
|
+
* @returns A parsed object based on the contents of the input formData and the result of parsing with the data parser.
|
|
446
|
+
*/
|
|
447
|
+
declare function parseFormData<DataType>(formData: FormData, dataParser: (data: Record<string, string | Blob>) => DataType): DataType;
|
|
448
|
+
/**
|
|
449
|
+
* Returns an object given FormData.
|
|
450
|
+
*
|
|
451
|
+
* @param formData - The FormData to parse.
|
|
452
|
+
*
|
|
453
|
+
* @returns An object based on the contents of the input formData.
|
|
454
|
+
*/
|
|
287
455
|
declare function parseFormData(formData: FormData): Record<string, string | Blob>;
|
|
288
456
|
//#endregion
|
|
289
457
|
//#region src/functions/parsers/parseIntStrict.d.ts
|
|
290
|
-
|
|
458
|
+
/**
|
|
459
|
+
* Converts a string to an integer and throws an error if it cannot be converted.
|
|
460
|
+
*
|
|
461
|
+
* @param string — A string to convert into a number.
|
|
462
|
+
* @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.
|
|
463
|
+
*
|
|
464
|
+
* @throws {TypeError} If the provided string cannot safely be converted to an integer.
|
|
465
|
+
*
|
|
466
|
+
* @returns The integer parsed from the input string.
|
|
467
|
+
*/
|
|
468
|
+
declare function parseIntStrict(string: string, radix?: number): number;
|
|
291
469
|
//#endregion
|
|
292
470
|
//#region src/functions/parsers/parseZodSchema.d.ts
|
|
471
|
+
/**
|
|
472
|
+
* An alternative function to zodSchema.parse() that can be used to strictly parse Zod schemas.
|
|
473
|
+
*
|
|
474
|
+
* @template Output - The Zod output type.
|
|
475
|
+
* @template Input - The Zod input type.
|
|
476
|
+
* @template Internals - The Zod internal types based on the output and input types.
|
|
477
|
+
*
|
|
478
|
+
* @param schema - The Zod schema to use in parsing.
|
|
479
|
+
* @param data - The data to parse.
|
|
480
|
+
*
|
|
481
|
+
* @throws {DataError} If the given data cannot be parsed according to the schema.
|
|
482
|
+
*
|
|
483
|
+
* @returns The parsed data from the Zod schema.
|
|
484
|
+
*/
|
|
293
485
|
declare function parseZodSchema<Output, Input, Internals extends core.$ZodTypeInternals<Output, Input>>(schema: ZodType<Output, Input, Internals>, data: unknown): core.output<ZodType<Output, Input, Internals>>;
|
|
294
486
|
//#endregion
|
|
295
|
-
//#region src/functions/
|
|
296
|
-
|
|
487
|
+
//#region src/functions/recursive/deepCopy.d.ts
|
|
488
|
+
/**
|
|
489
|
+
* Deeply copies an object or array such that all child objects/arrays are also copied.
|
|
490
|
+
*
|
|
491
|
+
* @template ObjectType - The type of the input object.
|
|
492
|
+
*
|
|
493
|
+
* @param object - The object to copy. May also be an array.
|
|
494
|
+
*
|
|
495
|
+
* @returns An identical object with a new reference in memory.
|
|
496
|
+
*/
|
|
497
|
+
declare function deepCopy<ObjectType extends object>(object: ObjectType): ObjectType;
|
|
297
498
|
//#endregion
|
|
298
|
-
//#region src/functions/
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
499
|
+
//#region src/functions/recursive/deepFreeze.d.ts
|
|
500
|
+
/**
|
|
501
|
+
* Deeply freezes an object or array such that all child objects/arrays are also frozen.
|
|
502
|
+
*
|
|
503
|
+
* Note that this will also freeze the input itself as well.
|
|
504
|
+
* 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.
|
|
505
|
+
*
|
|
506
|
+
* @template ObjectType - The type of the input object.
|
|
507
|
+
*
|
|
508
|
+
* @param object - The object to freeze. May also be an array.
|
|
509
|
+
*
|
|
510
|
+
* @returns The input object completely frozen.
|
|
511
|
+
*/
|
|
512
|
+
declare function deepFreeze<ObjectType extends object>(object: ObjectType): Readonly<ObjectType>;
|
|
513
|
+
//#endregion
|
|
514
|
+
//#region src/functions/stringHelpers/appendSemicolon.d.ts
|
|
515
|
+
/**
|
|
516
|
+
* Appends a semicolon to the end of a string, trimming where necessary first.
|
|
517
|
+
*
|
|
518
|
+
* @param stringToAppendTo - The string to append a semicolon to.
|
|
519
|
+
*
|
|
520
|
+
* @throws {Error} If the string contains multiple lines.
|
|
521
|
+
*
|
|
522
|
+
* @returns A string with the semicolon appended.
|
|
523
|
+
*/
|
|
524
|
+
declare function appendSemicolon(stringToAppendTo: string): string;
|
|
525
|
+
//#endregion
|
|
526
|
+
//#region src/functions/stringHelpers/camelToKebab.d.ts
|
|
527
|
+
/**
|
|
528
|
+
* Converts a string from camelCase to kebab-case
|
|
529
|
+
*
|
|
530
|
+
* @param string - The string to convert.
|
|
531
|
+
*
|
|
532
|
+
* @returns The string converted to kebab-case.
|
|
533
|
+
*/
|
|
534
|
+
declare function camelToKebab(string: string): string;
|
|
535
|
+
//#endregion
|
|
536
|
+
//#region src/functions/stringHelpers/kebabToCamel.d.ts
|
|
537
|
+
interface KebabToCamelOptions {
|
|
538
|
+
/** Whether or not the converted string should start with an uppercase (e.g. CamelCase instead of camelCase). */
|
|
539
|
+
startWithUpper?: boolean;
|
|
302
540
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
541
|
+
/**
|
|
542
|
+
* Converts a string from kebab-case to camelCase
|
|
543
|
+
*
|
|
544
|
+
* @param string - The string to convert.
|
|
545
|
+
* @param options - Options to apply to the conversion.
|
|
546
|
+
*
|
|
547
|
+
* @returns The string converted to camelCase.
|
|
548
|
+
*/
|
|
549
|
+
declare function kebabToCamel(string: string, options?: KebabToCamelOptions): string;
|
|
550
|
+
//#endregion
|
|
551
|
+
//#region src/functions/stringHelpers/normalizeImportPath.d.ts
|
|
552
|
+
/**
|
|
553
|
+
* Normalizes an import path meant for use in an import statement in JavaScript.
|
|
554
|
+
*
|
|
555
|
+
* 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.
|
|
556
|
+
*
|
|
557
|
+
* If the path starts with ./, it is preserved (unlike what would happen with path.posix.normalize() normally).
|
|
558
|
+
*
|
|
559
|
+
* Helpful for custom linter rules that need to check (or fix) import paths.
|
|
560
|
+
*
|
|
561
|
+
* @param importPath - The import path to normalize.
|
|
562
|
+
*
|
|
563
|
+
* @returns The import path normalized.
|
|
564
|
+
*/
|
|
565
|
+
declare function normalizeImportPath(importPath: string): string;
|
|
566
|
+
/**
|
|
567
|
+
* Normalises an import path meant for use in an import statement in JavaScript.
|
|
568
|
+
*
|
|
569
|
+
* 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.
|
|
570
|
+
*
|
|
571
|
+
* If the path starts with ./, it is preserved (unlike what would happen with path.posix.normalize() normally).
|
|
572
|
+
*
|
|
573
|
+
* Helpful for custom linter rules that need to check (or fix) import paths.
|
|
574
|
+
*
|
|
575
|
+
* @param importPath - The import path to normalise.
|
|
576
|
+
*
|
|
577
|
+
* @returns The import path normalised.
|
|
578
|
+
*/
|
|
579
|
+
declare const normaliseImportPath: typeof normalizeImportPath;
|
|
580
|
+
//#endregion
|
|
581
|
+
//#region src/functions/stringHelpers/truncate.d.ts
|
|
582
|
+
/**
|
|
583
|
+
* Truncates a string and appends `...` to the end of it
|
|
584
|
+
*
|
|
585
|
+
* @param stringToTruncate - The string to truncate.
|
|
586
|
+
* @param maxLength - The length at which to start truncating. Note that this does not include the `...` part that would be appended.
|
|
587
|
+
*
|
|
588
|
+
* @returns A new string that has been truncated based on the length provided.
|
|
589
|
+
*/
|
|
590
|
+
declare function truncate(stringToTruncate: string, maxLength?: number): string;
|
|
591
|
+
//#endregion
|
|
592
|
+
//#region src/functions/taggedTemplate/createTemplateStringsArray.d.ts
|
|
593
|
+
/**
|
|
594
|
+
* Creates a template strings array given a regular array of strings
|
|
595
|
+
*
|
|
596
|
+
* @param strings - The array of strings.
|
|
597
|
+
*
|
|
598
|
+
* @returns A template strings array that can be passed as the first argument of any tagged template function.
|
|
599
|
+
*/
|
|
600
|
+
declare function createTemplateStringsArray(strings: readonly string[]): TemplateStringsArray;
|
|
307
601
|
//#endregion
|
|
308
602
|
//#region src/functions/taggedTemplate/interpolate.d.ts
|
|
603
|
+
/**
|
|
604
|
+
* Returns the result of interpolating a template string when given the strings and interpolations separately.
|
|
605
|
+
*
|
|
606
|
+
* You can pass a template string directly by doing:
|
|
607
|
+
*
|
|
608
|
+
* interpolate`Template string here`.
|
|
609
|
+
*
|
|
610
|
+
* In this case, it will be functionally the same as if you just wrote the template string by itself.
|
|
611
|
+
*
|
|
612
|
+
* @param strings - The strings from the template to process.
|
|
613
|
+
* @param interpolations - An array of all interpolations from the template.
|
|
614
|
+
*
|
|
615
|
+
* @returns A new string with the strings and interpolations from the template applied.
|
|
616
|
+
*/
|
|
309
617
|
declare function interpolate(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
|
|
310
618
|
//#endregion
|
|
311
619
|
//#region src/functions/taggedTemplate/interpolateObjects.d.ts
|
|
312
|
-
|
|
620
|
+
/**
|
|
621
|
+
* Returns the result of interpolating a template string, also stringifying objects.
|
|
622
|
+
*
|
|
623
|
+
* You can pass a template string directly by doing:
|
|
624
|
+
*
|
|
625
|
+
* interpolateObjects`Template string here ${{ my: "object" }}`.
|
|
626
|
+
*
|
|
627
|
+
* @param strings - The strings from the template to process.
|
|
628
|
+
* @param interpolations - An array of all interpolations from the template.
|
|
629
|
+
*
|
|
630
|
+
* @returns A new string with the strings and interpolations from the template applied, with objects stringified.
|
|
631
|
+
*/
|
|
632
|
+
declare function interpolateObjects(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
|
|
313
633
|
//#endregion
|
|
314
634
|
//#region src/functions/taggedTemplate/normaliseIndents.d.ts
|
|
315
635
|
interface NormaliseIndentsOptions {
|
|
636
|
+
/** Whether to preserve extra tabs or not (defaults to true) */
|
|
316
637
|
preserveTabs?: boolean;
|
|
317
638
|
}
|
|
318
639
|
type NormalizeIndentsOptions = NormaliseIndentsOptions;
|
|
319
640
|
type NormaliseIndentsFunction = (strings: TemplateStringsArray, ...interpolations: unknown[]) => string;
|
|
320
641
|
type NormalizeIndentsFunction = NormaliseIndentsFunction;
|
|
642
|
+
/**
|
|
643
|
+
* Provides a new function that removes any extraneous indents from a multi-line template string, with the given options applied.
|
|
644
|
+
*
|
|
645
|
+
* @param options - The options to apply.
|
|
646
|
+
*
|
|
647
|
+
* @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.
|
|
648
|
+
*/
|
|
321
649
|
declare function normaliseIndents(options: NormaliseIndentsOptions): NormaliseIndentsFunction;
|
|
650
|
+
/**
|
|
651
|
+
* Removes any extraneous indents from a multi-line template string.
|
|
652
|
+
*
|
|
653
|
+
* You can pass a template string directly by doing:
|
|
654
|
+
*
|
|
655
|
+
* normaliseIndents`Template string here
|
|
656
|
+
* with a new line
|
|
657
|
+
* and another new line`.
|
|
658
|
+
*
|
|
659
|
+
* @param strings - The strings from the template to process.
|
|
660
|
+
* @param interpolations - An array of all interpolations from the template.
|
|
661
|
+
*
|
|
662
|
+
* @returns A new string with the strings and interpolations from the template applied, and extraneous indents removed.
|
|
663
|
+
*/
|
|
322
664
|
declare function normaliseIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
|
|
665
|
+
/**
|
|
666
|
+
* Applies any options if provided, then removes any extraneous indents from a multi-line template string.
|
|
667
|
+
*
|
|
668
|
+
* You can pass a template string directly by doing:
|
|
669
|
+
*
|
|
670
|
+
* normalizeIndents`Template string here
|
|
671
|
+
* with a new line
|
|
672
|
+
* and another new line`.
|
|
673
|
+
*
|
|
674
|
+
* You may also pass the options first, then invoke the resulting function with a template string:
|
|
675
|
+
*
|
|
676
|
+
* normalizeIndents({ preserveTabs: false })`Template string here
|
|
677
|
+
* with a new line
|
|
678
|
+
* and another new line`.
|
|
679
|
+
*
|
|
680
|
+
* @param first - The strings from the template to process, or the options to apply.
|
|
681
|
+
* @param args - An array of all interpolations from the template.
|
|
682
|
+
*
|
|
683
|
+
* @returns An additional function to invoke, or a new string with the strings and interpolations from the template applied, and extraneous indents removed.
|
|
684
|
+
*/
|
|
323
685
|
declare const normalizeIndents: typeof normaliseIndents;
|
|
324
686
|
//#endregion
|
|
325
687
|
//#region src/functions/taggedTemplate/removeIndents.d.ts
|
|
@@ -339,10 +701,43 @@ declare function removeIndents(options: RemoveIndentsOptions): RemoveIndentsFunc
|
|
|
339
701
|
*/
|
|
340
702
|
declare function removeIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
|
|
341
703
|
//#endregion
|
|
342
|
-
//#region src/functions/
|
|
343
|
-
|
|
704
|
+
//#region src/functions/versioning/determineVersionType.d.ts
|
|
705
|
+
type VersionType = "major" | "minor" | "patch";
|
|
706
|
+
/**
|
|
707
|
+
* Determines whether the given version is a major, minor, or patch version.
|
|
708
|
+
*
|
|
709
|
+
* @param version - The version number.
|
|
710
|
+
*
|
|
711
|
+
* @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
|
|
712
|
+
*/
|
|
713
|
+
declare function determineVersionType(version: string): VersionType;
|
|
344
714
|
//#endregion
|
|
345
|
-
//#region src/functions/
|
|
346
|
-
|
|
715
|
+
//#region src/functions/versioning/getIndividualVersionNumbers.d.ts
|
|
716
|
+
/**
|
|
717
|
+
* Gets the individual version numbers from a given version number as a tuple of numbers.
|
|
718
|
+
*
|
|
719
|
+
* @param version - The version number.
|
|
720
|
+
*
|
|
721
|
+
* @returns A tuple of three numbers indicating `[major, minor, patch]`.
|
|
722
|
+
*/
|
|
723
|
+
declare function getIndividualVersionNumbers(version: string): [number, number, number];
|
|
724
|
+
//#endregion
|
|
725
|
+
//#region src/functions/versioning/parseVersion.d.ts
|
|
726
|
+
interface ParseVersionOptions {
|
|
727
|
+
omitPrefix?: boolean;
|
|
728
|
+
}
|
|
729
|
+
/**
|
|
730
|
+
* Parses a string and verifies it is a valid package version number.
|
|
731
|
+
*
|
|
732
|
+
* Valid formats: `X.Y.Z` or `vX.Y.Z`, where X, Y, and Z are non-negative integers.
|
|
733
|
+
*
|
|
734
|
+
* @param input - The version string to parse.
|
|
735
|
+
* @param options - Extra options to apply.
|
|
736
|
+
*
|
|
737
|
+
* @throws {DataError} If the input is not a valid version number.
|
|
738
|
+
*
|
|
739
|
+
* @returns The validated version number, prefixed with `v` if it was not already.
|
|
740
|
+
*/
|
|
741
|
+
declare function parseVersion(input: string, options?: ParseVersionOptions): string;
|
|
347
742
|
//#endregion
|
|
348
|
-
export { APIError, ArrayElement, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DeepReadonly, DisallowUndefined, Email, Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, RecordKey, RemoveIndentsFunction, RemoveIndentsOptions, StringListToArrayOptions, UUID, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEmail, parseEnv, parseFormData, parseIntStrict, parseUUID, parseZodSchema, randomiseArray, range, removeDuplicates, removeIndents, stringListToArray, stringToBoolean, truncate, wait };
|
|
743
|
+
export { APIError, ArrayElement, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DeepReadonly, DisallowUndefined, Email, Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, RecordKey, RemoveIndentsFunction, RemoveIndentsOptions, StringListToArrayOptions, UUID, VERSION_NUMBER_REGEX, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, fillArray, formatDateAndTime, getIndividualVersionNumbers, getRandomNumber, getRecordKeys, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEmail, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersion, parseZodSchema, randomiseArray, range, removeDuplicates, removeIndents, stringListToArray, stringToBoolean, truncate, wait };
|