@alextheman/utility 2.19.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 +112 -56
- package/dist/index.d.cts +18 -2
- package/dist/index.d.ts +18 -2
- package/dist/index.js +108 -56
- package/package.json +6 -4
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,
|
|
@@ -64,12 +65,15 @@ __export(index_exports, {
|
|
|
64
65
|
isOrdered: () => isOrdered_default,
|
|
65
66
|
isSameDate: () => isSameDate_default,
|
|
66
67
|
kebabToCamel: () => kebabToCamel_default,
|
|
68
|
+
normaliseImportPath: () => normaliseImportPath,
|
|
69
|
+
normalizeImportPath: () => normalizeImportPath_default,
|
|
67
70
|
omitProperties: () => omitProperties_default,
|
|
68
71
|
paralleliseArrays: () => paralleliseArrays_default,
|
|
69
72
|
parseEmail: () => Email_default,
|
|
70
73
|
parseEnv: () => Env_default,
|
|
71
74
|
parseIntStrict: () => parseIntStrict_default,
|
|
72
75
|
parseUUID: () => UUID_default,
|
|
76
|
+
parseZodSchema: () => parseZodSchema_default,
|
|
73
77
|
randomiseArray: () => randomiseArray_default,
|
|
74
78
|
range: () => range_default,
|
|
75
79
|
removeDuplicates: () => removeDuplicates_default,
|
|
@@ -390,6 +394,18 @@ function kebabToCamel(string, options) {
|
|
|
390
394
|
}
|
|
391
395
|
var kebabToCamel_default = kebabToCamel;
|
|
392
396
|
|
|
397
|
+
// src/functions/normalizeImportPath.ts
|
|
398
|
+
var import_path = __toESM(require("path"), 1);
|
|
399
|
+
function normalizeImportPath(importPath) {
|
|
400
|
+
const normalizedPath = import_path.default.posix.normalize(importPath);
|
|
401
|
+
if (importPath.startsWith("./") && !normalizedPath.startsWith("./")) {
|
|
402
|
+
return `./${normalizedPath}`;
|
|
403
|
+
}
|
|
404
|
+
return normalizedPath;
|
|
405
|
+
}
|
|
406
|
+
var normaliseImportPath = normalizeImportPath;
|
|
407
|
+
var normalizeImportPath_default = normalizeImportPath;
|
|
408
|
+
|
|
393
409
|
// src/functions/omitProperties.ts
|
|
394
410
|
function omitProperties(object, keysToOmit) {
|
|
395
411
|
const outputObject = __spreadValues({}, object);
|
|
@@ -411,6 +427,98 @@ function paralleliseArrays(firstArray, secondArray) {
|
|
|
411
427
|
}
|
|
412
428
|
var paralleliseArrays_default = paralleliseArrays;
|
|
413
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
|
+
|
|
414
522
|
// src/functions/randomiseArray.ts
|
|
415
523
|
function randomiseArray(array) {
|
|
416
524
|
const mutableArray = [...array];
|
|
@@ -594,65 +702,10 @@ function stripIndents(first, ...args) {
|
|
|
594
702
|
return reduceLines2(fullString.split("\n"), options);
|
|
595
703
|
}
|
|
596
704
|
var stripIndents_default = stripIndents;
|
|
597
|
-
|
|
598
|
-
// src/types/APIError.ts
|
|
599
|
-
var httpErrorCodeLookup = {
|
|
600
|
-
400: "BAD_REQUEST",
|
|
601
|
-
401: "UNAUTHORISED",
|
|
602
|
-
403: "FORBIDDEN",
|
|
603
|
-
404: "NOT_FOUND",
|
|
604
|
-
/* Supporting this one too because it's funny. You'll never use it in practice because
|
|
605
|
-
why would an error give a teapot, but it's funny. Do not question me. */
|
|
606
|
-
418: "I_AM_A_TEAPOT",
|
|
607
|
-
500: "INTERNAL_SERVER_ERROR"
|
|
608
|
-
};
|
|
609
|
-
var APIError = class extends Error {
|
|
610
|
-
constructor(status = 500, message, options) {
|
|
611
|
-
var _a;
|
|
612
|
-
super(message, options);
|
|
613
|
-
__publicField(this, "status");
|
|
614
|
-
this.status = status;
|
|
615
|
-
if (message) {
|
|
616
|
-
this.message = message;
|
|
617
|
-
} else {
|
|
618
|
-
this.message = (_a = httpErrorCodeLookup[this.status]) != null ? _a : "API_ERROR";
|
|
619
|
-
}
|
|
620
|
-
Object.defineProperty(this, "message", { enumerable: true });
|
|
621
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
622
|
-
}
|
|
623
|
-
static check(input) {
|
|
624
|
-
const data = input;
|
|
625
|
-
return typeof data === "object" && data !== null && typeof (data == null ? void 0 : data.status) === "number" && typeof (data == null ? void 0 : data.message) === "string";
|
|
626
|
-
}
|
|
627
|
-
};
|
|
628
|
-
var APIError_default = APIError;
|
|
629
|
-
|
|
630
|
-
// src/types/Email.ts
|
|
631
|
-
var import_zod = __toESM(require("zod"), 1);
|
|
632
|
-
var emailSchema = import_zod.default.email().brand();
|
|
633
|
-
function parseEmail(data) {
|
|
634
|
-
return emailSchema.parse(data);
|
|
635
|
-
}
|
|
636
|
-
var Email_default = parseEmail;
|
|
637
|
-
|
|
638
|
-
// src/types/Env.ts
|
|
639
|
-
var import_zod2 = require("zod");
|
|
640
|
-
var envSchema = import_zod2.z.enum(["test", "development", "production"]);
|
|
641
|
-
function parseEnv(data = "development") {
|
|
642
|
-
return envSchema.parse(data);
|
|
643
|
-
}
|
|
644
|
-
var Env_default = parseEnv;
|
|
645
|
-
|
|
646
|
-
// src/types/UUID.ts
|
|
647
|
-
var import_zod3 = __toESM(require("zod"), 1);
|
|
648
|
-
var uuidSchema = import_zod3.default.uuid().brand();
|
|
649
|
-
function parseUUID(UUID) {
|
|
650
|
-
return uuidSchema.parse(UUID);
|
|
651
|
-
}
|
|
652
|
-
var UUID_default = parseUUID;
|
|
653
705
|
// Annotate the CommonJS export names for ESM import in node:
|
|
654
706
|
0 && (module.exports = {
|
|
655
707
|
APIError,
|
|
708
|
+
DataError,
|
|
656
709
|
addDaysToDate,
|
|
657
710
|
appendSemicolon,
|
|
658
711
|
camelToKebab,
|
|
@@ -671,12 +724,15 @@ var UUID_default = parseUUID;
|
|
|
671
724
|
isOrdered,
|
|
672
725
|
isSameDate,
|
|
673
726
|
kebabToCamel,
|
|
727
|
+
normaliseImportPath,
|
|
728
|
+
normalizeImportPath,
|
|
674
729
|
omitProperties,
|
|
675
730
|
paralleliseArrays,
|
|
676
731
|
parseEmail,
|
|
677
732
|
parseEnv,
|
|
678
733
|
parseIntStrict,
|
|
679
734
|
parseUUID,
|
|
735
|
+
parseZodSchema,
|
|
680
736
|
randomiseArray,
|
|
681
737
|
range,
|
|
682
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;
|
|
@@ -86,6 +97,9 @@ interface KebabToCamelOptions {
|
|
|
86
97
|
}
|
|
87
98
|
declare function kebabToCamel(string: string, options?: KebabToCamelOptions): string;
|
|
88
99
|
|
|
100
|
+
declare function normalizeImportPath(importPath: string): string;
|
|
101
|
+
declare const normaliseImportPath: typeof normalizeImportPath;
|
|
102
|
+
|
|
89
103
|
declare function omitProperties<T extends Record<string, unknown> | Readonly<Record<string, unknown>>, K extends keyof T>(object: T, keysToOmit: K | readonly K[]): Omit<T, K>;
|
|
90
104
|
|
|
91
105
|
type ParallelTuple<A, B> = [A, B | undefined];
|
|
@@ -93,6 +107,8 @@ declare function paralleliseArrays<FirstArrayItem, SecondArrayItem>(firstArray:
|
|
|
93
107
|
|
|
94
108
|
declare function parseIntStrict(...[string, radix]: Parameters<typeof parseInt>): number;
|
|
95
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
|
+
|
|
96
112
|
declare function randomiseArray<T>(array: T[]): T[];
|
|
97
113
|
|
|
98
114
|
declare function range(start: number, stop: number, step?: number): number[];
|
|
@@ -130,4 +146,4 @@ type StripIndentsFunction = (strings: TemplateStringsArray, ...interpolations: u
|
|
|
130
146
|
declare function stripIndents(options: StripIndentsOptions): StripIndentsFunction;
|
|
131
147
|
declare function stripIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
|
|
132
148
|
|
|
133
|
-
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, 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;
|
|
@@ -86,6 +97,9 @@ interface KebabToCamelOptions {
|
|
|
86
97
|
}
|
|
87
98
|
declare function kebabToCamel(string: string, options?: KebabToCamelOptions): string;
|
|
88
99
|
|
|
100
|
+
declare function normalizeImportPath(importPath: string): string;
|
|
101
|
+
declare const normaliseImportPath: typeof normalizeImportPath;
|
|
102
|
+
|
|
89
103
|
declare function omitProperties<T extends Record<string, unknown> | Readonly<Record<string, unknown>>, K extends keyof T>(object: T, keysToOmit: K | readonly K[]): Omit<T, K>;
|
|
90
104
|
|
|
91
105
|
type ParallelTuple<A, B> = [A, B | undefined];
|
|
@@ -93,6 +107,8 @@ declare function paralleliseArrays<FirstArrayItem, SecondArrayItem>(firstArray:
|
|
|
93
107
|
|
|
94
108
|
declare function parseIntStrict(...[string, radix]: Parameters<typeof parseInt>): number;
|
|
95
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
|
+
|
|
96
112
|
declare function randomiseArray<T>(array: T[]): T[];
|
|
97
113
|
|
|
98
114
|
declare function range(start: number, stop: number, step?: number): number[];
|
|
@@ -130,4 +146,4 @@ type StripIndentsFunction = (strings: TemplateStringsArray, ...interpolations: u
|
|
|
130
146
|
declare function stripIndents(options: StripIndentsOptions): StripIndentsFunction;
|
|
131
147
|
declare function stripIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
|
|
132
148
|
|
|
133
|
-
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, 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
|
@@ -324,6 +324,18 @@ function kebabToCamel(string, options) {
|
|
|
324
324
|
}
|
|
325
325
|
var kebabToCamel_default = kebabToCamel;
|
|
326
326
|
|
|
327
|
+
// src/functions/normalizeImportPath.ts
|
|
328
|
+
import path from "path";
|
|
329
|
+
function normalizeImportPath(importPath) {
|
|
330
|
+
const normalizedPath = path.posix.normalize(importPath);
|
|
331
|
+
if (importPath.startsWith("./") && !normalizedPath.startsWith("./")) {
|
|
332
|
+
return `./${normalizedPath}`;
|
|
333
|
+
}
|
|
334
|
+
return normalizedPath;
|
|
335
|
+
}
|
|
336
|
+
var normaliseImportPath = normalizeImportPath;
|
|
337
|
+
var normalizeImportPath_default = normalizeImportPath;
|
|
338
|
+
|
|
327
339
|
// src/functions/omitProperties.ts
|
|
328
340
|
function omitProperties(object, keysToOmit) {
|
|
329
341
|
const outputObject = __spreadValues({}, object);
|
|
@@ -345,6 +357,98 @@ function paralleliseArrays(firstArray, secondArray) {
|
|
|
345
357
|
}
|
|
346
358
|
var paralleliseArrays_default = paralleliseArrays;
|
|
347
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
|
+
|
|
348
452
|
// src/functions/randomiseArray.ts
|
|
349
453
|
function randomiseArray(array) {
|
|
350
454
|
const mutableArray = [...array];
|
|
@@ -528,64 +632,9 @@ function stripIndents(first, ...args) {
|
|
|
528
632
|
return reduceLines2(fullString.split("\n"), options);
|
|
529
633
|
}
|
|
530
634
|
var stripIndents_default = stripIndents;
|
|
531
|
-
|
|
532
|
-
// src/types/APIError.ts
|
|
533
|
-
var httpErrorCodeLookup = {
|
|
534
|
-
400: "BAD_REQUEST",
|
|
535
|
-
401: "UNAUTHORISED",
|
|
536
|
-
403: "FORBIDDEN",
|
|
537
|
-
404: "NOT_FOUND",
|
|
538
|
-
/* Supporting this one too because it's funny. You'll never use it in practice because
|
|
539
|
-
why would an error give a teapot, but it's funny. Do not question me. */
|
|
540
|
-
418: "I_AM_A_TEAPOT",
|
|
541
|
-
500: "INTERNAL_SERVER_ERROR"
|
|
542
|
-
};
|
|
543
|
-
var APIError = class extends Error {
|
|
544
|
-
constructor(status = 500, message, options) {
|
|
545
|
-
var _a;
|
|
546
|
-
super(message, options);
|
|
547
|
-
__publicField(this, "status");
|
|
548
|
-
this.status = status;
|
|
549
|
-
if (message) {
|
|
550
|
-
this.message = message;
|
|
551
|
-
} else {
|
|
552
|
-
this.message = (_a = httpErrorCodeLookup[this.status]) != null ? _a : "API_ERROR";
|
|
553
|
-
}
|
|
554
|
-
Object.defineProperty(this, "message", { enumerable: true });
|
|
555
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
556
|
-
}
|
|
557
|
-
static check(input) {
|
|
558
|
-
const data = input;
|
|
559
|
-
return typeof data === "object" && data !== null && typeof (data == null ? void 0 : data.status) === "number" && typeof (data == null ? void 0 : data.message) === "string";
|
|
560
|
-
}
|
|
561
|
-
};
|
|
562
|
-
var APIError_default = APIError;
|
|
563
|
-
|
|
564
|
-
// src/types/Email.ts
|
|
565
|
-
import z from "zod";
|
|
566
|
-
var emailSchema = z.email().brand();
|
|
567
|
-
function parseEmail(data) {
|
|
568
|
-
return emailSchema.parse(data);
|
|
569
|
-
}
|
|
570
|
-
var Email_default = parseEmail;
|
|
571
|
-
|
|
572
|
-
// src/types/Env.ts
|
|
573
|
-
import { z as z2 } from "zod";
|
|
574
|
-
var envSchema = z2.enum(["test", "development", "production"]);
|
|
575
|
-
function parseEnv(data = "development") {
|
|
576
|
-
return envSchema.parse(data);
|
|
577
|
-
}
|
|
578
|
-
var Env_default = parseEnv;
|
|
579
|
-
|
|
580
|
-
// src/types/UUID.ts
|
|
581
|
-
import z3 from "zod";
|
|
582
|
-
var uuidSchema = z3.uuid().brand();
|
|
583
|
-
function parseUUID(UUID) {
|
|
584
|
-
return uuidSchema.parse(UUID);
|
|
585
|
-
}
|
|
586
|
-
var UUID_default = parseUUID;
|
|
587
635
|
export {
|
|
588
636
|
APIError_default as APIError,
|
|
637
|
+
DataError_default as DataError,
|
|
589
638
|
addDaysToDate_default as addDaysToDate,
|
|
590
639
|
appendSemicolon_default as appendSemicolon,
|
|
591
640
|
camelToKebab_default as camelToKebab,
|
|
@@ -604,12 +653,15 @@ export {
|
|
|
604
653
|
isOrdered_default as isOrdered,
|
|
605
654
|
isSameDate_default as isSameDate,
|
|
606
655
|
kebabToCamel_default as kebabToCamel,
|
|
656
|
+
normaliseImportPath,
|
|
657
|
+
normalizeImportPath_default as normalizeImportPath,
|
|
607
658
|
omitProperties_default as omitProperties,
|
|
608
659
|
paralleliseArrays_default as paralleliseArrays,
|
|
609
660
|
Email_default as parseEmail,
|
|
610
661
|
Env_default as parseEnv,
|
|
611
662
|
parseIntStrict_default as parseIntStrict,
|
|
612
663
|
UUID_default as parseUUID,
|
|
664
|
+
parseZodSchema_default as parseZodSchema,
|
|
613
665
|
randomiseArray_default as randomiseArray,
|
|
614
666
|
range_default as range,
|
|
615
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",
|
|
@@ -50,6 +52,6 @@
|
|
|
50
52
|
"tsup": "^8.5.1",
|
|
51
53
|
"typescript": "^5.9.3",
|
|
52
54
|
"vite-tsconfig-paths": "^5.1.4",
|
|
53
|
-
"vitest": "^4.0.
|
|
55
|
+
"vitest": "^4.0.13"
|
|
54
56
|
}
|
|
55
57
|
}
|