@alextheman/utility 2.20.0 → 2.21.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 +96 -56
- package/dist/index.d.cts +15 -2
- package/dist/index.d.ts +15 -2
- package/dist/index.js +94 -56
- package/package.json +5 -3
package/dist/index.cjs
CHANGED
|
@@ -46,6 +46,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
46
46
|
var index_exports = {};
|
|
47
47
|
__export(index_exports, {
|
|
48
48
|
APIError: () => APIError_default,
|
|
49
|
+
DataError: () => DataError_default,
|
|
49
50
|
addDaysToDate: () => addDaysToDate_default,
|
|
50
51
|
appendSemicolon: () => appendSemicolon_default,
|
|
51
52
|
camelToKebab: () => camelToKebab_default,
|
|
@@ -72,6 +73,7 @@ __export(index_exports, {
|
|
|
72
73
|
parseEnv: () => Env_default,
|
|
73
74
|
parseIntStrict: () => parseIntStrict_default,
|
|
74
75
|
parseUUID: () => UUID_default,
|
|
76
|
+
parseZodSchema: () => parseZodSchema_default,
|
|
75
77
|
randomiseArray: () => randomiseArray_default,
|
|
76
78
|
range: () => range_default,
|
|
77
79
|
removeDuplicates: () => removeDuplicates_default,
|
|
@@ -425,6 +427,98 @@ function paralleliseArrays(firstArray, secondArray) {
|
|
|
425
427
|
}
|
|
426
428
|
var paralleliseArrays_default = paralleliseArrays;
|
|
427
429
|
|
|
430
|
+
// src/types/APIError.ts
|
|
431
|
+
var httpErrorCodeLookup = {
|
|
432
|
+
400: "BAD_REQUEST",
|
|
433
|
+
401: "UNAUTHORISED",
|
|
434
|
+
403: "FORBIDDEN",
|
|
435
|
+
404: "NOT_FOUND",
|
|
436
|
+
/* Supporting this one too because it's funny. You'll never use it in practice because
|
|
437
|
+
why would an error give a teapot, but it's funny. Do not question me. */
|
|
438
|
+
418: "I_AM_A_TEAPOT",
|
|
439
|
+
500: "INTERNAL_SERVER_ERROR"
|
|
440
|
+
};
|
|
441
|
+
var APIError = class extends Error {
|
|
442
|
+
constructor(status = 500, message, options) {
|
|
443
|
+
var _a;
|
|
444
|
+
super(message, options);
|
|
445
|
+
__publicField(this, "status");
|
|
446
|
+
this.status = status;
|
|
447
|
+
if (message) {
|
|
448
|
+
this.message = message;
|
|
449
|
+
} else {
|
|
450
|
+
this.message = (_a = httpErrorCodeLookup[this.status]) != null ? _a : "API_ERROR";
|
|
451
|
+
}
|
|
452
|
+
Object.defineProperty(this, "message", { enumerable: true });
|
|
453
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
454
|
+
}
|
|
455
|
+
static check(input) {
|
|
456
|
+
const data = input;
|
|
457
|
+
return typeof data === "object" && data !== null && typeof (data == null ? void 0 : data.status) === "number" && typeof (data == null ? void 0 : data.message) === "string";
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
var APIError_default = APIError;
|
|
461
|
+
|
|
462
|
+
// src/types/DataError.ts
|
|
463
|
+
var DataError = class extends Error {
|
|
464
|
+
/** @param data - The data that caused the error. */
|
|
465
|
+
/** @param message - A human-readable error message (e.g. The data provided is invalid). */
|
|
466
|
+
/** @param code - A standardised code (e.g. UNEXPECTED_DATA). */
|
|
467
|
+
/** @param options - Extra options to pass to super Error constructor. */
|
|
468
|
+
constructor(data, message = "The data provided is invalid", code = "INVALID_DATA", options) {
|
|
469
|
+
super(message, options);
|
|
470
|
+
__publicField(this, "data");
|
|
471
|
+
__publicField(this, "code");
|
|
472
|
+
if (Error.captureStackTrace) {
|
|
473
|
+
Error.captureStackTrace(this, new.target);
|
|
474
|
+
}
|
|
475
|
+
this.name = new.target.name;
|
|
476
|
+
this.code = code;
|
|
477
|
+
this.data = data;
|
|
478
|
+
Object.defineProperty(this, "message", { enumerable: true });
|
|
479
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
480
|
+
}
|
|
481
|
+
static check(input) {
|
|
482
|
+
const data = input;
|
|
483
|
+
return typeof data === "object" && data !== null && typeof data.message === "string" && typeof data.code === "string" && "data" in data;
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
var DataError_default = DataError;
|
|
487
|
+
|
|
488
|
+
// src/types/Email.ts
|
|
489
|
+
var import_zod = __toESM(require("zod"), 1);
|
|
490
|
+
var emailSchema = import_zod.default.email().brand();
|
|
491
|
+
function parseEmail(data) {
|
|
492
|
+
return emailSchema.parse(data);
|
|
493
|
+
}
|
|
494
|
+
var Email_default = parseEmail;
|
|
495
|
+
|
|
496
|
+
// src/types/Env.ts
|
|
497
|
+
var import_zod2 = require("zod");
|
|
498
|
+
var envSchema = import_zod2.z.enum(["test", "development", "production"]);
|
|
499
|
+
function parseEnv(data = "development") {
|
|
500
|
+
return envSchema.parse(data);
|
|
501
|
+
}
|
|
502
|
+
var Env_default = parseEnv;
|
|
503
|
+
|
|
504
|
+
// src/types/UUID.ts
|
|
505
|
+
var import_zod3 = __toESM(require("zod"), 1);
|
|
506
|
+
var uuidSchema = import_zod3.default.uuid().brand();
|
|
507
|
+
function parseUUID(UUID) {
|
|
508
|
+
return uuidSchema.parse(UUID);
|
|
509
|
+
}
|
|
510
|
+
var UUID_default = parseUUID;
|
|
511
|
+
|
|
512
|
+
// src/functions/parseZodSchema.ts
|
|
513
|
+
function parseZodSchema(schema, data) {
|
|
514
|
+
const parsedResult = schema.safeParse(data);
|
|
515
|
+
if (!parsedResult.success) {
|
|
516
|
+
throw new DataError_default(data);
|
|
517
|
+
}
|
|
518
|
+
return parsedResult.data;
|
|
519
|
+
}
|
|
520
|
+
var parseZodSchema_default = parseZodSchema;
|
|
521
|
+
|
|
428
522
|
// src/functions/randomiseArray.ts
|
|
429
523
|
function randomiseArray(array) {
|
|
430
524
|
const mutableArray = [...array];
|
|
@@ -608,65 +702,10 @@ function stripIndents(first, ...args) {
|
|
|
608
702
|
return reduceLines2(fullString.split("\n"), options);
|
|
609
703
|
}
|
|
610
704
|
var stripIndents_default = stripIndents;
|
|
611
|
-
|
|
612
|
-
// src/types/APIError.ts
|
|
613
|
-
var httpErrorCodeLookup = {
|
|
614
|
-
400: "BAD_REQUEST",
|
|
615
|
-
401: "UNAUTHORISED",
|
|
616
|
-
403: "FORBIDDEN",
|
|
617
|
-
404: "NOT_FOUND",
|
|
618
|
-
/* Supporting this one too because it's funny. You'll never use it in practice because
|
|
619
|
-
why would an error give a teapot, but it's funny. Do not question me. */
|
|
620
|
-
418: "I_AM_A_TEAPOT",
|
|
621
|
-
500: "INTERNAL_SERVER_ERROR"
|
|
622
|
-
};
|
|
623
|
-
var APIError = class extends Error {
|
|
624
|
-
constructor(status = 500, message, options) {
|
|
625
|
-
var _a;
|
|
626
|
-
super(message, options);
|
|
627
|
-
__publicField(this, "status");
|
|
628
|
-
this.status = status;
|
|
629
|
-
if (message) {
|
|
630
|
-
this.message = message;
|
|
631
|
-
} else {
|
|
632
|
-
this.message = (_a = httpErrorCodeLookup[this.status]) != null ? _a : "API_ERROR";
|
|
633
|
-
}
|
|
634
|
-
Object.defineProperty(this, "message", { enumerable: true });
|
|
635
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
636
|
-
}
|
|
637
|
-
static check(input) {
|
|
638
|
-
const data = input;
|
|
639
|
-
return typeof data === "object" && data !== null && typeof (data == null ? void 0 : data.status) === "number" && typeof (data == null ? void 0 : data.message) === "string";
|
|
640
|
-
}
|
|
641
|
-
};
|
|
642
|
-
var APIError_default = APIError;
|
|
643
|
-
|
|
644
|
-
// src/types/Email.ts
|
|
645
|
-
var import_zod = __toESM(require("zod"), 1);
|
|
646
|
-
var emailSchema = import_zod.default.email().brand();
|
|
647
|
-
function parseEmail(data) {
|
|
648
|
-
return emailSchema.parse(data);
|
|
649
|
-
}
|
|
650
|
-
var Email_default = parseEmail;
|
|
651
|
-
|
|
652
|
-
// src/types/Env.ts
|
|
653
|
-
var import_zod2 = require("zod");
|
|
654
|
-
var envSchema = import_zod2.z.enum(["test", "development", "production"]);
|
|
655
|
-
function parseEnv(data = "development") {
|
|
656
|
-
return envSchema.parse(data);
|
|
657
|
-
}
|
|
658
|
-
var Env_default = parseEnv;
|
|
659
|
-
|
|
660
|
-
// src/types/UUID.ts
|
|
661
|
-
var import_zod3 = __toESM(require("zod"), 1);
|
|
662
|
-
var uuidSchema = import_zod3.default.uuid().brand();
|
|
663
|
-
function parseUUID(UUID) {
|
|
664
|
-
return uuidSchema.parse(UUID);
|
|
665
|
-
}
|
|
666
|
-
var UUID_default = parseUUID;
|
|
667
705
|
// Annotate the CommonJS export names for ESM import in node:
|
|
668
706
|
0 && (module.exports = {
|
|
669
707
|
APIError,
|
|
708
|
+
DataError,
|
|
670
709
|
addDaysToDate,
|
|
671
710
|
appendSemicolon,
|
|
672
711
|
camelToKebab,
|
|
@@ -693,6 +732,7 @@ var UUID_default = parseUUID;
|
|
|
693
732
|
parseEnv,
|
|
694
733
|
parseIntStrict,
|
|
695
734
|
parseUUID,
|
|
735
|
+
parseZodSchema,
|
|
696
736
|
randomiseArray,
|
|
697
737
|
range,
|
|
698
738
|
removeDuplicates,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import z, { z as z$1 } from 'zod';
|
|
1
|
+
import z, { z as z$1, core, ZodType } from 'zod';
|
|
2
2
|
|
|
3
3
|
declare function addDaysToDate(currentDate?: Date, dayIncrement?: number): Date;
|
|
4
4
|
|
|
@@ -18,6 +18,17 @@ declare class APIError extends Error {
|
|
|
18
18
|
static check(input: unknown): input is APIError;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
declare class DataError extends Error {
|
|
22
|
+
data: unknown;
|
|
23
|
+
code: string;
|
|
24
|
+
/** @param data - The data that caused the error. */
|
|
25
|
+
/** @param message - A human-readable error message (e.g. The data provided is invalid). */
|
|
26
|
+
/** @param code - A standardised code (e.g. UNEXPECTED_DATA). */
|
|
27
|
+
/** @param options - Extra options to pass to super Error constructor. */
|
|
28
|
+
constructor(data: unknown, message?: string, code?: string, options?: ErrorOptions);
|
|
29
|
+
static check(input: unknown): input is DataError;
|
|
30
|
+
}
|
|
31
|
+
|
|
21
32
|
declare const emailSchema: z.core.$ZodBranded<z.ZodEmail, "Email">;
|
|
22
33
|
type Email = z.infer<typeof emailSchema>;
|
|
23
34
|
declare function parseEmail(data: unknown): Email;
|
|
@@ -96,6 +107,8 @@ declare function paralleliseArrays<FirstArrayItem, SecondArrayItem>(firstArray:
|
|
|
96
107
|
|
|
97
108
|
declare function parseIntStrict(...[string, radix]: Parameters<typeof parseInt>): number;
|
|
98
109
|
|
|
110
|
+
declare function parseZodSchema<Output, Input, Internals extends core.$ZodTypeInternals<Output, Input>>(schema: ZodType<Output, Input, Internals>, data: unknown): core.output<ZodType<Output, Input, Internals>>;
|
|
111
|
+
|
|
99
112
|
declare function randomiseArray<T>(array: T[]): T[];
|
|
100
113
|
|
|
101
114
|
declare function range(start: number, stop: number, step?: number): number[];
|
|
@@ -133,4 +146,4 @@ type StripIndentsFunction = (strings: TemplateStringsArray, ...interpolations: u
|
|
|
133
146
|
declare function stripIndents(options: StripIndentsOptions): StripIndentsFunction;
|
|
134
147
|
declare function stripIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
|
|
135
148
|
|
|
136
|
-
export { APIError, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, type DisallowUndefined, type Email, type Env, type FormDataNullableResolutionStrategy as FormDataResolutionStrategy, type HTTPErrorCode, type HTTPErrorCodes, type IgnoreCase, type KebabToCamelOptions, type NonUndefined, type OptionalOnCondition, type RecordKey, type RemoveIndentsFunction, type RemoveIndentsOptions, type StringListToArrayOptions, type StripIndentsFunction, type StripIndentsOptions, type UUID, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, httpErrorCodeLookup, interpolate, interpolateObjects, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normalizeImportPath, omitProperties, paralleliseArrays, parseEmail, parseEnv, parseIntStrict, parseUUID, randomiseArray, range, removeDuplicates, removeIndents, stringListToArray, stringToBoolean, stripIndents, truncate, wait };
|
|
149
|
+
export { APIError, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, DataError, type DisallowUndefined, type Email, type Env, type FormDataNullableResolutionStrategy as FormDataResolutionStrategy, type HTTPErrorCode, type HTTPErrorCodes, type IgnoreCase, type KebabToCamelOptions, type NonUndefined, type OptionalOnCondition, type RecordKey, type RemoveIndentsFunction, type RemoveIndentsOptions, type StringListToArrayOptions, type StripIndentsFunction, type StripIndentsOptions, type UUID, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, httpErrorCodeLookup, interpolate, interpolateObjects, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normalizeImportPath, omitProperties, paralleliseArrays, parseEmail, parseEnv, parseIntStrict, parseUUID, parseZodSchema, randomiseArray, range, removeDuplicates, removeIndents, stringListToArray, stringToBoolean, stripIndents, truncate, wait };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import z, { z as z$1 } from 'zod';
|
|
1
|
+
import z, { z as z$1, core, ZodType } from 'zod';
|
|
2
2
|
|
|
3
3
|
declare function addDaysToDate(currentDate?: Date, dayIncrement?: number): Date;
|
|
4
4
|
|
|
@@ -18,6 +18,17 @@ declare class APIError extends Error {
|
|
|
18
18
|
static check(input: unknown): input is APIError;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
declare class DataError extends Error {
|
|
22
|
+
data: unknown;
|
|
23
|
+
code: string;
|
|
24
|
+
/** @param data - The data that caused the error. */
|
|
25
|
+
/** @param message - A human-readable error message (e.g. The data provided is invalid). */
|
|
26
|
+
/** @param code - A standardised code (e.g. UNEXPECTED_DATA). */
|
|
27
|
+
/** @param options - Extra options to pass to super Error constructor. */
|
|
28
|
+
constructor(data: unknown, message?: string, code?: string, options?: ErrorOptions);
|
|
29
|
+
static check(input: unknown): input is DataError;
|
|
30
|
+
}
|
|
31
|
+
|
|
21
32
|
declare const emailSchema: z.core.$ZodBranded<z.ZodEmail, "Email">;
|
|
22
33
|
type Email = z.infer<typeof emailSchema>;
|
|
23
34
|
declare function parseEmail(data: unknown): Email;
|
|
@@ -96,6 +107,8 @@ declare function paralleliseArrays<FirstArrayItem, SecondArrayItem>(firstArray:
|
|
|
96
107
|
|
|
97
108
|
declare function parseIntStrict(...[string, radix]: Parameters<typeof parseInt>): number;
|
|
98
109
|
|
|
110
|
+
declare function parseZodSchema<Output, Input, Internals extends core.$ZodTypeInternals<Output, Input>>(schema: ZodType<Output, Input, Internals>, data: unknown): core.output<ZodType<Output, Input, Internals>>;
|
|
111
|
+
|
|
99
112
|
declare function randomiseArray<T>(array: T[]): T[];
|
|
100
113
|
|
|
101
114
|
declare function range(start: number, stop: number, step?: number): number[];
|
|
@@ -133,4 +146,4 @@ type StripIndentsFunction = (strings: TemplateStringsArray, ...interpolations: u
|
|
|
133
146
|
declare function stripIndents(options: StripIndentsOptions): StripIndentsFunction;
|
|
134
147
|
declare function stripIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
|
|
135
148
|
|
|
136
|
-
export { APIError, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, type DisallowUndefined, type Email, type Env, type FormDataNullableResolutionStrategy as FormDataResolutionStrategy, type HTTPErrorCode, type HTTPErrorCodes, type IgnoreCase, type KebabToCamelOptions, type NonUndefined, type OptionalOnCondition, type RecordKey, type RemoveIndentsFunction, type RemoveIndentsOptions, type StringListToArrayOptions, type StripIndentsFunction, type StripIndentsOptions, type UUID, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, httpErrorCodeLookup, interpolate, interpolateObjects, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normalizeImportPath, omitProperties, paralleliseArrays, parseEmail, parseEnv, parseIntStrict, parseUUID, randomiseArray, range, removeDuplicates, removeIndents, stringListToArray, stringToBoolean, stripIndents, truncate, wait };
|
|
149
|
+
export { APIError, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, DataError, type DisallowUndefined, type Email, type Env, type FormDataNullableResolutionStrategy as FormDataResolutionStrategy, type HTTPErrorCode, type HTTPErrorCodes, type IgnoreCase, type KebabToCamelOptions, type NonUndefined, type OptionalOnCondition, type RecordKey, type RemoveIndentsFunction, type RemoveIndentsOptions, type StringListToArrayOptions, type StripIndentsFunction, type StripIndentsOptions, type UUID, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, httpErrorCodeLookup, interpolate, interpolateObjects, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normalizeImportPath, omitProperties, paralleliseArrays, parseEmail, parseEnv, parseIntStrict, parseUUID, parseZodSchema, randomiseArray, range, removeDuplicates, removeIndents, stringListToArray, stringToBoolean, stripIndents, truncate, wait };
|
package/dist/index.js
CHANGED
|
@@ -357,6 +357,98 @@ function paralleliseArrays(firstArray, secondArray) {
|
|
|
357
357
|
}
|
|
358
358
|
var paralleliseArrays_default = paralleliseArrays;
|
|
359
359
|
|
|
360
|
+
// src/types/APIError.ts
|
|
361
|
+
var httpErrorCodeLookup = {
|
|
362
|
+
400: "BAD_REQUEST",
|
|
363
|
+
401: "UNAUTHORISED",
|
|
364
|
+
403: "FORBIDDEN",
|
|
365
|
+
404: "NOT_FOUND",
|
|
366
|
+
/* Supporting this one too because it's funny. You'll never use it in practice because
|
|
367
|
+
why would an error give a teapot, but it's funny. Do not question me. */
|
|
368
|
+
418: "I_AM_A_TEAPOT",
|
|
369
|
+
500: "INTERNAL_SERVER_ERROR"
|
|
370
|
+
};
|
|
371
|
+
var APIError = class extends Error {
|
|
372
|
+
constructor(status = 500, message, options) {
|
|
373
|
+
var _a;
|
|
374
|
+
super(message, options);
|
|
375
|
+
__publicField(this, "status");
|
|
376
|
+
this.status = status;
|
|
377
|
+
if (message) {
|
|
378
|
+
this.message = message;
|
|
379
|
+
} else {
|
|
380
|
+
this.message = (_a = httpErrorCodeLookup[this.status]) != null ? _a : "API_ERROR";
|
|
381
|
+
}
|
|
382
|
+
Object.defineProperty(this, "message", { enumerable: true });
|
|
383
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
384
|
+
}
|
|
385
|
+
static check(input) {
|
|
386
|
+
const data = input;
|
|
387
|
+
return typeof data === "object" && data !== null && typeof (data == null ? void 0 : data.status) === "number" && typeof (data == null ? void 0 : data.message) === "string";
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
var APIError_default = APIError;
|
|
391
|
+
|
|
392
|
+
// src/types/DataError.ts
|
|
393
|
+
var DataError = class extends Error {
|
|
394
|
+
/** @param data - The data that caused the error. */
|
|
395
|
+
/** @param message - A human-readable error message (e.g. The data provided is invalid). */
|
|
396
|
+
/** @param code - A standardised code (e.g. UNEXPECTED_DATA). */
|
|
397
|
+
/** @param options - Extra options to pass to super Error constructor. */
|
|
398
|
+
constructor(data, message = "The data provided is invalid", code = "INVALID_DATA", options) {
|
|
399
|
+
super(message, options);
|
|
400
|
+
__publicField(this, "data");
|
|
401
|
+
__publicField(this, "code");
|
|
402
|
+
if (Error.captureStackTrace) {
|
|
403
|
+
Error.captureStackTrace(this, new.target);
|
|
404
|
+
}
|
|
405
|
+
this.name = new.target.name;
|
|
406
|
+
this.code = code;
|
|
407
|
+
this.data = data;
|
|
408
|
+
Object.defineProperty(this, "message", { enumerable: true });
|
|
409
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
410
|
+
}
|
|
411
|
+
static check(input) {
|
|
412
|
+
const data = input;
|
|
413
|
+
return typeof data === "object" && data !== null && typeof data.message === "string" && typeof data.code === "string" && "data" in data;
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
var DataError_default = DataError;
|
|
417
|
+
|
|
418
|
+
// src/types/Email.ts
|
|
419
|
+
import z from "zod";
|
|
420
|
+
var emailSchema = z.email().brand();
|
|
421
|
+
function parseEmail(data) {
|
|
422
|
+
return emailSchema.parse(data);
|
|
423
|
+
}
|
|
424
|
+
var Email_default = parseEmail;
|
|
425
|
+
|
|
426
|
+
// src/types/Env.ts
|
|
427
|
+
import { z as z2 } from "zod";
|
|
428
|
+
var envSchema = z2.enum(["test", "development", "production"]);
|
|
429
|
+
function parseEnv(data = "development") {
|
|
430
|
+
return envSchema.parse(data);
|
|
431
|
+
}
|
|
432
|
+
var Env_default = parseEnv;
|
|
433
|
+
|
|
434
|
+
// src/types/UUID.ts
|
|
435
|
+
import z3 from "zod";
|
|
436
|
+
var uuidSchema = z3.uuid().brand();
|
|
437
|
+
function parseUUID(UUID) {
|
|
438
|
+
return uuidSchema.parse(UUID);
|
|
439
|
+
}
|
|
440
|
+
var UUID_default = parseUUID;
|
|
441
|
+
|
|
442
|
+
// src/functions/parseZodSchema.ts
|
|
443
|
+
function parseZodSchema(schema, data) {
|
|
444
|
+
const parsedResult = schema.safeParse(data);
|
|
445
|
+
if (!parsedResult.success) {
|
|
446
|
+
throw new DataError_default(data);
|
|
447
|
+
}
|
|
448
|
+
return parsedResult.data;
|
|
449
|
+
}
|
|
450
|
+
var parseZodSchema_default = parseZodSchema;
|
|
451
|
+
|
|
360
452
|
// src/functions/randomiseArray.ts
|
|
361
453
|
function randomiseArray(array) {
|
|
362
454
|
const mutableArray = [...array];
|
|
@@ -540,64 +632,9 @@ function stripIndents(first, ...args) {
|
|
|
540
632
|
return reduceLines2(fullString.split("\n"), options);
|
|
541
633
|
}
|
|
542
634
|
var stripIndents_default = stripIndents;
|
|
543
|
-
|
|
544
|
-
// src/types/APIError.ts
|
|
545
|
-
var httpErrorCodeLookup = {
|
|
546
|
-
400: "BAD_REQUEST",
|
|
547
|
-
401: "UNAUTHORISED",
|
|
548
|
-
403: "FORBIDDEN",
|
|
549
|
-
404: "NOT_FOUND",
|
|
550
|
-
/* Supporting this one too because it's funny. You'll never use it in practice because
|
|
551
|
-
why would an error give a teapot, but it's funny. Do not question me. */
|
|
552
|
-
418: "I_AM_A_TEAPOT",
|
|
553
|
-
500: "INTERNAL_SERVER_ERROR"
|
|
554
|
-
};
|
|
555
|
-
var APIError = class extends Error {
|
|
556
|
-
constructor(status = 500, message, options) {
|
|
557
|
-
var _a;
|
|
558
|
-
super(message, options);
|
|
559
|
-
__publicField(this, "status");
|
|
560
|
-
this.status = status;
|
|
561
|
-
if (message) {
|
|
562
|
-
this.message = message;
|
|
563
|
-
} else {
|
|
564
|
-
this.message = (_a = httpErrorCodeLookup[this.status]) != null ? _a : "API_ERROR";
|
|
565
|
-
}
|
|
566
|
-
Object.defineProperty(this, "message", { enumerable: true });
|
|
567
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
568
|
-
}
|
|
569
|
-
static check(input) {
|
|
570
|
-
const data = input;
|
|
571
|
-
return typeof data === "object" && data !== null && typeof (data == null ? void 0 : data.status) === "number" && typeof (data == null ? void 0 : data.message) === "string";
|
|
572
|
-
}
|
|
573
|
-
};
|
|
574
|
-
var APIError_default = APIError;
|
|
575
|
-
|
|
576
|
-
// src/types/Email.ts
|
|
577
|
-
import z from "zod";
|
|
578
|
-
var emailSchema = z.email().brand();
|
|
579
|
-
function parseEmail(data) {
|
|
580
|
-
return emailSchema.parse(data);
|
|
581
|
-
}
|
|
582
|
-
var Email_default = parseEmail;
|
|
583
|
-
|
|
584
|
-
// src/types/Env.ts
|
|
585
|
-
import { z as z2 } from "zod";
|
|
586
|
-
var envSchema = z2.enum(["test", "development", "production"]);
|
|
587
|
-
function parseEnv(data = "development") {
|
|
588
|
-
return envSchema.parse(data);
|
|
589
|
-
}
|
|
590
|
-
var Env_default = parseEnv;
|
|
591
|
-
|
|
592
|
-
// src/types/UUID.ts
|
|
593
|
-
import z3 from "zod";
|
|
594
|
-
var uuidSchema = z3.uuid().brand();
|
|
595
|
-
function parseUUID(UUID) {
|
|
596
|
-
return uuidSchema.parse(UUID);
|
|
597
|
-
}
|
|
598
|
-
var UUID_default = parseUUID;
|
|
599
635
|
export {
|
|
600
636
|
APIError_default as APIError,
|
|
637
|
+
DataError_default as DataError,
|
|
601
638
|
addDaysToDate_default as addDaysToDate,
|
|
602
639
|
appendSemicolon_default as appendSemicolon,
|
|
603
640
|
camelToKebab_default as camelToKebab,
|
|
@@ -624,6 +661,7 @@ export {
|
|
|
624
661
|
Env_default as parseEnv,
|
|
625
662
|
parseIntStrict_default as parseIntStrict,
|
|
626
663
|
UUID_default as parseUUID,
|
|
664
|
+
parseZodSchema_default as parseZodSchema,
|
|
627
665
|
randomiseArray_default as randomiseArray,
|
|
628
666
|
range_default as range,
|
|
629
667
|
removeDuplicates_default as removeDuplicates,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alextheman/utility",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.21.0",
|
|
4
4
|
"description": "Helpful utility functions",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,13 +34,15 @@
|
|
|
34
34
|
"prepare": "husky",
|
|
35
35
|
"test": "vitest run",
|
|
36
36
|
"test-watch": "vitest",
|
|
37
|
-
"update-dependencies": "bash -c 'npx npm-check-updates -u \"$@\" && npm install' --"
|
|
37
|
+
"update-dependencies": "bash -c 'npx npm-check-updates -u \"$@\" && npm install' --",
|
|
38
|
+
"use-live-eslint-plugin": "npm uninstall @alextheman/eslint-plugin && npm install --save-dev @alextheman/eslint-plugin",
|
|
39
|
+
"use-local-eslint-plugin": "npm --prefix ../eslint-plugin run create-local-package && npm uninstall @alextheman/eslint-plugin && npm install --save-dev ../eslint-plugin/alextheman-eslint-plugin-*.tgz"
|
|
38
40
|
},
|
|
39
41
|
"dependencies": {
|
|
40
42
|
"zod": "^4.1.12"
|
|
41
43
|
},
|
|
42
44
|
"devDependencies": {
|
|
43
|
-
"@alextheman/eslint-plugin": "^
|
|
45
|
+
"@alextheman/eslint-plugin": "^4.1.0",
|
|
44
46
|
"@types/node": "^24.10.1",
|
|
45
47
|
"eslint": "^9.39.1",
|
|
46
48
|
"globals": "^16.5.0",
|