@alextheman/utility 3.5.10 → 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 +526 -219
- package/dist/index.d.cts +477 -120
- package/dist/index.d.ts +478 -121
- package/dist/index.js +526 -219
- 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[];
|
|
89
95
|
//#endregion
|
|
90
|
-
//#region src/functions/
|
|
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;
|
|
165
|
+
//#endregion
|
|
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,212 +209,476 @@ 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
|
|
116
222
|
//#region src/types/Email.d.ts
|
|
117
223
|
declare const emailSchema: z.core.$ZodBranded<z.ZodEmail, "Email">;
|
|
224
|
+
/** @deprecated Please use the inferred type from `z.email() from Zod instead.` */
|
|
118
225
|
type Email = z.infer<typeof emailSchema>;
|
|
226
|
+
/** @deprecated Please use `z.email().parse() from Zod instead.`*/
|
|
119
227
|
declare function parseEmail(data: unknown): Email;
|
|
120
228
|
//#endregion
|
|
121
|
-
//#region src/types/Env.d.ts
|
|
122
|
-
declare const envSchema: z$1.ZodEnum<{
|
|
123
|
-
test: "test";
|
|
124
|
-
development: "development";
|
|
125
|
-
production: "production";
|
|
126
|
-
}>;
|
|
127
|
-
type Env = z$1.infer<typeof envSchema>;
|
|
128
|
-
declare function parseEnv(data?: unknown): Env;
|
|
129
|
-
//#endregion
|
|
130
229
|
//#region src/types/UUID.d.ts
|
|
131
230
|
declare const uuidSchema: z.core.$ZodBranded<z.ZodUUID, "UUID">;
|
|
231
|
+
/** @deprecated Please use the inferred type from `z.uuid() from Zod instead.` */
|
|
132
232
|
type UUID = z.infer<typeof uuidSchema>;
|
|
233
|
+
/** @deprecated Please use `z.uuid().parse() from Zod instead.`*/
|
|
133
234
|
declare function parseUUID(UUID: unknown): UUID;
|
|
134
235
|
//#endregion
|
|
135
236
|
//#region src/types/ArrayElement.d.ts
|
|
136
|
-
|
|
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;
|
|
137
243
|
//#endregion
|
|
138
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. */
|
|
139
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;
|
|
140
247
|
//#endregion
|
|
141
248
|
//#region src/types/DisallowUndefined.d.ts
|
|
142
|
-
|
|
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;
|
|
143
255
|
//#endregion
|
|
144
256
|
//#region src/types/IgnoreCase.d.ts
|
|
145
|
-
|
|
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>}` : "";
|
|
146
263
|
//#endregion
|
|
147
264
|
//#region src/types/NonUndefined.d.ts
|
|
148
|
-
|
|
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;
|
|
149
271
|
//#endregion
|
|
150
272
|
//#region src/types/OptionalOnCondition.d.ts
|
|
151
|
-
|
|
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;
|
|
152
280
|
//#endregion
|
|
153
281
|
//#region src/types/RecordKey.d.ts
|
|
282
|
+
/** Represents the native Record's possible key type. */
|
|
154
283
|
type RecordKey = string | number | symbol;
|
|
155
284
|
//#endregion
|
|
156
|
-
//#region src/functions/createFormData.d.ts
|
|
285
|
+
//#region src/functions/miscellaneous/createFormData.d.ts
|
|
157
286
|
type FormDataNullableResolutionStrategy = "stringify" | "empty" | "omit";
|
|
158
287
|
type FormDataArrayResolutionStrategy = "stringify" | "multiple";
|
|
159
|
-
interface CreateFormDataOptionsBase<
|
|
160
|
-
|
|
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>>;
|
|
161
291
|
}
|
|
162
|
-
interface CreateFormDataOptionsUndefinedOrNullResolution<
|
|
163
|
-
|
|
164
|
-
|
|
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. */
|
|
165
298
|
nullableResolution?: never;
|
|
166
299
|
}
|
|
167
|
-
interface CreateFormDataOptionsNullableResolution<
|
|
300
|
+
interface CreateFormDataOptionsNullableResolution<Key extends RecordKey> extends CreateFormDataOptionsBase<Key> {
|
|
301
|
+
/** @note This must not be provided at the same time as nullableResolution. */
|
|
168
302
|
undefinedResolution?: never;
|
|
303
|
+
/** @note This must not be provided at the same time as nullableResolution. */
|
|
169
304
|
nullResolution?: never;
|
|
170
|
-
|
|
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>>;
|
|
171
307
|
}
|
|
172
|
-
type CreateFormDataOptions<
|
|
173
|
-
|
|
308
|
+
type CreateFormDataOptions<Key extends RecordKey> = CreateFormDataOptionsUndefinedOrNullResolution<Key> | CreateFormDataOptionsNullableResolution<Key>;
|
|
309
|
+
/**
|
|
310
|
+
* Creates FormData from a given object, resolving non-string types as appropriate.
|
|
311
|
+
*
|
|
312
|
+
* @template DataType - The type of the given data.
|
|
313
|
+
*
|
|
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.
|
|
318
|
+
*/
|
|
319
|
+
declare function createFormData<DataType extends Record<RecordKey, unknown>>(data: DataType, options?: CreateFormDataOptions<keyof DataType>): FormData;
|
|
174
320
|
//#endregion
|
|
175
|
-
//#region src/functions/
|
|
176
|
-
|
|
321
|
+
//#region src/functions/miscellaneous/getRandomNumber.d.ts
|
|
322
|
+
/**
|
|
323
|
+
* Gets a random number between the given bounds.
|
|
324
|
+
*
|
|
325
|
+
* @param lowerBound - The lowest number that can be chosen.
|
|
326
|
+
* @param upperBound - The highest number that can be chosen.
|
|
327
|
+
*
|
|
328
|
+
* @returns A random number between the provided lower bound and upper bound.
|
|
329
|
+
*/
|
|
330
|
+
declare function getRandomNumber(lowerBound: number, upperBound: number): number;
|
|
177
331
|
//#endregion
|
|
178
|
-
//#region src/functions/
|
|
332
|
+
//#region src/functions/miscellaneous/isOrdered.d.ts
|
|
179
333
|
/**
|
|
180
|
-
*
|
|
334
|
+
* Checks to see if the given array is sorted in ascending order.
|
|
181
335
|
*
|
|
182
|
-
* @param
|
|
183
|
-
* @param dayIncrement - The amount of days you want to add (defaults to 1)
|
|
336
|
+
* @param array - The array to check.
|
|
184
337
|
*
|
|
185
|
-
* @returns
|
|
338
|
+
* @returns `true` if the array is sorted in ascending order, and `false` otherwise.
|
|
186
339
|
*/
|
|
187
|
-
declare function
|
|
340
|
+
declare function isOrdered(array: readonly number[]): boolean;
|
|
188
341
|
//#endregion
|
|
189
|
-
//#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
|
+
}
|
|
190
349
|
/**
|
|
191
|
-
*
|
|
350
|
+
* Converts a stringly-typed list to a proper array.
|
|
192
351
|
*
|
|
193
|
-
* @param
|
|
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.
|
|
194
356
|
*
|
|
195
|
-
* @returns A new
|
|
357
|
+
* @returns A new array with each item being an item from the given list.
|
|
358
|
+
*/
|
|
359
|
+
declare function stringListToArray(stringList: string, {
|
|
360
|
+
separator,
|
|
361
|
+
trimWhitespace
|
|
362
|
+
}?: StringListToArrayOptions): string[];
|
|
363
|
+
//#endregion
|
|
364
|
+
//#region src/functions/miscellaneous/wait.d.ts
|
|
365
|
+
/**
|
|
366
|
+
* Waits for the given number of seconds
|
|
196
367
|
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
368
|
+
* @param seconds - The number of seconds to wait.
|
|
369
|
+
*
|
|
370
|
+
* @returns A Promise that resolves after the given number of seconds.
|
|
200
371
|
*/
|
|
201
|
-
declare function
|
|
372
|
+
declare function wait(seconds: number): Promise<void>;
|
|
202
373
|
//#endregion
|
|
203
|
-
//#region src/functions/
|
|
374
|
+
//#region src/functions/objectHelpers/getRecordKeys.d.ts
|
|
204
375
|
/**
|
|
205
|
-
*
|
|
376
|
+
* Gets the keys from a given record object, properly typed to be an array of the key of the input object's type.
|
|
206
377
|
*
|
|
207
|
-
* @
|
|
208
|
-
* @param secondDate - The second date to compare.
|
|
378
|
+
* @template InputRecordType - The type of the input object.
|
|
209
379
|
*
|
|
210
|
-
* @
|
|
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`.
|
|
211
383
|
*/
|
|
212
|
-
declare function
|
|
384
|
+
declare function getRecordKeys<InputRecordType extends Record<RecordKey, unknown>>(record: InputRecordType & object): (keyof InputRecordType)[];
|
|
213
385
|
//#endregion
|
|
214
|
-
//#region src/functions/
|
|
386
|
+
//#region src/functions/objectHelpers/omitProperties.d.ts
|
|
215
387
|
/**
|
|
216
|
-
*
|
|
388
|
+
* Omits properties from a given object.
|
|
217
389
|
*
|
|
218
|
-
* @
|
|
390
|
+
* @template ObjectType - The type of the input object.
|
|
391
|
+
* @template KeysToOmit - A type representing the keys to omit from the object.
|
|
219
392
|
*
|
|
220
|
-
* @
|
|
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.
|
|
221
395
|
*
|
|
222
|
-
* @returns
|
|
396
|
+
* @returns An object with a new reference in memory, with the properties omitted.
|
|
223
397
|
*/
|
|
224
|
-
declare function
|
|
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>;
|
|
225
399
|
//#endregion
|
|
226
|
-
//#region src/functions/
|
|
400
|
+
//#region src/functions/parsers/parseBoolean.d.ts
|
|
227
401
|
/**
|
|
228
|
-
*
|
|
402
|
+
* Takes a stringly-typed boolean and converts it to an actual boolean type.
|
|
229
403
|
*
|
|
230
|
-
* @param
|
|
231
|
-
* @param secondDate - The second date to compare.
|
|
404
|
+
* @param inputString - The string to parse.
|
|
232
405
|
*
|
|
233
|
-
* @
|
|
406
|
+
* @throws {TypeError} If the string is not either `true` or `false` (case insensitive).
|
|
407
|
+
*
|
|
408
|
+
* @returns The string parsed as an actual boolean.
|
|
234
409
|
*/
|
|
235
|
-
declare function
|
|
410
|
+
declare function parseBoolean(inputString: string): boolean;
|
|
411
|
+
/** @deprecated This function has been renamed to parseBoolean. */
|
|
412
|
+
declare const stringToBoolean: typeof parseBoolean;
|
|
236
413
|
//#endregion
|
|
237
|
-
//#region src/functions/
|
|
414
|
+
//#region src/functions/parsers/parseEnv.d.ts
|
|
415
|
+
declare const envSchema: z$1.ZodEnum<{
|
|
416
|
+
test: "test";
|
|
417
|
+
development: "development";
|
|
418
|
+
production: "production";
|
|
419
|
+
}>;
|
|
420
|
+
/** Represents the most common development environments */
|
|
421
|
+
type Env = z$1.infer<typeof envSchema>;
|
|
238
422
|
/**
|
|
239
|
-
*
|
|
423
|
+
* Parses the input and verifies it matches one of the environments allowed by the Env types ("test" | "development" | "production").
|
|
240
424
|
*
|
|
241
|
-
* @param
|
|
242
|
-
* @param secondDate - The second date to compare.
|
|
425
|
+
* @param data - The data to parse.
|
|
243
426
|
*
|
|
244
|
-
* @
|
|
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.
|
|
245
430
|
*/
|
|
246
|
-
declare function
|
|
431
|
+
declare function parseEnv(data: unknown): Env;
|
|
247
432
|
//#endregion
|
|
248
|
-
//#region src/functions/
|
|
249
|
-
|
|
433
|
+
//#region src/functions/parsers/parseFormData.d.ts
|
|
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
|
+
*/
|
|
452
|
+
declare function parseFormData(formData: FormData): Record<string, string | Blob>;
|
|
250
453
|
//#endregion
|
|
251
|
-
//#region src/functions/
|
|
252
|
-
|
|
454
|
+
//#region src/functions/parsers/parseIntStrict.d.ts
|
|
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;
|
|
253
466
|
//#endregion
|
|
254
|
-
//#region src/functions/
|
|
255
|
-
|
|
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
|
+
*/
|
|
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>>;
|
|
483
|
+
//#endregion
|
|
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;
|
|
495
|
+
//#endregion
|
|
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>;
|
|
256
510
|
//#endregion
|
|
257
|
-
//#region src/functions/
|
|
258
|
-
|
|
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;
|
|
259
522
|
//#endregion
|
|
260
|
-
//#region src/functions/
|
|
261
|
-
|
|
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;
|
|
262
532
|
//#endregion
|
|
263
|
-
//#region src/functions/kebabToCamel.d.ts
|
|
533
|
+
//#region src/functions/stringHelpers/kebabToCamel.d.ts
|
|
264
534
|
interface KebabToCamelOptions {
|
|
535
|
+
/** Whether or not the converted string should start with an uppercase (e.g. CamelCase instead of camelCase). */
|
|
265
536
|
startWithUpper?: boolean;
|
|
266
537
|
}
|
|
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
|
+
*/
|
|
267
546
|
declare function kebabToCamel(string: string, options?: KebabToCamelOptions): string;
|
|
268
547
|
//#endregion
|
|
269
|
-
//#region src/functions/normalizeImportPath.d.ts
|
|
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
|
+
*/
|
|
270
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
|
+
*/
|
|
271
576
|
declare const normaliseImportPath: typeof normalizeImportPath;
|
|
272
577
|
//#endregion
|
|
273
|
-
//#region src/functions/
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
declare function
|
|
283
|
-
declare function parseFormData(formData: FormData): Record<string, string | Blob>;
|
|
284
|
-
//#endregion
|
|
285
|
-
//#region src/functions/parsers/parseIntStrict.d.ts
|
|
286
|
-
declare function parseIntStrict(...[string, radix]: Parameters<typeof parseInt>): number;
|
|
287
|
-
//#endregion
|
|
288
|
-
//#region src/functions/parsers/parseZodSchema.d.ts
|
|
289
|
-
declare function parseZodSchema<Output, Input, Internals extends core.$ZodTypeInternals<Output, Input>>(schema: ZodType<Output, Input, Internals>, data: unknown): core.output<ZodType<Output, Input, Internals>>;
|
|
290
|
-
//#endregion
|
|
291
|
-
//#region src/functions/removeDuplicates.d.ts
|
|
292
|
-
declare function removeDuplicates<T>(array: T[] | readonly T[]): T[];
|
|
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;
|
|
293
588
|
//#endregion
|
|
294
|
-
//#region src/functions/
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
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;
|
|
303
598
|
//#endregion
|
|
304
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
|
+
*/
|
|
305
614
|
declare function interpolate(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
|
|
306
615
|
//#endregion
|
|
307
616
|
//#region src/functions/taggedTemplate/interpolateObjects.d.ts
|
|
308
|
-
|
|
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;
|
|
309
630
|
//#endregion
|
|
310
631
|
//#region src/functions/taggedTemplate/normaliseIndents.d.ts
|
|
311
632
|
interface NormaliseIndentsOptions {
|
|
633
|
+
/** Whether to preserve extra tabs or not (defaults to true) */
|
|
312
634
|
preserveTabs?: boolean;
|
|
313
635
|
}
|
|
314
636
|
type NormalizeIndentsOptions = NormaliseIndentsOptions;
|
|
315
637
|
type NormaliseIndentsFunction = (strings: TemplateStringsArray, ...interpolations: unknown[]) => string;
|
|
316
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
|
+
*/
|
|
317
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
|
+
*/
|
|
318
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
|
+
*/
|
|
319
682
|
declare const normalizeIndents: typeof normaliseIndents;
|
|
320
683
|
//#endregion
|
|
321
684
|
//#region src/functions/taggedTemplate/removeIndents.d.ts
|
|
@@ -335,10 +698,4 @@ declare function removeIndents(options: RemoveIndentsOptions): RemoveIndentsFunc
|
|
|
335
698
|
*/
|
|
336
699
|
declare function removeIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
|
|
337
700
|
//#endregion
|
|
338
|
-
//#region src/functions/truncate.d.ts
|
|
339
|
-
declare function truncate(stringToTruncate: string, maxLength?: number): string;
|
|
340
|
-
//#endregion
|
|
341
|
-
//#region src/functions/wait.d.ts
|
|
342
|
-
declare function wait(seconds: number): Promise<void>;
|
|
343
|
-
//#endregion
|
|
344
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 };
|