@alextheman/utility 4.3.1 → 4.3.2
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/README.md +17 -0
- package/dist/index.cjs +48 -33
- package/dist/index.d.cts +113 -51
- package/dist/index.d.ts +113 -51
- package/dist/index.js +48 -34
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @alextheman/utility
|
|
2
2
|
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
[](https://github.com/AlexMan123456/utility/actions/workflows/ci.yml)
|
|
8
|
+
[](https://github.com/AlexMan123456/utility/actions/workflows/npm-publish.yml)
|
|
9
|
+
[](https://github.com/AlexMan123456/utility/actions/workflows/netlify-docs-publish.yml)
|
|
10
|
+
|
|
11
|
+
[](https://app.netlify.com/projects/alextheman-utility-docs/deploys)
|
|
12
|
+
|
|
13
|
+
|
|
3
14
|
This is my personal utility package. It provides custom utility functions that can be used in more or less any TypeScript or JavaScript project, using either the browser or Node environment.
|
|
4
15
|
|
|
5
16
|
## Installation
|
|
@@ -24,3 +35,9 @@ import { formatDateAndTime } from "@alextheman/utility";
|
|
|
24
35
|
const myVariable: NonUndefined<string> = formatDateAndTime(new Date());
|
|
25
36
|
// ...
|
|
26
37
|
```
|
|
38
|
+
|
|
39
|
+
## Documentation
|
|
40
|
+
|
|
41
|
+
You can find the relevant documentation of all features of the package in the [docs/features/markdown](https://github.com/AlexMan123456/utility/tree/main/docs/features/markdown) directory of the repository. The hosted documentation site can be found [here](https://alextheman-utility-docs.netlify.app/).
|
|
42
|
+
|
|
43
|
+
See the GitHub repository [here](https://github.com/AlexMan123456/utility).
|
package/dist/index.cjs
CHANGED
|
@@ -175,19 +175,6 @@ var DataError = class extends Error {
|
|
|
175
175
|
};
|
|
176
176
|
var DataError_default = DataError;
|
|
177
177
|
|
|
178
|
-
//#endregion
|
|
179
|
-
//#region src/types/VersionType.ts
|
|
180
|
-
/**
|
|
181
|
-
* Represents the three common software version types.
|
|
182
|
-
*
|
|
183
|
-
* @category Types
|
|
184
|
-
*/
|
|
185
|
-
const VersionType = {
|
|
186
|
-
MAJOR: "major",
|
|
187
|
-
MINOR: "minor",
|
|
188
|
-
PATCH: "patch"
|
|
189
|
-
};
|
|
190
|
-
|
|
191
178
|
//#endregion
|
|
192
179
|
//#region src/types/VersionNumber.ts
|
|
193
180
|
/**
|
|
@@ -834,11 +821,16 @@ var parseZodSchema_default = parseZodSchema;
|
|
|
834
821
|
|
|
835
822
|
//#endregion
|
|
836
823
|
//#region src/functions/parsers/parseEnv.ts
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
824
|
+
/**
|
|
825
|
+
* Represents the three common development environments.
|
|
826
|
+
*
|
|
827
|
+
* @category Types
|
|
828
|
+
*/
|
|
829
|
+
const Env = {
|
|
830
|
+
TEST: "test",
|
|
831
|
+
DEVELOPMENT: "development",
|
|
832
|
+
PRODUCTION: "production"
|
|
833
|
+
};
|
|
842
834
|
/**
|
|
843
835
|
* Parses the input and verifies it matches one of the environments allowed by the Env types ("test" | "development" | "production").
|
|
844
836
|
*
|
|
@@ -851,7 +843,7 @@ const envSchema = zod.z.enum([
|
|
|
851
843
|
* @returns The specified environment if allowed.
|
|
852
844
|
*/
|
|
853
845
|
function parseEnv(data) {
|
|
854
|
-
return parseZodSchema_default(
|
|
846
|
+
return parseZodSchema_default(zod.z.enum(Env), data, new DataError_default(data, "INVALID_ENV", "The provided environment type must be one of `test | development | production`"));
|
|
855
847
|
}
|
|
856
848
|
var parseEnv_default = parseEnv;
|
|
857
849
|
|
|
@@ -882,6 +874,16 @@ var parseFormData_default = parseFormData;
|
|
|
882
874
|
//#endregion
|
|
883
875
|
//#region src/functions/parsers/parseVersionType.ts
|
|
884
876
|
/**
|
|
877
|
+
* Represents the three common software version types.
|
|
878
|
+
*
|
|
879
|
+
* @category Types
|
|
880
|
+
*/
|
|
881
|
+
const VersionType = {
|
|
882
|
+
MAJOR: "major",
|
|
883
|
+
MINOR: "minor",
|
|
884
|
+
PATCH: "patch"
|
|
885
|
+
};
|
|
886
|
+
/**
|
|
885
887
|
* Parses the input and verifies it is a valid software version type (i.e. `"major" | "minor" | "patch"`)
|
|
886
888
|
*
|
|
887
889
|
* @category Parsers
|
|
@@ -1130,7 +1132,9 @@ var createTemplateStringsArray_default = createTemplateStringsArray;
|
|
|
1130
1132
|
*
|
|
1131
1133
|
* You can pass a template string directly by doing:
|
|
1132
1134
|
*
|
|
1133
|
-
*
|
|
1135
|
+
* ```
|
|
1136
|
+
* interpolate`Template string here`.
|
|
1137
|
+
* ```
|
|
1134
1138
|
*
|
|
1135
1139
|
* In this case, it will be functionally the same as if you just wrote the template string by itself.
|
|
1136
1140
|
*
|
|
@@ -1155,7 +1159,9 @@ var interpolate_default = interpolate;
|
|
|
1155
1159
|
*
|
|
1156
1160
|
* You can pass a template string directly by doing:
|
|
1157
1161
|
*
|
|
1158
|
-
*
|
|
1162
|
+
* ```typescript
|
|
1163
|
+
* interpolateObjects`Template string here ${{ my: "object" }}`.
|
|
1164
|
+
* ```
|
|
1159
1165
|
*
|
|
1160
1166
|
* @category Tagged Template
|
|
1161
1167
|
*
|
|
@@ -1205,15 +1211,19 @@ function reduceLines(lines, { preserveTabs = true }) {
|
|
|
1205
1211
|
*
|
|
1206
1212
|
* You can pass a template string directly by doing:
|
|
1207
1213
|
*
|
|
1208
|
-
*
|
|
1209
|
-
*
|
|
1210
|
-
*
|
|
1214
|
+
* ```typescript
|
|
1215
|
+
* normaliseIndents`Template string here
|
|
1216
|
+
* with a new line
|
|
1217
|
+
* and another new line`.
|
|
1218
|
+
* ```
|
|
1211
1219
|
*
|
|
1212
1220
|
* You may also pass the options first, then invoke the resulting function with a template string:
|
|
1213
1221
|
*
|
|
1214
|
-
*
|
|
1215
|
-
*
|
|
1216
|
-
*
|
|
1222
|
+
* ```typescript
|
|
1223
|
+
* normaliseIndents({ preserveTabs: false })`Template string here
|
|
1224
|
+
* with a new line
|
|
1225
|
+
* and another new line`.
|
|
1226
|
+
* ```
|
|
1217
1227
|
*
|
|
1218
1228
|
*@category Tagged Template
|
|
1219
1229
|
*
|
|
@@ -1238,15 +1248,19 @@ function normaliseIndents(first, ...args) {
|
|
|
1238
1248
|
*
|
|
1239
1249
|
* You can pass a template string directly by doing:
|
|
1240
1250
|
*
|
|
1241
|
-
*
|
|
1242
|
-
*
|
|
1243
|
-
*
|
|
1251
|
+
* ```typescript
|
|
1252
|
+
* normalizeIndents`Template string here
|
|
1253
|
+
* with a new line
|
|
1254
|
+
* and another new line`.
|
|
1255
|
+
* ```
|
|
1244
1256
|
*
|
|
1245
1257
|
* You may also pass the options first, then invoke the resulting function with a template string:
|
|
1246
1258
|
*
|
|
1247
|
-
*
|
|
1248
|
-
*
|
|
1249
|
-
*
|
|
1259
|
+
* ```typescript
|
|
1260
|
+
* normalizeIndents({ preserveTabs: false })`Template string here
|
|
1261
|
+
* with a new line
|
|
1262
|
+
* and another new line`.
|
|
1263
|
+
* ```
|
|
1250
1264
|
*
|
|
1251
1265
|
* @param first - The strings from the template to process, or the options to apply.
|
|
1252
1266
|
* @param args - An array of all interpolations from the template.
|
|
@@ -1351,6 +1365,7 @@ var incrementVersion_default = incrementVersion;
|
|
|
1351
1365
|
//#endregion
|
|
1352
1366
|
exports.APIError = APIError_default;
|
|
1353
1367
|
exports.DataError = DataError_default;
|
|
1368
|
+
exports.Env = Env;
|
|
1354
1369
|
exports.NAMESPACE_EXPORT_REGEX = NAMESPACE_EXPORT_REGEX_default;
|
|
1355
1370
|
exports.VERSION_NUMBER_REGEX = VERSION_NUMBER_REGEX_default;
|
|
1356
1371
|
exports.VersionNumber = VersionNumber_default;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ZodType, core
|
|
1
|
+
import { ZodType, core } from "zod";
|
|
2
2
|
|
|
3
3
|
//#region src/constants/NAMESPACE_EXPORT_REGEX.d.ts
|
|
4
4
|
declare const NAMESPACE_EXPORT_REGEX = "export\\s+\\*\\s+from";
|
|
@@ -252,39 +252,14 @@ declare class DataError extends Error {
|
|
|
252
252
|
static check(input: unknown): input is DataError;
|
|
253
253
|
}
|
|
254
254
|
//#endregion
|
|
255
|
-
//#region src/types/
|
|
256
|
-
/**
|
|
257
|
-
* Represents the native Record's possible key type.
|
|
258
|
-
*
|
|
259
|
-
* @category Types
|
|
260
|
-
*/
|
|
261
|
-
type RecordKey = string | number | symbol;
|
|
262
|
-
//#endregion
|
|
263
|
-
//#region src/types/CreateEnumType.d.ts
|
|
264
|
-
/**
|
|
265
|
-
* Get the value types from a const object so the object can behave similarly to an enum.
|
|
266
|
-
*
|
|
267
|
-
* @category Types
|
|
268
|
-
*
|
|
269
|
-
* @template ObjectType - The type of the object to get the value types for.
|
|
270
|
-
*/
|
|
271
|
-
type CreateEnumType<ObjectType extends Record<RecordKey, unknown>> = ObjectType[keyof ObjectType];
|
|
272
|
-
//#endregion
|
|
273
|
-
//#region src/types/VersionType.d.ts
|
|
255
|
+
//#region src/types/VersionNumber.d.ts
|
|
274
256
|
/**
|
|
275
|
-
*
|
|
257
|
+
* Options to apply to the stringification of the version number.
|
|
276
258
|
*
|
|
277
|
-
* @category
|
|
259
|
+
* @category Class Options
|
|
278
260
|
*/
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
readonly MINOR: "minor";
|
|
282
|
-
readonly PATCH: "patch";
|
|
283
|
-
};
|
|
284
|
-
type VersionType = CreateEnumType<typeof VersionType>;
|
|
285
|
-
//#endregion
|
|
286
|
-
//#region src/types/VersionNumber.d.ts
|
|
287
|
-
interface ToStringOptions {
|
|
261
|
+
interface VersionNumberToStringOptions {
|
|
262
|
+
/** Whether you want to omit the "v" prefix or not (defaults to false). */
|
|
288
263
|
omitPrefix?: boolean;
|
|
289
264
|
}
|
|
290
265
|
/**
|
|
@@ -338,7 +313,7 @@ declare class VersionNumber {
|
|
|
338
313
|
*
|
|
339
314
|
* @returns A stringified representation of the current version number, leaving out the prefix if `omitPrefix` option was set to true.
|
|
340
315
|
*/
|
|
341
|
-
toString(options?:
|
|
316
|
+
toString(options?: VersionNumberToStringOptions): string;
|
|
342
317
|
}
|
|
343
318
|
//#endregion
|
|
344
319
|
//#region src/types/ArrayElement.d.ts
|
|
@@ -351,6 +326,24 @@ declare class VersionNumber {
|
|
|
351
326
|
*/
|
|
352
327
|
type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
|
|
353
328
|
//#endregion
|
|
329
|
+
//#region src/types/RecordKey.d.ts
|
|
330
|
+
/**
|
|
331
|
+
* Represents the native Record's possible key type.
|
|
332
|
+
*
|
|
333
|
+
* @category Types
|
|
334
|
+
*/
|
|
335
|
+
type RecordKey = string | number | symbol;
|
|
336
|
+
//#endregion
|
|
337
|
+
//#region src/types/CreateEnumType.d.ts
|
|
338
|
+
/**
|
|
339
|
+
* Get the value types from a const object so the object can behave similarly to an enum.
|
|
340
|
+
*
|
|
341
|
+
* @category Types
|
|
342
|
+
*
|
|
343
|
+
* @template ObjectType - The type of the object to get the value types for.
|
|
344
|
+
*/
|
|
345
|
+
type CreateEnumType<ObjectType extends Record<RecordKey, unknown>> = ObjectType[keyof ObjectType];
|
|
346
|
+
//#endregion
|
|
354
347
|
//#region src/types/DisallowUndefined.d.ts
|
|
355
348
|
/**
|
|
356
349
|
* Resolves to an error message type if the type argument could potentially be undefined.
|
|
@@ -395,10 +388,24 @@ type OptionalOnCondition<Condition extends boolean, ResolvedTypeIfTrue> = Condit
|
|
|
395
388
|
//#region src/functions/miscellaneous/createFormData.d.ts
|
|
396
389
|
type FormDataNullableResolutionStrategy = "stringify" | "empty" | "omit";
|
|
397
390
|
type FormDataArrayResolutionStrategy = "stringify" | "multiple";
|
|
391
|
+
/**
|
|
392
|
+
* Base options for resolving form data.
|
|
393
|
+
*
|
|
394
|
+
* @category Function Options
|
|
395
|
+
*
|
|
396
|
+
* @template Key - The type of the key of the input record.
|
|
397
|
+
*/
|
|
398
398
|
interface CreateFormDataOptionsBase<Key extends RecordKey> {
|
|
399
399
|
/** How to resolve any arrays provided in the data (can either stringify them or add them multiple times). */
|
|
400
400
|
arrayResolution?: FormDataArrayResolutionStrategy | Partial<Record<Key, FormDataArrayResolutionStrategy>>;
|
|
401
401
|
}
|
|
402
|
+
/**
|
|
403
|
+
* Options for resolving form data when it may be undefined or null, but not both.
|
|
404
|
+
*
|
|
405
|
+
* @category Function Options
|
|
406
|
+
*
|
|
407
|
+
* @template Key - The type of the key of the input record.
|
|
408
|
+
*/
|
|
402
409
|
interface CreateFormDataOptionsUndefinedOrNullResolution<Key extends RecordKey> extends CreateFormDataOptionsBase<Key> {
|
|
403
410
|
/** How to resolve undefined data (May either stringify to 'undefined', resolve to an empty string, or omit entirely). */
|
|
404
411
|
undefinedResolution?: FormDataNullableResolutionStrategy | Partial<Record<Key, FormDataNullableResolutionStrategy>>;
|
|
@@ -407,6 +414,13 @@ interface CreateFormDataOptionsUndefinedOrNullResolution<Key extends RecordKey>
|
|
|
407
414
|
/** @note This must not be provided at the same time as undefinedResolution and/or nullResolution. */
|
|
408
415
|
nullableResolution?: never;
|
|
409
416
|
}
|
|
417
|
+
/**
|
|
418
|
+
* Options for resolving form data when it may be nullable, but not both.
|
|
419
|
+
*
|
|
420
|
+
* @category Function Options
|
|
421
|
+
*
|
|
422
|
+
* @template Key - The type of the key of the input record.
|
|
423
|
+
*/
|
|
410
424
|
interface CreateFormDataOptionsNullableResolution<Key extends RecordKey> extends CreateFormDataOptionsBase<Key> {
|
|
411
425
|
/** @note This must not be provided at the same time as nullableResolution. */
|
|
412
426
|
undefinedResolution?: never;
|
|
@@ -415,6 +429,13 @@ interface CreateFormDataOptionsNullableResolution<Key extends RecordKey> extends
|
|
|
415
429
|
/** How to resolve nullable data (May either stringify to 'undefined | null', resolve to an empty string, or omit entirely). */
|
|
416
430
|
nullableResolution: FormDataNullableResolutionStrategy | Partial<Record<Key, FormDataNullableResolutionStrategy>>;
|
|
417
431
|
}
|
|
432
|
+
/**
|
|
433
|
+
* Options for resolving form data.
|
|
434
|
+
*
|
|
435
|
+
* @category Function Options
|
|
436
|
+
*
|
|
437
|
+
* @template Key - The type of the key of the input record.
|
|
438
|
+
*/
|
|
418
439
|
type CreateFormDataOptions<Key extends RecordKey> = CreateFormDataOptionsUndefinedOrNullResolution<Key> | CreateFormDataOptionsNullableResolution<Key>;
|
|
419
440
|
/**
|
|
420
441
|
* Creates FormData from a given object, resolving non-string types as appropriate.
|
|
@@ -456,6 +477,11 @@ declare function getRandomNumber(lowerBound: number, upperBound: number): number
|
|
|
456
477
|
declare function isOrdered(array: readonly number[]): boolean;
|
|
457
478
|
//#endregion
|
|
458
479
|
//#region src/functions/miscellaneous/stringListToArray.d.ts
|
|
480
|
+
/**
|
|
481
|
+
* Options to apply to the conversion of a string list to an array.
|
|
482
|
+
*
|
|
483
|
+
* @category Function Options
|
|
484
|
+
*/
|
|
459
485
|
interface StringListToArrayOptions {
|
|
460
486
|
/** What each item in the list is separated by. */
|
|
461
487
|
separator?: string;
|
|
@@ -536,17 +562,17 @@ declare function omitProperties<ObjectType extends Record<string, unknown> | Rea
|
|
|
536
562
|
declare function parseBoolean(inputString: string): boolean;
|
|
537
563
|
//#endregion
|
|
538
564
|
//#region src/functions/parsers/parseEnv.d.ts
|
|
539
|
-
declare const envSchema: z.ZodEnum<{
|
|
540
|
-
test: "test";
|
|
541
|
-
development: "development";
|
|
542
|
-
production: "production";
|
|
543
|
-
}>;
|
|
544
565
|
/**
|
|
545
|
-
* Represents the
|
|
566
|
+
* Represents the three common development environments.
|
|
546
567
|
*
|
|
547
568
|
* @category Types
|
|
548
569
|
*/
|
|
549
|
-
|
|
570
|
+
declare const Env: {
|
|
571
|
+
TEST: string;
|
|
572
|
+
DEVELOPMENT: string;
|
|
573
|
+
PRODUCTION: string;
|
|
574
|
+
};
|
|
575
|
+
type Env = CreateEnumType<typeof Env>;
|
|
550
576
|
/**
|
|
551
577
|
* Parses the input and verifies it matches one of the environments allowed by the Env types ("test" | "development" | "production").
|
|
552
578
|
*
|
|
@@ -597,6 +623,17 @@ declare function parseFormData(formData: FormData): Record<string, string | Blob
|
|
|
597
623
|
declare function parseIntStrict(string: string, radix?: number): number;
|
|
598
624
|
//#endregion
|
|
599
625
|
//#region src/functions/parsers/parseVersionType.d.ts
|
|
626
|
+
/**
|
|
627
|
+
* Represents the three common software version types.
|
|
628
|
+
*
|
|
629
|
+
* @category Types
|
|
630
|
+
*/
|
|
631
|
+
declare const VersionType: {
|
|
632
|
+
readonly MAJOR: "major";
|
|
633
|
+
readonly MINOR: "minor";
|
|
634
|
+
readonly PATCH: "patch";
|
|
635
|
+
};
|
|
636
|
+
type VersionType = CreateEnumType<typeof VersionType>;
|
|
600
637
|
/**
|
|
601
638
|
* Parses the input and verifies it is a valid software version type (i.e. `"major" | "minor" | "patch"`)
|
|
602
639
|
*
|
|
@@ -677,6 +714,11 @@ declare function deepFreeze<ObjectType extends object>(object: ObjectType): Read
|
|
|
677
714
|
declare function appendSemicolon(stringToAppendTo: string): string;
|
|
678
715
|
//#endregion
|
|
679
716
|
//#region src/functions/stringHelpers/camelToKebab.d.ts
|
|
717
|
+
/**
|
|
718
|
+
* Options to apply to the conversion from camelCase to kebab-case
|
|
719
|
+
*
|
|
720
|
+
* @category Function Options
|
|
721
|
+
*/
|
|
680
722
|
interface CamelToKebabOptions {
|
|
681
723
|
/** Whether to leave consecutive capitals alone in the conversion or not (e.g. `validateAPIUser` becomes `validate-a-p-i-user` if `false`, and `validate-api-user` if `true`) */
|
|
682
724
|
preserveConsecutiveCapitals?: boolean;
|
|
@@ -694,6 +736,11 @@ interface CamelToKebabOptions {
|
|
|
694
736
|
declare function camelToKebab(string: string, options?: CamelToKebabOptions): string;
|
|
695
737
|
//#endregion
|
|
696
738
|
//#region src/functions/stringHelpers/kebabToCamel.d.ts
|
|
739
|
+
/**
|
|
740
|
+
* Options to apply to the conversion from kebab-case to camelCase
|
|
741
|
+
*
|
|
742
|
+
* @category Function Options
|
|
743
|
+
*/
|
|
697
744
|
interface KebabToCamelOptions {
|
|
698
745
|
/** Whether or not the converted string should start with an uppercase (e.g. CamelCase instead of camelCase). */
|
|
699
746
|
startWithUpper?: boolean;
|
|
@@ -773,7 +820,9 @@ declare function createTemplateStringsArray(strings: readonly string[]): Templat
|
|
|
773
820
|
*
|
|
774
821
|
* You can pass a template string directly by doing:
|
|
775
822
|
*
|
|
776
|
-
*
|
|
823
|
+
* ```
|
|
824
|
+
* interpolate`Template string here`.
|
|
825
|
+
* ```
|
|
777
826
|
*
|
|
778
827
|
* In this case, it will be functionally the same as if you just wrote the template string by itself.
|
|
779
828
|
*
|
|
@@ -792,7 +841,9 @@ declare function interpolate(strings: TemplateStringsArray, ...interpolations: u
|
|
|
792
841
|
*
|
|
793
842
|
* You can pass a template string directly by doing:
|
|
794
843
|
*
|
|
795
|
-
*
|
|
844
|
+
* ```typescript
|
|
845
|
+
* interpolateObjects`Template string here ${{ my: "object" }}`.
|
|
846
|
+
* ```
|
|
796
847
|
*
|
|
797
848
|
* @category Tagged Template
|
|
798
849
|
*
|
|
@@ -804,6 +855,11 @@ declare function interpolate(strings: TemplateStringsArray, ...interpolations: u
|
|
|
804
855
|
declare function interpolateObjects(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
|
|
805
856
|
//#endregion
|
|
806
857
|
//#region src/functions/taggedTemplate/normaliseIndents.d.ts
|
|
858
|
+
/**
|
|
859
|
+
* Options to apply to the normalisation of indents in multi-line template strings
|
|
860
|
+
*
|
|
861
|
+
* @category Function Options
|
|
862
|
+
*/
|
|
807
863
|
interface NormaliseIndentsOptions {
|
|
808
864
|
/** Whether to preserve extra tabs or not (defaults to true) */
|
|
809
865
|
preserveTabs?: boolean;
|
|
@@ -826,9 +882,11 @@ declare function normaliseIndents(options: NormaliseIndentsOptions): NormaliseIn
|
|
|
826
882
|
*
|
|
827
883
|
* You can pass a template string directly by doing:
|
|
828
884
|
*
|
|
829
|
-
*
|
|
830
|
-
*
|
|
831
|
-
*
|
|
885
|
+
* ```typescript
|
|
886
|
+
* normaliseIndents`Template string here
|
|
887
|
+
* with a new line
|
|
888
|
+
* and another new line`.
|
|
889
|
+
* ```
|
|
832
890
|
*
|
|
833
891
|
*@category Tagged Template
|
|
834
892
|
*
|
|
@@ -843,15 +901,19 @@ declare function normaliseIndents(strings: TemplateStringsArray, ...interpolatio
|
|
|
843
901
|
*
|
|
844
902
|
* You can pass a template string directly by doing:
|
|
845
903
|
*
|
|
846
|
-
*
|
|
847
|
-
*
|
|
848
|
-
*
|
|
904
|
+
* ```typescript
|
|
905
|
+
* normalizeIndents`Template string here
|
|
906
|
+
* with a new line
|
|
907
|
+
* and another new line`.
|
|
908
|
+
* ```
|
|
849
909
|
*
|
|
850
910
|
* You may also pass the options first, then invoke the resulting function with a template string:
|
|
851
911
|
*
|
|
852
|
-
*
|
|
853
|
-
*
|
|
854
|
-
*
|
|
912
|
+
* ```typescript
|
|
913
|
+
* normalizeIndents({ preserveTabs: false })`Template string here
|
|
914
|
+
* with a new line
|
|
915
|
+
* and another new line`.
|
|
916
|
+
* ```
|
|
855
917
|
*
|
|
856
918
|
* @param first - The strings from the template to process, or the options to apply.
|
|
857
919
|
* @param args - An array of all interpolations from the template.
|
|
@@ -931,4 +993,4 @@ interface ParseVersionOptions {
|
|
|
931
993
|
*/
|
|
932
994
|
declare function parseVersion(input: string, options?: ParseVersionOptions): string;
|
|
933
995
|
//#endregion
|
|
934
|
-
export { APIError, ArrayElement, CamelToKebabOptions, CreateEnumType, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, IncrementVersionOptions, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, ParseVersionOptions, RecordKey, StringListToArrayOptions, VERSION_NUMBER_REGEX, VersionNumber, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, fillArray, formatDateAndTime, getIndividualVersionNumbers, getRandomNumber, getRecordKeys, httpErrorCodeLookup, incrementVersion, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersion, parseVersionType, parseZodSchema, randomiseArray, range, removeDuplicates, stringListToArray, truncate, wait };
|
|
996
|
+
export { APIError, ArrayElement, CamelToKebabOptions, CreateEnumType, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, IncrementVersionOptions, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, ParallelTuple, ParseVersionOptions, RecordKey, StringListToArrayOptions, VERSION_NUMBER_REGEX, VersionNumber, VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, fillArray, formatDateAndTime, getIndividualVersionNumbers, getRandomNumber, getRecordKeys, httpErrorCodeLookup, incrementVersion, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersion, parseVersionType, parseZodSchema, randomiseArray, range, removeDuplicates, stringListToArray, truncate, wait };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ZodType, core
|
|
1
|
+
import { ZodType, core } from "zod";
|
|
2
2
|
|
|
3
3
|
//#region src/constants/NAMESPACE_EXPORT_REGEX.d.ts
|
|
4
4
|
declare const NAMESPACE_EXPORT_REGEX = "export\\s+\\*\\s+from";
|
|
@@ -252,39 +252,14 @@ declare class DataError extends Error {
|
|
|
252
252
|
static check(input: unknown): input is DataError;
|
|
253
253
|
}
|
|
254
254
|
//#endregion
|
|
255
|
-
//#region src/types/
|
|
256
|
-
/**
|
|
257
|
-
* Represents the native Record's possible key type.
|
|
258
|
-
*
|
|
259
|
-
* @category Types
|
|
260
|
-
*/
|
|
261
|
-
type RecordKey = string | number | symbol;
|
|
262
|
-
//#endregion
|
|
263
|
-
//#region src/types/CreateEnumType.d.ts
|
|
264
|
-
/**
|
|
265
|
-
* Get the value types from a const object so the object can behave similarly to an enum.
|
|
266
|
-
*
|
|
267
|
-
* @category Types
|
|
268
|
-
*
|
|
269
|
-
* @template ObjectType - The type of the object to get the value types for.
|
|
270
|
-
*/
|
|
271
|
-
type CreateEnumType<ObjectType extends Record<RecordKey, unknown>> = ObjectType[keyof ObjectType];
|
|
272
|
-
//#endregion
|
|
273
|
-
//#region src/types/VersionType.d.ts
|
|
255
|
+
//#region src/types/VersionNumber.d.ts
|
|
274
256
|
/**
|
|
275
|
-
*
|
|
257
|
+
* Options to apply to the stringification of the version number.
|
|
276
258
|
*
|
|
277
|
-
* @category
|
|
259
|
+
* @category Class Options
|
|
278
260
|
*/
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
readonly MINOR: "minor";
|
|
282
|
-
readonly PATCH: "patch";
|
|
283
|
-
};
|
|
284
|
-
type VersionType = CreateEnumType<typeof VersionType>;
|
|
285
|
-
//#endregion
|
|
286
|
-
//#region src/types/VersionNumber.d.ts
|
|
287
|
-
interface ToStringOptions {
|
|
261
|
+
interface VersionNumberToStringOptions {
|
|
262
|
+
/** Whether you want to omit the "v" prefix or not (defaults to false). */
|
|
288
263
|
omitPrefix?: boolean;
|
|
289
264
|
}
|
|
290
265
|
/**
|
|
@@ -338,7 +313,7 @@ declare class VersionNumber {
|
|
|
338
313
|
*
|
|
339
314
|
* @returns A stringified representation of the current version number, leaving out the prefix if `omitPrefix` option was set to true.
|
|
340
315
|
*/
|
|
341
|
-
toString(options?:
|
|
316
|
+
toString(options?: VersionNumberToStringOptions): string;
|
|
342
317
|
}
|
|
343
318
|
//#endregion
|
|
344
319
|
//#region src/types/ArrayElement.d.ts
|
|
@@ -351,6 +326,24 @@ declare class VersionNumber {
|
|
|
351
326
|
*/
|
|
352
327
|
type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
|
|
353
328
|
//#endregion
|
|
329
|
+
//#region src/types/RecordKey.d.ts
|
|
330
|
+
/**
|
|
331
|
+
* Represents the native Record's possible key type.
|
|
332
|
+
*
|
|
333
|
+
* @category Types
|
|
334
|
+
*/
|
|
335
|
+
type RecordKey = string | number | symbol;
|
|
336
|
+
//#endregion
|
|
337
|
+
//#region src/types/CreateEnumType.d.ts
|
|
338
|
+
/**
|
|
339
|
+
* Get the value types from a const object so the object can behave similarly to an enum.
|
|
340
|
+
*
|
|
341
|
+
* @category Types
|
|
342
|
+
*
|
|
343
|
+
* @template ObjectType - The type of the object to get the value types for.
|
|
344
|
+
*/
|
|
345
|
+
type CreateEnumType<ObjectType extends Record<RecordKey, unknown>> = ObjectType[keyof ObjectType];
|
|
346
|
+
//#endregion
|
|
354
347
|
//#region src/types/DisallowUndefined.d.ts
|
|
355
348
|
/**
|
|
356
349
|
* Resolves to an error message type if the type argument could potentially be undefined.
|
|
@@ -395,10 +388,24 @@ type OptionalOnCondition<Condition extends boolean, ResolvedTypeIfTrue> = Condit
|
|
|
395
388
|
//#region src/functions/miscellaneous/createFormData.d.ts
|
|
396
389
|
type FormDataNullableResolutionStrategy = "stringify" | "empty" | "omit";
|
|
397
390
|
type FormDataArrayResolutionStrategy = "stringify" | "multiple";
|
|
391
|
+
/**
|
|
392
|
+
* Base options for resolving form data.
|
|
393
|
+
*
|
|
394
|
+
* @category Function Options
|
|
395
|
+
*
|
|
396
|
+
* @template Key - The type of the key of the input record.
|
|
397
|
+
*/
|
|
398
398
|
interface CreateFormDataOptionsBase<Key extends RecordKey> {
|
|
399
399
|
/** How to resolve any arrays provided in the data (can either stringify them or add them multiple times). */
|
|
400
400
|
arrayResolution?: FormDataArrayResolutionStrategy | Partial<Record<Key, FormDataArrayResolutionStrategy>>;
|
|
401
401
|
}
|
|
402
|
+
/**
|
|
403
|
+
* Options for resolving form data when it may be undefined or null, but not both.
|
|
404
|
+
*
|
|
405
|
+
* @category Function Options
|
|
406
|
+
*
|
|
407
|
+
* @template Key - The type of the key of the input record.
|
|
408
|
+
*/
|
|
402
409
|
interface CreateFormDataOptionsUndefinedOrNullResolution<Key extends RecordKey> extends CreateFormDataOptionsBase<Key> {
|
|
403
410
|
/** How to resolve undefined data (May either stringify to 'undefined', resolve to an empty string, or omit entirely). */
|
|
404
411
|
undefinedResolution?: FormDataNullableResolutionStrategy | Partial<Record<Key, FormDataNullableResolutionStrategy>>;
|
|
@@ -407,6 +414,13 @@ interface CreateFormDataOptionsUndefinedOrNullResolution<Key extends RecordKey>
|
|
|
407
414
|
/** @note This must not be provided at the same time as undefinedResolution and/or nullResolution. */
|
|
408
415
|
nullableResolution?: never;
|
|
409
416
|
}
|
|
417
|
+
/**
|
|
418
|
+
* Options for resolving form data when it may be nullable, but not both.
|
|
419
|
+
*
|
|
420
|
+
* @category Function Options
|
|
421
|
+
*
|
|
422
|
+
* @template Key - The type of the key of the input record.
|
|
423
|
+
*/
|
|
410
424
|
interface CreateFormDataOptionsNullableResolution<Key extends RecordKey> extends CreateFormDataOptionsBase<Key> {
|
|
411
425
|
/** @note This must not be provided at the same time as nullableResolution. */
|
|
412
426
|
undefinedResolution?: never;
|
|
@@ -415,6 +429,13 @@ interface CreateFormDataOptionsNullableResolution<Key extends RecordKey> extends
|
|
|
415
429
|
/** How to resolve nullable data (May either stringify to 'undefined | null', resolve to an empty string, or omit entirely). */
|
|
416
430
|
nullableResolution: FormDataNullableResolutionStrategy | Partial<Record<Key, FormDataNullableResolutionStrategy>>;
|
|
417
431
|
}
|
|
432
|
+
/**
|
|
433
|
+
* Options for resolving form data.
|
|
434
|
+
*
|
|
435
|
+
* @category Function Options
|
|
436
|
+
*
|
|
437
|
+
* @template Key - The type of the key of the input record.
|
|
438
|
+
*/
|
|
418
439
|
type CreateFormDataOptions<Key extends RecordKey> = CreateFormDataOptionsUndefinedOrNullResolution<Key> | CreateFormDataOptionsNullableResolution<Key>;
|
|
419
440
|
/**
|
|
420
441
|
* Creates FormData from a given object, resolving non-string types as appropriate.
|
|
@@ -456,6 +477,11 @@ declare function getRandomNumber(lowerBound: number, upperBound: number): number
|
|
|
456
477
|
declare function isOrdered(array: readonly number[]): boolean;
|
|
457
478
|
//#endregion
|
|
458
479
|
//#region src/functions/miscellaneous/stringListToArray.d.ts
|
|
480
|
+
/**
|
|
481
|
+
* Options to apply to the conversion of a string list to an array.
|
|
482
|
+
*
|
|
483
|
+
* @category Function Options
|
|
484
|
+
*/
|
|
459
485
|
interface StringListToArrayOptions {
|
|
460
486
|
/** What each item in the list is separated by. */
|
|
461
487
|
separator?: string;
|
|
@@ -536,17 +562,17 @@ declare function omitProperties<ObjectType extends Record<string, unknown> | Rea
|
|
|
536
562
|
declare function parseBoolean(inputString: string): boolean;
|
|
537
563
|
//#endregion
|
|
538
564
|
//#region src/functions/parsers/parseEnv.d.ts
|
|
539
|
-
declare const envSchema: z$1.ZodEnum<{
|
|
540
|
-
test: "test";
|
|
541
|
-
development: "development";
|
|
542
|
-
production: "production";
|
|
543
|
-
}>;
|
|
544
565
|
/**
|
|
545
|
-
* Represents the
|
|
566
|
+
* Represents the three common development environments.
|
|
546
567
|
*
|
|
547
568
|
* @category Types
|
|
548
569
|
*/
|
|
549
|
-
|
|
570
|
+
declare const Env: {
|
|
571
|
+
TEST: string;
|
|
572
|
+
DEVELOPMENT: string;
|
|
573
|
+
PRODUCTION: string;
|
|
574
|
+
};
|
|
575
|
+
type Env = CreateEnumType<typeof Env>;
|
|
550
576
|
/**
|
|
551
577
|
* Parses the input and verifies it matches one of the environments allowed by the Env types ("test" | "development" | "production").
|
|
552
578
|
*
|
|
@@ -597,6 +623,17 @@ declare function parseFormData(formData: FormData): Record<string, string | Blob
|
|
|
597
623
|
declare function parseIntStrict(string: string, radix?: number): number;
|
|
598
624
|
//#endregion
|
|
599
625
|
//#region src/functions/parsers/parseVersionType.d.ts
|
|
626
|
+
/**
|
|
627
|
+
* Represents the three common software version types.
|
|
628
|
+
*
|
|
629
|
+
* @category Types
|
|
630
|
+
*/
|
|
631
|
+
declare const VersionType: {
|
|
632
|
+
readonly MAJOR: "major";
|
|
633
|
+
readonly MINOR: "minor";
|
|
634
|
+
readonly PATCH: "patch";
|
|
635
|
+
};
|
|
636
|
+
type VersionType = CreateEnumType<typeof VersionType>;
|
|
600
637
|
/**
|
|
601
638
|
* Parses the input and verifies it is a valid software version type (i.e. `"major" | "minor" | "patch"`)
|
|
602
639
|
*
|
|
@@ -677,6 +714,11 @@ declare function deepFreeze<ObjectType extends object>(object: ObjectType): Read
|
|
|
677
714
|
declare function appendSemicolon(stringToAppendTo: string): string;
|
|
678
715
|
//#endregion
|
|
679
716
|
//#region src/functions/stringHelpers/camelToKebab.d.ts
|
|
717
|
+
/**
|
|
718
|
+
* Options to apply to the conversion from camelCase to kebab-case
|
|
719
|
+
*
|
|
720
|
+
* @category Function Options
|
|
721
|
+
*/
|
|
680
722
|
interface CamelToKebabOptions {
|
|
681
723
|
/** Whether to leave consecutive capitals alone in the conversion or not (e.g. `validateAPIUser` becomes `validate-a-p-i-user` if `false`, and `validate-api-user` if `true`) */
|
|
682
724
|
preserveConsecutiveCapitals?: boolean;
|
|
@@ -694,6 +736,11 @@ interface CamelToKebabOptions {
|
|
|
694
736
|
declare function camelToKebab(string: string, options?: CamelToKebabOptions): string;
|
|
695
737
|
//#endregion
|
|
696
738
|
//#region src/functions/stringHelpers/kebabToCamel.d.ts
|
|
739
|
+
/**
|
|
740
|
+
* Options to apply to the conversion from kebab-case to camelCase
|
|
741
|
+
*
|
|
742
|
+
* @category Function Options
|
|
743
|
+
*/
|
|
697
744
|
interface KebabToCamelOptions {
|
|
698
745
|
/** Whether or not the converted string should start with an uppercase (e.g. CamelCase instead of camelCase). */
|
|
699
746
|
startWithUpper?: boolean;
|
|
@@ -773,7 +820,9 @@ declare function createTemplateStringsArray(strings: readonly string[]): Templat
|
|
|
773
820
|
*
|
|
774
821
|
* You can pass a template string directly by doing:
|
|
775
822
|
*
|
|
776
|
-
*
|
|
823
|
+
* ```
|
|
824
|
+
* interpolate`Template string here`.
|
|
825
|
+
* ```
|
|
777
826
|
*
|
|
778
827
|
* In this case, it will be functionally the same as if you just wrote the template string by itself.
|
|
779
828
|
*
|
|
@@ -792,7 +841,9 @@ declare function interpolate(strings: TemplateStringsArray, ...interpolations: u
|
|
|
792
841
|
*
|
|
793
842
|
* You can pass a template string directly by doing:
|
|
794
843
|
*
|
|
795
|
-
*
|
|
844
|
+
* ```typescript
|
|
845
|
+
* interpolateObjects`Template string here ${{ my: "object" }}`.
|
|
846
|
+
* ```
|
|
796
847
|
*
|
|
797
848
|
* @category Tagged Template
|
|
798
849
|
*
|
|
@@ -804,6 +855,11 @@ declare function interpolate(strings: TemplateStringsArray, ...interpolations: u
|
|
|
804
855
|
declare function interpolateObjects(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
|
|
805
856
|
//#endregion
|
|
806
857
|
//#region src/functions/taggedTemplate/normaliseIndents.d.ts
|
|
858
|
+
/**
|
|
859
|
+
* Options to apply to the normalisation of indents in multi-line template strings
|
|
860
|
+
*
|
|
861
|
+
* @category Function Options
|
|
862
|
+
*/
|
|
807
863
|
interface NormaliseIndentsOptions {
|
|
808
864
|
/** Whether to preserve extra tabs or not (defaults to true) */
|
|
809
865
|
preserveTabs?: boolean;
|
|
@@ -826,9 +882,11 @@ declare function normaliseIndents(options: NormaliseIndentsOptions): NormaliseIn
|
|
|
826
882
|
*
|
|
827
883
|
* You can pass a template string directly by doing:
|
|
828
884
|
*
|
|
829
|
-
*
|
|
830
|
-
*
|
|
831
|
-
*
|
|
885
|
+
* ```typescript
|
|
886
|
+
* normaliseIndents`Template string here
|
|
887
|
+
* with a new line
|
|
888
|
+
* and another new line`.
|
|
889
|
+
* ```
|
|
832
890
|
*
|
|
833
891
|
*@category Tagged Template
|
|
834
892
|
*
|
|
@@ -843,15 +901,19 @@ declare function normaliseIndents(strings: TemplateStringsArray, ...interpolatio
|
|
|
843
901
|
*
|
|
844
902
|
* You can pass a template string directly by doing:
|
|
845
903
|
*
|
|
846
|
-
*
|
|
847
|
-
*
|
|
848
|
-
*
|
|
904
|
+
* ```typescript
|
|
905
|
+
* normalizeIndents`Template string here
|
|
906
|
+
* with a new line
|
|
907
|
+
* and another new line`.
|
|
908
|
+
* ```
|
|
849
909
|
*
|
|
850
910
|
* You may also pass the options first, then invoke the resulting function with a template string:
|
|
851
911
|
*
|
|
852
|
-
*
|
|
853
|
-
*
|
|
854
|
-
*
|
|
912
|
+
* ```typescript
|
|
913
|
+
* normalizeIndents({ preserveTabs: false })`Template string here
|
|
914
|
+
* with a new line
|
|
915
|
+
* and another new line`.
|
|
916
|
+
* ```
|
|
855
917
|
*
|
|
856
918
|
* @param first - The strings from the template to process, or the options to apply.
|
|
857
919
|
* @param args - An array of all interpolations from the template.
|
|
@@ -931,4 +993,4 @@ interface ParseVersionOptions {
|
|
|
931
993
|
*/
|
|
932
994
|
declare function parseVersion(input: string, options?: ParseVersionOptions): string;
|
|
933
995
|
//#endregion
|
|
934
|
-
export { APIError, ArrayElement, CamelToKebabOptions, CreateEnumType, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined,
|
|
996
|
+
export { APIError, ArrayElement, CamelToKebabOptions, CreateEnumType, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, type IncrementVersionOptions, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, ParallelTuple, type ParseVersionOptions, RecordKey, StringListToArrayOptions, VERSION_NUMBER_REGEX, VersionNumber, VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, fillArray, formatDateAndTime, getIndividualVersionNumbers, getRandomNumber, getRecordKeys, httpErrorCodeLookup, incrementVersion, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersion, parseVersionType, parseZodSchema, randomiseArray, range, removeDuplicates, stringListToArray, truncate, wait };
|
package/dist/index.js
CHANGED
|
@@ -146,19 +146,6 @@ var DataError = class extends Error {
|
|
|
146
146
|
};
|
|
147
147
|
var DataError_default = DataError;
|
|
148
148
|
|
|
149
|
-
//#endregion
|
|
150
|
-
//#region src/types/VersionType.ts
|
|
151
|
-
/**
|
|
152
|
-
* Represents the three common software version types.
|
|
153
|
-
*
|
|
154
|
-
* @category Types
|
|
155
|
-
*/
|
|
156
|
-
const VersionType = {
|
|
157
|
-
MAJOR: "major",
|
|
158
|
-
MINOR: "minor",
|
|
159
|
-
PATCH: "patch"
|
|
160
|
-
};
|
|
161
|
-
|
|
162
149
|
//#endregion
|
|
163
150
|
//#region src/types/VersionNumber.ts
|
|
164
151
|
/**
|
|
@@ -805,11 +792,16 @@ var parseZodSchema_default = parseZodSchema;
|
|
|
805
792
|
|
|
806
793
|
//#endregion
|
|
807
794
|
//#region src/functions/parsers/parseEnv.ts
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
795
|
+
/**
|
|
796
|
+
* Represents the three common development environments.
|
|
797
|
+
*
|
|
798
|
+
* @category Types
|
|
799
|
+
*/
|
|
800
|
+
const Env = {
|
|
801
|
+
TEST: "test",
|
|
802
|
+
DEVELOPMENT: "development",
|
|
803
|
+
PRODUCTION: "production"
|
|
804
|
+
};
|
|
813
805
|
/**
|
|
814
806
|
* Parses the input and verifies it matches one of the environments allowed by the Env types ("test" | "development" | "production").
|
|
815
807
|
*
|
|
@@ -822,7 +814,7 @@ const envSchema = z$1.enum([
|
|
|
822
814
|
* @returns The specified environment if allowed.
|
|
823
815
|
*/
|
|
824
816
|
function parseEnv(data) {
|
|
825
|
-
return parseZodSchema_default(
|
|
817
|
+
return parseZodSchema_default(z$1.enum(Env), data, new DataError_default(data, "INVALID_ENV", "The provided environment type must be one of `test | development | production`"));
|
|
826
818
|
}
|
|
827
819
|
var parseEnv_default = parseEnv;
|
|
828
820
|
|
|
@@ -853,6 +845,16 @@ var parseFormData_default = parseFormData;
|
|
|
853
845
|
//#endregion
|
|
854
846
|
//#region src/functions/parsers/parseVersionType.ts
|
|
855
847
|
/**
|
|
848
|
+
* Represents the three common software version types.
|
|
849
|
+
*
|
|
850
|
+
* @category Types
|
|
851
|
+
*/
|
|
852
|
+
const VersionType = {
|
|
853
|
+
MAJOR: "major",
|
|
854
|
+
MINOR: "minor",
|
|
855
|
+
PATCH: "patch"
|
|
856
|
+
};
|
|
857
|
+
/**
|
|
856
858
|
* Parses the input and verifies it is a valid software version type (i.e. `"major" | "minor" | "patch"`)
|
|
857
859
|
*
|
|
858
860
|
* @category Parsers
|
|
@@ -1101,7 +1103,9 @@ var createTemplateStringsArray_default = createTemplateStringsArray;
|
|
|
1101
1103
|
*
|
|
1102
1104
|
* You can pass a template string directly by doing:
|
|
1103
1105
|
*
|
|
1104
|
-
*
|
|
1106
|
+
* ```
|
|
1107
|
+
* interpolate`Template string here`.
|
|
1108
|
+
* ```
|
|
1105
1109
|
*
|
|
1106
1110
|
* In this case, it will be functionally the same as if you just wrote the template string by itself.
|
|
1107
1111
|
*
|
|
@@ -1126,7 +1130,9 @@ var interpolate_default = interpolate;
|
|
|
1126
1130
|
*
|
|
1127
1131
|
* You can pass a template string directly by doing:
|
|
1128
1132
|
*
|
|
1129
|
-
*
|
|
1133
|
+
* ```typescript
|
|
1134
|
+
* interpolateObjects`Template string here ${{ my: "object" }}`.
|
|
1135
|
+
* ```
|
|
1130
1136
|
*
|
|
1131
1137
|
* @category Tagged Template
|
|
1132
1138
|
*
|
|
@@ -1176,15 +1182,19 @@ function reduceLines(lines, { preserveTabs = true }) {
|
|
|
1176
1182
|
*
|
|
1177
1183
|
* You can pass a template string directly by doing:
|
|
1178
1184
|
*
|
|
1179
|
-
*
|
|
1180
|
-
*
|
|
1181
|
-
*
|
|
1185
|
+
* ```typescript
|
|
1186
|
+
* normaliseIndents`Template string here
|
|
1187
|
+
* with a new line
|
|
1188
|
+
* and another new line`.
|
|
1189
|
+
* ```
|
|
1182
1190
|
*
|
|
1183
1191
|
* You may also pass the options first, then invoke the resulting function with a template string:
|
|
1184
1192
|
*
|
|
1185
|
-
*
|
|
1186
|
-
*
|
|
1187
|
-
*
|
|
1193
|
+
* ```typescript
|
|
1194
|
+
* normaliseIndents({ preserveTabs: false })`Template string here
|
|
1195
|
+
* with a new line
|
|
1196
|
+
* and another new line`.
|
|
1197
|
+
* ```
|
|
1188
1198
|
*
|
|
1189
1199
|
*@category Tagged Template
|
|
1190
1200
|
*
|
|
@@ -1209,15 +1219,19 @@ function normaliseIndents(first, ...args) {
|
|
|
1209
1219
|
*
|
|
1210
1220
|
* You can pass a template string directly by doing:
|
|
1211
1221
|
*
|
|
1212
|
-
*
|
|
1213
|
-
*
|
|
1214
|
-
*
|
|
1222
|
+
* ```typescript
|
|
1223
|
+
* normalizeIndents`Template string here
|
|
1224
|
+
* with a new line
|
|
1225
|
+
* and another new line`.
|
|
1226
|
+
* ```
|
|
1215
1227
|
*
|
|
1216
1228
|
* You may also pass the options first, then invoke the resulting function with a template string:
|
|
1217
1229
|
*
|
|
1218
|
-
*
|
|
1219
|
-
*
|
|
1220
|
-
*
|
|
1230
|
+
* ```typescript
|
|
1231
|
+
* normalizeIndents({ preserveTabs: false })`Template string here
|
|
1232
|
+
* with a new line
|
|
1233
|
+
* and another new line`.
|
|
1234
|
+
* ```
|
|
1221
1235
|
*
|
|
1222
1236
|
* @param first - The strings from the template to process, or the options to apply.
|
|
1223
1237
|
* @param args - An array of all interpolations from the template.
|
|
@@ -1320,4 +1334,4 @@ function incrementVersion(version, incrementType, options) {
|
|
|
1320
1334
|
var incrementVersion_default = incrementVersion;
|
|
1321
1335
|
|
|
1322
1336
|
//#endregion
|
|
1323
|
-
export { APIError_default as APIError, DataError_default as DataError, NAMESPACE_EXPORT_REGEX_default as NAMESPACE_EXPORT_REGEX, VERSION_NUMBER_REGEX_default as VERSION_NUMBER_REGEX, VersionNumber_default as VersionNumber, VersionType, addDaysToDate_default as addDaysToDate, appendSemicolon_default as appendSemicolon, camelToKebab_default as camelToKebab, convertFileToBase64_default as convertFileToBase64, createFormData_default as createFormData, createTemplateStringsArray_default as createTemplateStringsArray, deepCopy_default as deepCopy, deepFreeze_default as deepFreeze, determineVersionType_default as determineVersionType, fillArray_default as fillArray, formatDateAndTime_default as formatDateAndTime, getIndividualVersionNumbers_default as getIndividualVersionNumbers, getRandomNumber_default as getRandomNumber, getRecordKeys_default as getRecordKeys, httpErrorCodeLookup, incrementVersion_default as incrementVersion, interpolate_default as interpolate, interpolateObjects_default as interpolateObjects, isAnniversary_default as isAnniversary, isLeapYear_default as isLeapYear, isMonthlyMultiple_default as isMonthlyMultiple, isOrdered_default as isOrdered, isSameDate_default as isSameDate, kebabToCamel_default as kebabToCamel, normaliseImportPath, normaliseIndents_default as normaliseIndents, normalizeImportPath_default as normalizeImportPath, normalizeIndents, omitProperties_default as omitProperties, paralleliseArrays_default as paralleliseArrays, parseBoolean_default as parseBoolean, parseEnv_default as parseEnv, parseFormData_default as parseFormData, parseIntStrict_default as parseIntStrict, parseVersion_default as parseVersion, parseVersionType_default as parseVersionType, parseZodSchema_default as parseZodSchema, randomiseArray_default as randomiseArray, range_default as range, removeDuplicates_default as removeDuplicates, stringListToArray_default as stringListToArray, truncate_default as truncate, wait_default as wait };
|
|
1337
|
+
export { APIError_default as APIError, DataError_default as DataError, Env, NAMESPACE_EXPORT_REGEX_default as NAMESPACE_EXPORT_REGEX, VERSION_NUMBER_REGEX_default as VERSION_NUMBER_REGEX, VersionNumber_default as VersionNumber, VersionType, addDaysToDate_default as addDaysToDate, appendSemicolon_default as appendSemicolon, camelToKebab_default as camelToKebab, convertFileToBase64_default as convertFileToBase64, createFormData_default as createFormData, createTemplateStringsArray_default as createTemplateStringsArray, deepCopy_default as deepCopy, deepFreeze_default as deepFreeze, determineVersionType_default as determineVersionType, fillArray_default as fillArray, formatDateAndTime_default as formatDateAndTime, getIndividualVersionNumbers_default as getIndividualVersionNumbers, getRandomNumber_default as getRandomNumber, getRecordKeys_default as getRecordKeys, httpErrorCodeLookup, incrementVersion_default as incrementVersion, interpolate_default as interpolate, interpolateObjects_default as interpolateObjects, isAnniversary_default as isAnniversary, isLeapYear_default as isLeapYear, isMonthlyMultiple_default as isMonthlyMultiple, isOrdered_default as isOrdered, isSameDate_default as isSameDate, kebabToCamel_default as kebabToCamel, normaliseImportPath, normaliseIndents_default as normaliseIndents, normalizeImportPath_default as normalizeImportPath, normalizeIndents, omitProperties_default as omitProperties, paralleliseArrays_default as paralleliseArrays, parseBoolean_default as parseBoolean, parseEnv_default as parseEnv, parseFormData_default as parseFormData, parseIntStrict_default as parseIntStrict, parseVersion_default as parseVersion, parseVersionType_default as parseVersionType, parseZodSchema_default as parseZodSchema, randomiseArray_default as randomiseArray, range_default as range, removeDuplicates_default as removeDuplicates, stringListToArray_default as stringListToArray, truncate_default as truncate, wait_default as wait };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alextheman/utility",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.2",
|
|
4
4
|
"description": "Helpful utility functions",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"zod": "^4.2.1"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@alextheman/eslint-plugin": "^5.2.
|
|
22
|
+
"@alextheman/eslint-plugin": "^5.2.1",
|
|
23
23
|
"@types/node": "^25.0.3",
|
|
24
24
|
"alex-c-line": "^1.10.0",
|
|
25
25
|
"dotenv-cli": "^11.0.0",
|