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