@alextheman/utility 2.20.0 → 3.0.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.js CHANGED
@@ -1,636 +1,521 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
- var __hasOwnProp = Object.prototype.hasOwnProperty;
4
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __spreadValues = (a, b) => {
7
- for (var prop in b || (b = {}))
8
- if (__hasOwnProp.call(b, prop))
9
- __defNormalProp(a, prop, b[prop]);
10
- if (__getOwnPropSymbols)
11
- for (var prop of __getOwnPropSymbols(b)) {
12
- if (__propIsEnum.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- }
15
- return a;
16
- };
17
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1
+ import path from "path";
2
+ import z, { z as z$1 } from "zod";
18
3
 
19
- // src/functions/addDaysToDate.ts
4
+ //#region src/functions/addDaysToDate.ts
20
5
  function addDaysToDate(currentDate = /* @__PURE__ */ new Date(), dayIncrement = 1) {
21
- const newDate = currentDate;
22
- newDate.setDate(newDate.getDate() + dayIncrement);
23
- return newDate;
6
+ const newDate = currentDate;
7
+ newDate.setDate(newDate.getDate() + dayIncrement);
8
+ return newDate;
24
9
  }
25
10
  var addDaysToDate_default = addDaysToDate;
26
11
 
27
- // src/functions/appendSemicolon.ts
12
+ //#endregion
13
+ //#region src/functions/appendSemicolon.ts
28
14
  function appendSemicolon(stringToAppendTo) {
29
- if (stringToAppendTo.includes("\n")) {
30
- throw new Error("MULTIPLE_LINE_ERROR");
31
- }
32
- const stringWithNoTrailingWhitespace = stringToAppendTo.trimEnd();
33
- if (stringWithNoTrailingWhitespace === "") {
34
- return "";
35
- }
36
- return stringWithNoTrailingWhitespace[stringWithNoTrailingWhitespace.length - 1] === ";" ? stringWithNoTrailingWhitespace : `${stringWithNoTrailingWhitespace};`;
15
+ if (stringToAppendTo.includes("\n")) throw new Error("MULTIPLE_LINE_ERROR");
16
+ const stringWithNoTrailingWhitespace = stringToAppendTo.trimEnd();
17
+ if (stringWithNoTrailingWhitespace === "") return "";
18
+ return stringWithNoTrailingWhitespace[stringWithNoTrailingWhitespace.length - 1] === ";" ? stringWithNoTrailingWhitespace : `${stringWithNoTrailingWhitespace};`;
37
19
  }
38
20
  var appendSemicolon_default = appendSemicolon;
39
21
 
40
- // src/functions/camelToKebab.ts
22
+ //#endregion
23
+ //#region src/functions/camelToKebab.ts
41
24
  function camelToKebab(string) {
42
- return string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([A-Z])([A-Z][a-z])/g, "$1-$2").toLowerCase();
25
+ return string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([A-Z])([A-Z][a-z])/g, "$1-$2").toLowerCase();
43
26
  }
44
27
  var camelToKebab_default = camelToKebab;
45
28
 
46
- // src/functions/convertFileToBase64.ts
29
+ //#endregion
30
+ //#region src/functions/convertFileToBase64.ts
47
31
  function convertFileToBase64(file) {
48
- return new Promise((resolve, reject) => {
49
- const reader = new FileReader();
50
- reader.readAsDataURL(file);
51
- reader.onload = () => {
52
- if (reader.result === null) {
53
- reject(new Error("FILE_CONVERSION_ERROR"));
54
- return;
55
- }
56
- resolve(reader.result);
57
- };
58
- reader.onerror = () => {
59
- reject(new Error("FILE_READER_ERROR"));
60
- };
61
- });
32
+ return new Promise((resolve, reject) => {
33
+ const reader = new FileReader();
34
+ reader.readAsDataURL(file);
35
+ reader.onload = () => {
36
+ if (reader.result === null) {
37
+ reject(/* @__PURE__ */ new Error("FILE_CONVERSION_ERROR"));
38
+ return;
39
+ }
40
+ resolve(reader.result);
41
+ };
42
+ reader.onerror = () => {
43
+ reject(/* @__PURE__ */ new Error("FILE_READER_ERROR"));
44
+ };
45
+ });
62
46
  }
63
47
  var convertFileToBase64_default = convertFileToBase64;
64
48
 
65
- // src/functions/createFormData.ts
49
+ //#endregion
50
+ //#region src/functions/createFormData.ts
66
51
  function getNullableResolutionStrategy(key, strategy) {
67
- var _a;
68
- return (_a = typeof strategy === "object" ? strategy[key] : strategy) != null ? _a : "empty";
52
+ return (typeof strategy === "object" ? strategy[key] : strategy) ?? "empty";
69
53
  }
70
54
  function createFormData(data, options = {
71
- arrayResolution: "stringify",
72
- nullableResolution: "empty"
55
+ arrayResolution: "stringify",
56
+ nullableResolution: "empty"
73
57
  }) {
74
- const formData = new FormData();
75
- function resolveNullablesByStrategy(key, value, resolutionStrategy) {
76
- switch (resolutionStrategy) {
77
- case "empty":
78
- formData.append(String(key), "");
79
- break;
80
- case "stringify":
81
- formData.append(String(key), JSON.stringify(value));
82
- break;
83
- case "omit":
84
- break;
85
- default:
86
- throw new TypeError("SLOPPY_PURE_JAVASCRIPT_USER_ERROR");
87
- }
88
- }
89
- function resolveNullables(key, value, options2) {
90
- if (options2.nullableResolution) {
91
- resolveNullablesByStrategy(
92
- key,
93
- value,
94
- getNullableResolutionStrategy(key, options2.nullableResolution)
95
- );
96
- return;
97
- }
98
- if (options2.undefinedResolution || options2.nullResolution) {
99
- if (data[key] === void 0 && options2.undefinedResolution) {
100
- resolveNullablesByStrategy(
101
- key,
102
- value,
103
- getNullableResolutionStrategy(key, options2.undefinedResolution)
104
- );
105
- return;
106
- }
107
- if (data[key] === null && options2.nullResolution) {
108
- resolveNullablesByStrategy(
109
- key,
110
- value,
111
- getNullableResolutionStrategy(key, options2.nullResolution)
112
- );
113
- }
114
- }
115
- }
116
- const entries = Object.entries(data);
117
- for (const [key, value] of entries) {
118
- if (value instanceof Blob) {
119
- formData.append(String(key), value);
120
- } else if (value === void 0 || value === null) {
121
- resolveNullables(key, value, options);
122
- } else if (typeof value === "object") {
123
- if (Array.isArray(value)) {
124
- if (value.some((item) => {
125
- return item instanceof Blob;
126
- }) && (options.arrayResolution === "stringify" || typeof options.arrayResolution === "object" && options.arrayResolution[key] === "stringify")) {
127
- throw new TypeError("CANNOT_STRINGIFY_BLOB");
128
- }
129
- if (options.arrayResolution === "multiple" || typeof options.arrayResolution === "object" && options.arrayResolution[key] === "multiple") {
130
- for (const item of value) {
131
- if ((typeof item === "object" || !item) && !(item instanceof Blob)) {
132
- throw new TypeError("NON_PRIMITIVE_ARRAY_ITEMS_FOUND");
133
- }
134
- if (item instanceof Blob) {
135
- formData.append(String(key), item);
136
- } else {
137
- formData.append(String(key), String(item));
138
- }
139
- }
140
- continue;
141
- }
142
- }
143
- formData.append(String(key), JSON.stringify(value));
144
- } else {
145
- formData.append(String(key), String(value));
146
- }
147
- }
148
- return formData;
58
+ const formData = new FormData();
59
+ function resolveNullablesByStrategy(key, value, resolutionStrategy) {
60
+ switch (resolutionStrategy) {
61
+ case "empty":
62
+ formData.append(String(key), "");
63
+ break;
64
+ case "stringify":
65
+ formData.append(String(key), JSON.stringify(value));
66
+ break;
67
+ case "omit": break;
68
+ default: throw new TypeError("SLOPPY_PURE_JAVASCRIPT_USER_ERROR");
69
+ }
70
+ }
71
+ function resolveNullables(key, value, options$1) {
72
+ if (options$1.nullableResolution) {
73
+ resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options$1.nullableResolution));
74
+ return;
75
+ }
76
+ if (options$1.undefinedResolution || options$1.nullResolution) {
77
+ if (data[key] === void 0 && options$1.undefinedResolution) {
78
+ resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options$1.undefinedResolution));
79
+ return;
80
+ }
81
+ if (data[key] === null && options$1.nullResolution) resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options$1.nullResolution));
82
+ }
83
+ }
84
+ const entries = Object.entries(data);
85
+ for (const [key, value] of entries) if (value instanceof Blob) formData.append(String(key), value);
86
+ else if (value === void 0 || value === null) resolveNullables(key, value, options);
87
+ else if (typeof value === "object") {
88
+ if (Array.isArray(value)) {
89
+ if (value.some((item) => {
90
+ return item instanceof Blob;
91
+ }) && (options.arrayResolution === "stringify" || typeof options.arrayResolution === "object" && options.arrayResolution[key] === "stringify")) throw new TypeError("CANNOT_STRINGIFY_BLOB");
92
+ if (options.arrayResolution === "multiple" || typeof options.arrayResolution === "object" && options.arrayResolution[key] === "multiple") {
93
+ for (const item of value) {
94
+ if ((typeof item === "object" || !item) && !(item instanceof Blob)) throw new TypeError("NON_PRIMITIVE_ARRAY_ITEMS_FOUND");
95
+ if (item instanceof Blob) formData.append(String(key), item);
96
+ else formData.append(String(key), String(item));
97
+ }
98
+ continue;
99
+ }
100
+ }
101
+ formData.append(String(key), JSON.stringify(value));
102
+ } else formData.append(String(key), String(value));
103
+ return formData;
149
104
  }
150
105
  var createFormData_default = createFormData;
151
106
 
152
- // src/functions/createTemplateStringsArray.ts
107
+ //#endregion
108
+ //#region src/functions/createTemplateStringsArray.ts
153
109
  function createTemplateStringsArray(strings) {
154
- return Object.assign([...strings], { raw: [...strings] });
110
+ return Object.assign([...strings], { raw: [...strings] });
155
111
  }
156
112
  var createTemplateStringsArray_default = createTemplateStringsArray;
157
113
 
158
- // src/functions/fillArray.ts
114
+ //#endregion
115
+ //#region src/functions/fillArray.ts
159
116
  function fillArray(callback, length = 1) {
160
- const outputArray = new Array(length).fill(null).map((_, index) => {
161
- return callback(index);
162
- });
163
- const isAsync = outputArray.some((item) => {
164
- return item instanceof Promise;
165
- });
166
- if (isAsync) {
167
- return Promise.all(outputArray);
168
- }
169
- return outputArray;
117
+ const outputArray = new Array(length).fill(null).map((_, index) => {
118
+ return callback(index);
119
+ });
120
+ if (outputArray.some((item) => {
121
+ return item instanceof Promise;
122
+ })) return Promise.all(outputArray);
123
+ return outputArray;
170
124
  }
171
125
  var fillArray_default = fillArray;
172
126
 
173
- // src/functions/isSameDate.ts
127
+ //#endregion
128
+ //#region src/functions/isSameDate.ts
174
129
  function isSameDate(firstDate, secondDate) {
175
- return firstDate.getDate() === secondDate.getDate() && firstDate.getMonth() === secondDate.getMonth() && firstDate.getFullYear() === secondDate.getFullYear();
130
+ return firstDate.getDate() === secondDate.getDate() && firstDate.getMonth() === secondDate.getMonth() && firstDate.getFullYear() === secondDate.getFullYear();
176
131
  }
177
132
  var isSameDate_default = isSameDate;
178
133
 
179
- // src/functions/formatDateAndTime.ts
134
+ //#endregion
135
+ //#region src/functions/formatDateAndTime.ts
180
136
  function formatDateAndTime(inputDate) {
181
- const yesterday = addDaysToDate_default(/* @__PURE__ */ new Date(), -1);
182
- const today = /* @__PURE__ */ new Date();
183
- const inputTime = `${inputDate.getHours().toString().padStart(2, "0")}:${inputDate.getMinutes().toString().padStart(2, "0")}`;
184
- if (isSameDate_default(inputDate, yesterday)) {
185
- return `Yesterday at ${inputTime}`;
186
- }
187
- if (isSameDate_default(inputDate, today)) {
188
- return `Today at ${inputTime}`;
189
- }
190
- const formattedInputDay = inputDate.getDate().toString().padStart(2, "0");
191
- const formattedInputMonth = (inputDate.getMonth() + 1).toString().padStart(2, "0");
192
- const formattedInputYear = inputDate.getFullYear().toString();
193
- return `${formattedInputDay}/${formattedInputMonth}/${formattedInputYear}, ${inputTime}`;
137
+ const yesterday = addDaysToDate_default(/* @__PURE__ */ new Date(), -1);
138
+ const today = /* @__PURE__ */ new Date();
139
+ const inputTime = `${inputDate.getHours().toString().padStart(2, "0")}:${inputDate.getMinutes().toString().padStart(2, "0")}`;
140
+ if (isSameDate_default(inputDate, yesterday)) return `Yesterday at ${inputTime}`;
141
+ if (isSameDate_default(inputDate, today)) return `Today at ${inputTime}`;
142
+ return `${inputDate.getDate().toString().padStart(2, "0")}/${(inputDate.getMonth() + 1).toString().padStart(2, "0")}/${inputDate.getFullYear().toString()}, ${inputTime}`;
194
143
  }
195
144
  var formatDateAndTime_default = formatDateAndTime;
196
145
 
197
- // src/functions/parseIntStrict.ts
198
- var IntegerParsingError = new TypeError("INTEGER_PARSING_ERROR");
146
+ //#endregion
147
+ //#region src/functions/parseIntStrict.ts
148
+ const IntegerParsingError = /* @__PURE__ */ new TypeError("INTEGER_PARSING_ERROR");
199
149
  function parseIntStrict(...[string, radix]) {
200
- const trimmedString = string.trim();
201
- const pattern = radix && radix > 10 && radix <= 36 ? (
202
- // String.fromCharCode() gets the maximum possible alphabetical character for a base above 10
203
- new RegExp(`^[+-]?[0-9a-${String.fromCharCode(87 + radix - 1)}]+$`, "i")
204
- ) : /^[+-]?\d+$/;
205
- if (!pattern.test(trimmedString)) {
206
- throw IntegerParsingError;
207
- }
208
- if (radix && radix < 10 && [...trimmedString].some((character) => {
209
- return parseInt(character) >= radix;
210
- })) {
211
- throw IntegerParsingError;
212
- }
213
- const parseIntResult = parseInt(trimmedString, radix);
214
- if (isNaN(parseIntResult)) {
215
- throw IntegerParsingError;
216
- }
217
- return parseIntResult;
150
+ const trimmedString = string.trim();
151
+ if (!(radix && radix > 10 && radix <= 36 ? new RegExp(`^[+-]?[0-9a-${String.fromCharCode(87 + radix - 1)}]+$`, "i") : /^[+-]?\d+$/).test(trimmedString)) throw IntegerParsingError;
152
+ if (radix && radix < 10 && [...trimmedString].some((character) => {
153
+ return parseInt(character) >= radix;
154
+ })) throw IntegerParsingError;
155
+ const parseIntResult = parseInt(trimmedString, radix);
156
+ if (isNaN(parseIntResult)) throw IntegerParsingError;
157
+ return parseIntResult;
218
158
  }
219
159
  var parseIntStrict_default = parseIntStrict;
220
160
 
221
- // src/functions/getRandomNumber.ts
161
+ //#endregion
162
+ //#region src/functions/getRandomNumber.ts
222
163
  function getRandomNumber(lowerBound, upperBound) {
223
- const parsedLowerBound = parseIntStrict_default(`${lowerBound}`);
224
- const parsedUpperBound = parseIntStrict_default(`${upperBound}`);
225
- return Math.floor(Math.random() * (parsedUpperBound - parsedLowerBound + 1) + parsedLowerBound);
164
+ const parsedLowerBound = parseIntStrict_default(`${lowerBound}`);
165
+ const parsedUpperBound = parseIntStrict_default(`${upperBound}`);
166
+ return Math.floor(Math.random() * (parsedUpperBound - parsedLowerBound + 1) + parsedLowerBound);
226
167
  }
227
168
  var getRandomNumber_default = getRandomNumber;
228
169
 
229
- // src/functions/getRecordKeys.ts
170
+ //#endregion
171
+ //#region src/functions/getRecordKeys.ts
230
172
  function getRecordKeys(record) {
231
- return Object.keys(record);
173
+ return Object.keys(record);
232
174
  }
233
175
  var getRecordKeys_default = getRecordKeys;
234
176
 
235
- // src/functions/isLeapYear.ts
177
+ //#endregion
178
+ //#region src/functions/isLeapYear.ts
236
179
  function isLeapYear(year) {
237
- const parsedYear = parseIntStrict_default(`${year}`);
238
- return parsedYear % 4 === 0 && parsedYear % 100 !== 0 || parsedYear % 400 === 0;
180
+ const parsedYear = parseIntStrict_default(`${year}`);
181
+ return parsedYear % 4 === 0 && parsedYear % 100 !== 0 || parsedYear % 400 === 0;
239
182
  }
240
183
  var isLeapYear_default = isLeapYear;
241
184
 
242
- // src/functions/isMonthlyMultiple.ts
185
+ //#endregion
186
+ //#region src/functions/isMonthlyMultiple.ts
243
187
  function endOfMonthChecksButNotFebruary(firstDate, secondDate) {
244
- if ([3, 5, 8, 10].includes(firstDate.getMonth())) {
245
- return firstDate.getDate() === 30 && secondDate.getDate() === 31;
246
- }
247
- return false;
188
+ if ([
189
+ 3,
190
+ 5,
191
+ 8,
192
+ 10
193
+ ].includes(firstDate.getMonth())) return firstDate.getDate() === 30 && secondDate.getDate() === 31;
194
+ return false;
248
195
  }
249
196
  function nonLeapYearFebruaryChecks(firstDate, secondDate) {
250
- if (firstDate.getMonth() === 1) {
251
- if (!isLeapYear_default(firstDate.getFullYear()) && firstDate.getDate() === 28) {
252
- return [28, 29, 30, 31].includes(secondDate.getDate());
253
- }
254
- }
255
- return false;
197
+ if (firstDate.getMonth() === 1) {
198
+ if (!isLeapYear_default(firstDate.getFullYear()) && firstDate.getDate() === 28) return [
199
+ 28,
200
+ 29,
201
+ 30,
202
+ 31
203
+ ].includes(secondDate.getDate());
204
+ }
205
+ return false;
256
206
  }
257
207
  function leapYearFebruaryChecks(firstDate, secondDate) {
258
- if (firstDate.getMonth() === 1) {
259
- if (isLeapYear_default(firstDate.getFullYear()) && firstDate.getDate() === 29) {
260
- return [29, 30, 31].includes(secondDate.getDate());
261
- }
262
- }
263
- return false;
208
+ if (firstDate.getMonth() === 1) {
209
+ if (isLeapYear_default(firstDate.getFullYear()) && firstDate.getDate() === 29) return [
210
+ 29,
211
+ 30,
212
+ 31
213
+ ].includes(secondDate.getDate());
214
+ }
215
+ return false;
264
216
  }
265
217
  function isMonthlyMultiple(firstDate, secondDate) {
266
- if (endOfMonthChecksButNotFebruary(firstDate, secondDate) || endOfMonthChecksButNotFebruary(secondDate, firstDate)) {
267
- return true;
268
- }
269
- if (nonLeapYearFebruaryChecks(firstDate, secondDate) || nonLeapYearFebruaryChecks(secondDate, firstDate)) {
270
- return true;
271
- }
272
- if (leapYearFebruaryChecks(firstDate, secondDate) || leapYearFebruaryChecks(secondDate, firstDate)) {
273
- return true;
274
- }
275
- return firstDate.getDate() === secondDate.getDate();
218
+ if (endOfMonthChecksButNotFebruary(firstDate, secondDate) || endOfMonthChecksButNotFebruary(secondDate, firstDate)) return true;
219
+ if (nonLeapYearFebruaryChecks(firstDate, secondDate) || nonLeapYearFebruaryChecks(secondDate, firstDate)) return true;
220
+ if (leapYearFebruaryChecks(firstDate, secondDate) || leapYearFebruaryChecks(secondDate, firstDate)) return true;
221
+ return firstDate.getDate() === secondDate.getDate();
276
222
  }
277
223
  var isMonthlyMultiple_default = isMonthlyMultiple;
278
224
 
279
- // src/functions/isOrdered.ts
225
+ //#endregion
226
+ //#region src/functions/isOrdered.ts
280
227
  function isOrdered(array) {
281
- const newArray = [...array];
282
- newArray.sort();
283
- for (const index in newArray) {
284
- if (newArray[index] !== array[index]) {
285
- return false;
286
- }
287
- }
288
- return true;
228
+ const newArray = [...array];
229
+ newArray.sort();
230
+ for (const index in newArray) if (newArray[index] !== array[index]) return false;
231
+ return true;
289
232
  }
290
233
  var isOrdered_default = isOrdered;
291
234
 
292
- // src/functions/kebabToCamel.ts
235
+ //#endregion
236
+ //#region src/functions/kebabToCamel.ts
293
237
  function kebabToCamel(string, options) {
294
- if (string !== string.toLowerCase()) {
295
- throw new Error("INVALID_KEBAB_CASE_INPUT");
296
- }
297
- if (string.startsWith("-") || string.endsWith("-") || string.includes("--")) {
298
- throw new Error("INVALID_KEBAB_CASE_INPUT");
299
- }
300
- let outputString = "";
301
- let skip = false;
302
- for (const stringIndex in [...string]) {
303
- if (skip) {
304
- skip = false;
305
- continue;
306
- }
307
- const index = parseIntStrict_default(stringIndex);
308
- if (index === 0 && (options == null ? void 0 : options.startWithUpper)) {
309
- outputString += string[index].toUpperCase();
310
- continue;
311
- }
312
- if (index === string.length - 1) {
313
- outputString += string[index];
314
- break;
315
- }
316
- if (string[index] === "-" && /^[a-zA-Z]+$/.test(string[index + 1])) {
317
- outputString += string[index + 1].toUpperCase();
318
- skip = true;
319
- } else {
320
- outputString += string[index];
321
- }
322
- }
323
- return outputString;
238
+ if (string !== string.toLowerCase()) throw new Error("INVALID_KEBAB_CASE_INPUT");
239
+ if (string.startsWith("-") || string.endsWith("-") || string.includes("--")) throw new Error("INVALID_KEBAB_CASE_INPUT");
240
+ let outputString = "";
241
+ let skip = false;
242
+ for (const stringIndex in [...string]) {
243
+ if (skip) {
244
+ skip = false;
245
+ continue;
246
+ }
247
+ const index = parseIntStrict_default(stringIndex);
248
+ if (index === 0 && options?.startWithUpper) {
249
+ outputString += string[index].toUpperCase();
250
+ continue;
251
+ }
252
+ if (index === string.length - 1) {
253
+ outputString += string[index];
254
+ break;
255
+ }
256
+ if (string[index] === "-" && /^[a-zA-Z]+$/.test(string[index + 1])) {
257
+ outputString += string[index + 1].toUpperCase();
258
+ skip = true;
259
+ } else outputString += string[index];
260
+ }
261
+ return outputString;
324
262
  }
325
263
  var kebabToCamel_default = kebabToCamel;
326
264
 
327
- // src/functions/normalizeImportPath.ts
328
- import path from "path";
265
+ //#endregion
266
+ //#region src/functions/normalizeImportPath.ts
329
267
  function normalizeImportPath(importPath) {
330
- const normalizedPath = path.posix.normalize(importPath);
331
- if (importPath.startsWith("./") && !normalizedPath.startsWith("./")) {
332
- return `./${normalizedPath}`;
333
- }
334
- return normalizedPath;
268
+ const normalizedPath = path.posix.normalize(importPath);
269
+ if (importPath.startsWith("./") && !normalizedPath.startsWith("./")) return `./${normalizedPath}`;
270
+ return normalizedPath;
335
271
  }
336
- var normaliseImportPath = normalizeImportPath;
272
+ const normaliseImportPath = normalizeImportPath;
337
273
  var normalizeImportPath_default = normalizeImportPath;
338
274
 
339
- // src/functions/omitProperties.ts
275
+ //#endregion
276
+ //#region src/functions/omitProperties.ts
340
277
  function omitProperties(object, keysToOmit) {
341
- const outputObject = __spreadValues({}, object);
342
- const keysArray = Array.isArray(keysToOmit) ? keysToOmit : [keysToOmit];
343
- keysArray.forEach((key) => {
344
- delete outputObject[key];
345
- });
346
- return outputObject;
278
+ const outputObject = { ...object };
279
+ (Array.isArray(keysToOmit) ? keysToOmit : [keysToOmit]).forEach((key) => {
280
+ delete outputObject[key];
281
+ });
282
+ return outputObject;
347
283
  }
348
284
  var omitProperties_default = omitProperties;
349
285
 
350
- // src/functions/paralleliseArrays.ts
286
+ //#endregion
287
+ //#region src/functions/paralleliseArrays.ts
351
288
  function paralleliseArrays(firstArray, secondArray) {
352
- const outputArray = [];
353
- for (let i = 0; i < firstArray.length; i++) {
354
- outputArray.push([firstArray[i], secondArray[i]]);
355
- }
356
- return outputArray;
289
+ const outputArray = [];
290
+ for (let i = 0; i < firstArray.length; i++) outputArray.push([firstArray[i], secondArray[i]]);
291
+ return outputArray;
357
292
  }
358
293
  var paralleliseArrays_default = paralleliseArrays;
359
294
 
360
- // src/functions/randomiseArray.ts
295
+ //#endregion
296
+ //#region src/types/APIError.ts
297
+ const httpErrorCodeLookup = {
298
+ 400: "BAD_REQUEST",
299
+ 401: "UNAUTHORISED",
300
+ 403: "FORBIDDEN",
301
+ 404: "NOT_FOUND",
302
+ 418: "I_AM_A_TEAPOT",
303
+ 500: "INTERNAL_SERVER_ERROR"
304
+ };
305
+ var APIError = class extends Error {
306
+ status;
307
+ constructor(status = 500, message, options) {
308
+ super(message, options);
309
+ this.status = status;
310
+ if (message) this.message = message;
311
+ else this.message = httpErrorCodeLookup[this.status] ?? "API_ERROR";
312
+ Object.defineProperty(this, "message", { enumerable: true });
313
+ Object.setPrototypeOf(this, new.target.prototype);
314
+ }
315
+ static check(input) {
316
+ const data = input;
317
+ return typeof data === "object" && data !== null && typeof data?.status === "number" && typeof data?.message === "string";
318
+ }
319
+ };
320
+ var APIError_default = APIError;
321
+
322
+ //#endregion
323
+ //#region src/types/DataError.ts
324
+ var DataError = class extends Error {
325
+ data;
326
+ code;
327
+ /** @param data - The data that caused the error. */
328
+ /** @param message - A human-readable error message (e.g. The data provided is invalid). */
329
+ /** @param code - A standardised code (e.g. UNEXPECTED_DATA). */
330
+ /** @param options - Extra options to pass to super Error constructor. */
331
+ constructor(data, message = "The data provided is invalid", code = "INVALID_DATA", options) {
332
+ super(message, options);
333
+ if (Error.captureStackTrace) Error.captureStackTrace(this, new.target);
334
+ this.name = new.target.name;
335
+ this.code = code;
336
+ this.data = data;
337
+ Object.defineProperty(this, "message", { enumerable: true });
338
+ Object.setPrototypeOf(this, new.target.prototype);
339
+ }
340
+ static check(input) {
341
+ const data = input;
342
+ return typeof data === "object" && data !== null && typeof data.message === "string" && typeof data.code === "string" && "data" in data;
343
+ }
344
+ };
345
+ var DataError_default = DataError;
346
+
347
+ //#endregion
348
+ //#region src/types/Email.ts
349
+ const emailSchema = z.email().brand();
350
+ function parseEmail(data) {
351
+ return emailSchema.parse(data);
352
+ }
353
+ var Email_default = parseEmail;
354
+
355
+ //#endregion
356
+ //#region src/types/Env.ts
357
+ const envSchema = z$1.enum([
358
+ "test",
359
+ "development",
360
+ "production"
361
+ ]);
362
+ function parseEnv(data = "development") {
363
+ return envSchema.parse(data);
364
+ }
365
+ var Env_default = parseEnv;
366
+
367
+ //#endregion
368
+ //#region src/types/UUID.ts
369
+ const uuidSchema = z.uuid().brand();
370
+ function parseUUID(UUID) {
371
+ return uuidSchema.parse(UUID);
372
+ }
373
+ var UUID_default = parseUUID;
374
+
375
+ //#endregion
376
+ //#region src/functions/parseZodSchema.ts
377
+ function parseZodSchema(schema, data) {
378
+ const parsedResult = schema.safeParse(data);
379
+ if (!parsedResult.success) throw new DataError_default(data);
380
+ return parsedResult.data;
381
+ }
382
+ var parseZodSchema_default = parseZodSchema;
383
+
384
+ //#endregion
385
+ //#region src/functions/randomiseArray.ts
361
386
  function randomiseArray(array) {
362
- const mutableArray = [...array];
363
- const outputArray = [];
364
- do {
365
- const indexToRemove = getRandomNumber_default(0, mutableArray.length - 1);
366
- outputArray.push(mutableArray.splice(indexToRemove, 1)[0]);
367
- } while (mutableArray.length > 0);
368
- return outputArray;
387
+ const mutableArray = [...array];
388
+ const outputArray = [];
389
+ do {
390
+ const indexToRemove = getRandomNumber_default(0, mutableArray.length - 1);
391
+ outputArray.push(mutableArray.splice(indexToRemove, 1)[0]);
392
+ } while (mutableArray.length > 0);
393
+ return outputArray;
369
394
  }
370
395
  var randomiseArray_default = randomiseArray;
371
396
 
372
- // src/functions/range.ts
397
+ //#endregion
398
+ //#region src/functions/range.ts
373
399
  function range(start, stop, step = 1) {
374
- const numbers = [];
375
- if (step === 0) {
376
- throw new Error("ZERO_STEP_SIZE_NOT_ALLOWED");
377
- } else if (step > 0) {
378
- if (start > stop) {
379
- throw new Error("INVALID_BOUNDARIES");
380
- }
381
- for (let i = start; i < stop; i += step) {
382
- numbers.push(i);
383
- }
384
- } else if (step < 0) {
385
- if (start < stop) {
386
- throw new Error("INVALID_BOUNDARIES");
387
- }
388
- for (let i = start; i > stop; i += step) {
389
- numbers.push(i);
390
- }
391
- }
392
- return numbers;
400
+ const numbers = [];
401
+ if (step === 0) throw new Error("ZERO_STEP_SIZE_NOT_ALLOWED");
402
+ else if (step > 0) {
403
+ if (start > stop) throw new Error("INVALID_BOUNDARIES");
404
+ for (let i = start; i < stop; i += step) numbers.push(i);
405
+ } else if (step < 0) {
406
+ if (start < stop) throw new Error("INVALID_BOUNDARIES");
407
+ for (let i = start; i > stop; i += step) numbers.push(i);
408
+ }
409
+ return numbers;
393
410
  }
394
411
  var range_default = range;
395
412
 
396
- // src/functions/removeDuplicates.ts
413
+ //#endregion
414
+ //#region src/functions/removeDuplicates.ts
397
415
  function removeDuplicates(array) {
398
- const outputArray = [];
399
- for (const item of array) {
400
- if (!outputArray.includes(item)) {
401
- outputArray.push(item);
402
- }
403
- }
404
- return outputArray;
416
+ const outputArray = [];
417
+ for (const item of array) if (!outputArray.includes(item)) outputArray.push(item);
418
+ return outputArray;
405
419
  }
406
420
  var removeDuplicates_default = removeDuplicates;
407
421
 
408
- // src/functions/stringListToArray.ts
422
+ //#endregion
423
+ //#region src/functions/stringListToArray.ts
409
424
  function stringListToArray(stringList, { separator = ",", trimWhitespace = true } = {}) {
410
- if (trimWhitespace && stringList.trim() === "") {
411
- return [];
412
- }
413
- const arrayList = stringList.split(separator != null ? separator : "");
414
- return trimWhitespace ? arrayList.map((item) => {
415
- return item.trim();
416
- }) : arrayList;
425
+ if (trimWhitespace && stringList.trim() === "") return [];
426
+ const arrayList = stringList.split(separator ?? "");
427
+ return trimWhitespace ? arrayList.map((item) => {
428
+ return item.trim();
429
+ }) : arrayList;
417
430
  }
418
431
  var stringListToArray_default = stringListToArray;
419
432
 
420
- // src/functions/stringToBoolean.ts
433
+ //#endregion
434
+ //#region src/functions/stringToBoolean.ts
421
435
  function stringToBoolean(inputString) {
422
- const normalisedString = inputString.toLowerCase();
423
- if (normalisedString !== "true" && normalisedString !== "false") {
424
- throw new TypeError("INVALID_BOOLEAN_STRING");
425
- }
426
- return normalisedString === "true";
436
+ const normalisedString = inputString.toLowerCase();
437
+ if (normalisedString !== "true" && normalisedString !== "false") throw new TypeError("INVALID_BOOLEAN_STRING");
438
+ return normalisedString === "true";
427
439
  }
428
440
  var stringToBoolean_default = stringToBoolean;
429
441
 
430
- // src/functions/truncate.ts
442
+ //#endregion
443
+ //#region src/functions/truncate.ts
431
444
  function truncate(stringToTruncate, maxLength = 5) {
432
- return stringToTruncate.length > maxLength ? `${stringToTruncate.slice(0, maxLength)}...` : stringToTruncate;
445
+ return stringToTruncate.length > maxLength ? `${stringToTruncate.slice(0, maxLength)}...` : stringToTruncate;
433
446
  }
434
447
  var truncate_default = truncate;
435
448
 
436
- // src/functions/wait.ts
449
+ //#endregion
450
+ //#region src/functions/wait.ts
437
451
  function wait(seconds) {
438
- return new Promise((resolve, _) => {
439
- setTimeout(() => {
440
- resolve();
441
- }, seconds * 1e3);
442
- });
452
+ return new Promise((resolve, _) => {
453
+ setTimeout(() => {
454
+ resolve();
455
+ }, seconds * 1e3);
456
+ });
443
457
  }
444
458
  var wait_default = wait;
445
459
 
446
- // src/functions/taggedTemplate/interpolate.ts
460
+ //#endregion
461
+ //#region src/functions/taggedTemplate/interpolate.ts
447
462
  function interpolate(strings, ...interpolations) {
448
- let result = "";
449
- for (const [string, interpolation = ""] of paralleliseArrays_default(strings, interpolations)) {
450
- result += string + interpolation;
451
- }
452
- return result;
463
+ let result = "";
464
+ for (const [string, interpolation = ""] of paralleliseArrays_default(strings, interpolations)) result += string + interpolation;
465
+ return result;
453
466
  }
454
467
  var interpolate_default = interpolate;
455
468
 
456
- // src/functions/taggedTemplate/interpolateObjects.ts
469
+ //#endregion
470
+ //#region src/functions/taggedTemplate/interpolateObjects.ts
457
471
  function interpolateObjects(strings, ...values) {
458
- let result = "";
459
- for (let i = 0; i < strings.length; i++) {
460
- result += strings[i];
461
- if (i !== strings.length - 1) {
462
- result += values[i] && typeof values[i] === "object" ? JSON.stringify(values[i]) : values[i];
463
- }
464
- }
465
- return result;
472
+ let result = "";
473
+ for (let i = 0; i < strings.length; i++) {
474
+ result += strings[i];
475
+ if (i !== strings.length - 1) result += values[i] && typeof values[i] === "object" ? JSON.stringify(values[i]) : values[i];
476
+ }
477
+ return result;
466
478
  }
467
479
  var interpolateObjects_default = interpolateObjects;
468
480
 
469
- // src/functions/taggedTemplate/removeIndents.ts
481
+ //#endregion
482
+ //#region src/functions/taggedTemplate/removeIndents.ts
470
483
  function calculateTabSize(line, whitespaceLength) {
471
- const potentialWhitespacePart = line.slice(0, whitespaceLength);
472
- const trimmedString = line.trimStart();
473
- if (potentialWhitespacePart.trim() !== "") {
474
- return 0;
475
- }
476
- const tabSize = line.length - (trimmedString.length + whitespaceLength);
477
- return tabSize < 0 ? 0 : tabSize;
484
+ const potentialWhitespacePart = line.slice(0, whitespaceLength);
485
+ const trimmedString = line.trimStart();
486
+ if (potentialWhitespacePart.trim() !== "") return 0;
487
+ const tabSize = line.length - (trimmedString.length + whitespaceLength);
488
+ return tabSize < 0 ? 0 : tabSize;
478
489
  }
479
490
  function getWhitespaceLength(lines) {
480
- const [firstNonEmptyLine] = lines.filter((line) => {
481
- return line.trim() !== "";
482
- });
483
- return firstNonEmptyLine.length - firstNonEmptyLine.trimStart().length;
491
+ const [firstNonEmptyLine] = lines.filter((line) => {
492
+ return line.trim() !== "";
493
+ });
494
+ return firstNonEmptyLine.length - firstNonEmptyLine.trimStart().length;
484
495
  }
485
496
  function reduceLines(lines, { preserveTabs = true }) {
486
- const slicedLines = lines.slice(1);
487
- const isFirstLineEmpty = lines[0].trim() === "";
488
- const whitespaceLength = getWhitespaceLength(isFirstLineEmpty ? lines : slicedLines);
489
- return (isFirstLineEmpty ? slicedLines : lines).map((line) => {
490
- const tabSize = calculateTabSize(line, whitespaceLength);
491
- return (preserveTabs ? fillArray_default(() => {
492
- return " ";
493
- }, tabSize).join("") : "") + line.trimStart();
494
- }).join("\n");
497
+ const slicedLines = lines.slice(1);
498
+ const isFirstLineEmpty = lines[0].trim() === "";
499
+ const whitespaceLength = getWhitespaceLength(isFirstLineEmpty ? lines : slicedLines);
500
+ return (isFirstLineEmpty ? slicedLines : lines).map((line) => {
501
+ const tabSize = calculateTabSize(line, whitespaceLength);
502
+ return (preserveTabs ? fillArray_default(() => {
503
+ return " ";
504
+ }, tabSize).join("") : "") + line.trimStart();
505
+ }).join("\n");
495
506
  }
496
507
  function removeIndents(first, ...args) {
497
- if (typeof first === "object" && first !== null && !Array.isArray(first)) {
498
- const options2 = first;
499
- return (strings2, ...interpolations2) => {
500
- return removeIndents(strings2, ...interpolations2, options2);
501
- };
502
- }
503
- const strings = first;
504
- const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
505
- const interpolations = [...args];
506
- const fullString = interpolate_default(strings, ...interpolations);
507
- return reduceLines(fullString.split("\n"), options);
508
+ if (typeof first === "object" && first !== null && !Array.isArray(first)) {
509
+ const options$1 = first;
510
+ return (strings$1, ...interpolations) => {
511
+ return removeIndents(strings$1, ...interpolations, options$1);
512
+ };
513
+ }
514
+ const strings = first;
515
+ const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
516
+ return reduceLines(interpolate_default(strings, ...[...args]).split("\n"), options);
508
517
  }
509
518
  var removeIndents_default = removeIndents;
510
519
 
511
- // src/functions/taggedTemplate/stripIndents.ts
512
- function calculateTabSize2(line, whitespaceLength = 12) {
513
- const potentialWhitespacePart = line.slice(0, whitespaceLength);
514
- const trimmedString = line.trimStart();
515
- if (potentialWhitespacePart.trim() !== "") {
516
- return 0;
517
- }
518
- const tabSize = line.length - (trimmedString.length + whitespaceLength);
519
- return tabSize < 0 ? 0 : tabSize;
520
- }
521
- function reduceLines2(lines, { whitespaceLength = 12, preserveTabs = true }) {
522
- return lines.map((line) => {
523
- const tabSize = calculateTabSize2(line, whitespaceLength);
524
- return (preserveTabs ? fillArray_default(() => {
525
- return " ";
526
- }, tabSize).join("") : "") + line.trimStart();
527
- }).join("\n");
528
- }
529
- function stripIndents(first, ...args) {
530
- if (typeof first === "object" && first !== null && !Array.isArray(first)) {
531
- const options2 = first;
532
- return (strings2, ...interpolations2) => {
533
- return stripIndents(strings2, ...interpolations2, options2);
534
- };
535
- }
536
- const strings = first;
537
- const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
538
- const interpolations = [...args];
539
- const fullString = interpolate_default(strings, ...interpolations);
540
- return reduceLines2(fullString.split("\n"), options);
541
- }
542
- 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
- export {
600
- APIError_default as APIError,
601
- addDaysToDate_default as addDaysToDate,
602
- appendSemicolon_default as appendSemicolon,
603
- camelToKebab_default as camelToKebab,
604
- convertFileToBase64_default as convertFileToBase64,
605
- createFormData_default as createFormData,
606
- createTemplateStringsArray_default as createTemplateStringsArray,
607
- fillArray_default as fillArray,
608
- formatDateAndTime_default as formatDateAndTime,
609
- getRandomNumber_default as getRandomNumber,
610
- getRecordKeys_default as getRecordKeys,
611
- httpErrorCodeLookup,
612
- interpolate_default as interpolate,
613
- interpolateObjects_default as interpolateObjects,
614
- isLeapYear_default as isLeapYear,
615
- isMonthlyMultiple_default as isMonthlyMultiple,
616
- isOrdered_default as isOrdered,
617
- isSameDate_default as isSameDate,
618
- kebabToCamel_default as kebabToCamel,
619
- normaliseImportPath,
620
- normalizeImportPath_default as normalizeImportPath,
621
- omitProperties_default as omitProperties,
622
- paralleliseArrays_default as paralleliseArrays,
623
- Email_default as parseEmail,
624
- Env_default as parseEnv,
625
- parseIntStrict_default as parseIntStrict,
626
- UUID_default as parseUUID,
627
- randomiseArray_default as randomiseArray,
628
- range_default as range,
629
- removeDuplicates_default as removeDuplicates,
630
- removeIndents_default as removeIndents,
631
- stringListToArray_default as stringListToArray,
632
- stringToBoolean_default as stringToBoolean,
633
- stripIndents_default as stripIndents,
634
- truncate_default as truncate,
635
- wait_default as wait
636
- };
520
+ //#endregion
521
+ export { APIError_default as APIError, DataError_default as DataError, addDaysToDate_default as addDaysToDate, appendSemicolon_default as appendSemicolon, camelToKebab_default as camelToKebab, convertFileToBase64_default as convertFileToBase64, createFormData_default as createFormData, createTemplateStringsArray_default as createTemplateStringsArray, fillArray_default as fillArray, formatDateAndTime_default as formatDateAndTime, getRandomNumber_default as getRandomNumber, getRecordKeys_default as getRecordKeys, httpErrorCodeLookup, interpolate_default as interpolate, interpolateObjects_default as interpolateObjects, isLeapYear_default as isLeapYear, isMonthlyMultiple_default as isMonthlyMultiple, isOrdered_default as isOrdered, isSameDate_default as isSameDate, kebabToCamel_default as kebabToCamel, normaliseImportPath, normalizeImportPath_default as normalizeImportPath, omitProperties_default as omitProperties, paralleliseArrays_default as paralleliseArrays, Email_default as parseEmail, Env_default as parseEnv, parseIntStrict_default as parseIntStrict, UUID_default as parseUUID, parseZodSchema_default as parseZodSchema, randomiseArray_default as randomiseArray, range_default as range, removeDuplicates_default as removeDuplicates, removeIndents_default as removeIndents, stringListToArray_default as stringListToArray, stringToBoolean_default as stringToBoolean, truncate_default as truncate, wait_default as wait };