@alextheman/utility 1.13.2 → 1.14.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 CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
9
  var __export = (target, all) => {
@@ -16,6 +18,14 @@ var __copyProps = (to, from, except, desc) => {
16
18
  }
17
19
  return to;
18
20
  };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
19
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
30
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
31
 
@@ -36,6 +46,7 @@ __export(index_exports, {
36
46
  randomiseArray: () => randomiseArray_default,
37
47
  range: () => range_default,
38
48
  truncate: () => truncate_default,
49
+ validateUUID: () => validateUUID_default,
39
50
  wait: () => wait_default
40
51
  });
41
52
  module.exports = __toCommonJS(index_exports);
@@ -201,15 +212,8 @@ function truncate(stringToTruncate, maxLength = 5) {
201
212
  }
202
213
  var truncate_default = truncate;
203
214
 
204
- // src/functions/wait.ts
205
- function wait(seconds) {
206
- return new Promise((resolve, _) => {
207
- setTimeout(() => {
208
- resolve();
209
- }, seconds * 1e3);
210
- });
211
- }
212
- var wait_default = wait;
215
+ // src/functions/validateUUID.ts
216
+ var import_zod2 = __toESM(require("zod"), 1);
213
217
 
214
218
  // src/types/APIError.ts
215
219
  var httpErrorCodeLookup = {
@@ -246,6 +250,27 @@ function newEnv(data = "development") {
246
250
  return envSchema.parse(data);
247
251
  }
248
252
  var Env_default = newEnv;
253
+
254
+ // src/functions/validateUUID.ts
255
+ function validateUUID(UUID, error = new APIError_default(400, "INVALID_UUID")) {
256
+ const uuidSchema = import_zod2.default.uuid();
257
+ const parsedUUID = uuidSchema.safeParse(UUID);
258
+ if (!parsedUUID.success) {
259
+ throw error;
260
+ }
261
+ return parsedUUID.data;
262
+ }
263
+ var validateUUID_default = validateUUID;
264
+
265
+ // src/functions/wait.ts
266
+ function wait(seconds) {
267
+ return new Promise((resolve, _) => {
268
+ setTimeout(() => {
269
+ resolve();
270
+ }, seconds * 1e3);
271
+ });
272
+ }
273
+ var wait_default = wait;
249
274
  // Annotate the CommonJS export names for ESM import in node:
250
275
  0 && (module.exports = {
251
276
  APIError,
@@ -262,5 +287,6 @@ var Env_default = newEnv;
262
287
  randomiseArray,
263
288
  range,
264
289
  truncate,
290
+ validateUUID,
265
291
  wait
266
292
  });
package/dist/index.d.cts CHANGED
@@ -22,8 +22,6 @@ declare function range(start: number, stop: number, step?: number): number[];
22
22
 
23
23
  declare function truncate(stringToTruncate: string, maxLength?: number): string;
24
24
 
25
- declare function wait(seconds: number): Promise<void>;
26
-
27
25
  type HTTPErrorCodes = 400 | 401 | 403 | 404 | 418 | 500;
28
26
  declare const httpErrorCodeLookup: Record<HTTPErrorCodes, string>;
29
27
  declare class APIError extends Error {
@@ -39,4 +37,8 @@ declare const envSchema: z.ZodEnum<{
39
37
  type Env = z.infer<typeof envSchema>;
40
38
  declare function newEnv(data?: unknown): Env;
41
39
 
42
- export { APIError, type Env, type HTTPErrorCodes, addDaysToDate, appendSemicolon, convertFileToBase64, formatDateAndTime, getRandomNumber, httpErrorCodeLookup, isLeapYear, isMonthlyMultiple, isSameDate, newEnv, randomiseArray, range, truncate, wait };
40
+ declare function validateUUID(UUID: string, error?: Error | APIError): string;
41
+
42
+ declare function wait(seconds: number): Promise<void>;
43
+
44
+ export { APIError, type Env, type HTTPErrorCodes, addDaysToDate, appendSemicolon, convertFileToBase64, formatDateAndTime, getRandomNumber, httpErrorCodeLookup, isLeapYear, isMonthlyMultiple, isSameDate, newEnv, randomiseArray, range, truncate, validateUUID, wait };
package/dist/index.d.ts CHANGED
@@ -22,8 +22,6 @@ declare function range(start: number, stop: number, step?: number): number[];
22
22
 
23
23
  declare function truncate(stringToTruncate: string, maxLength?: number): string;
24
24
 
25
- declare function wait(seconds: number): Promise<void>;
26
-
27
25
  type HTTPErrorCodes = 400 | 401 | 403 | 404 | 418 | 500;
28
26
  declare const httpErrorCodeLookup: Record<HTTPErrorCodes, string>;
29
27
  declare class APIError extends Error {
@@ -39,4 +37,8 @@ declare const envSchema: z.ZodEnum<{
39
37
  type Env = z.infer<typeof envSchema>;
40
38
  declare function newEnv(data?: unknown): Env;
41
39
 
42
- export { APIError, type Env, type HTTPErrorCodes, addDaysToDate, appendSemicolon, convertFileToBase64, formatDateAndTime, getRandomNumber, httpErrorCodeLookup, isLeapYear, isMonthlyMultiple, isSameDate, newEnv, randomiseArray, range, truncate, wait };
40
+ declare function validateUUID(UUID: string, error?: Error | APIError): string;
41
+
42
+ declare function wait(seconds: number): Promise<void>;
43
+
44
+ export { APIError, type Env, type HTTPErrorCodes, addDaysToDate, appendSemicolon, convertFileToBase64, formatDateAndTime, getRandomNumber, httpErrorCodeLookup, isLeapYear, isMonthlyMultiple, isSameDate, newEnv, randomiseArray, range, truncate, validateUUID, wait };
package/dist/index.js CHANGED
@@ -163,15 +163,8 @@ function truncate(stringToTruncate, maxLength = 5) {
163
163
  }
164
164
  var truncate_default = truncate;
165
165
 
166
- // src/functions/wait.ts
167
- function wait(seconds) {
168
- return new Promise((resolve, _) => {
169
- setTimeout(() => {
170
- resolve();
171
- }, seconds * 1e3);
172
- });
173
- }
174
- var wait_default = wait;
166
+ // src/functions/validateUUID.ts
167
+ import z2 from "zod";
175
168
 
176
169
  // src/types/APIError.ts
177
170
  var httpErrorCodeLookup = {
@@ -208,6 +201,27 @@ function newEnv(data = "development") {
208
201
  return envSchema.parse(data);
209
202
  }
210
203
  var Env_default = newEnv;
204
+
205
+ // src/functions/validateUUID.ts
206
+ function validateUUID(UUID, error = new APIError_default(400, "INVALID_UUID")) {
207
+ const uuidSchema = z2.uuid();
208
+ const parsedUUID = uuidSchema.safeParse(UUID);
209
+ if (!parsedUUID.success) {
210
+ throw error;
211
+ }
212
+ return parsedUUID.data;
213
+ }
214
+ var validateUUID_default = validateUUID;
215
+
216
+ // src/functions/wait.ts
217
+ function wait(seconds) {
218
+ return new Promise((resolve, _) => {
219
+ setTimeout(() => {
220
+ resolve();
221
+ }, seconds * 1e3);
222
+ });
223
+ }
224
+ var wait_default = wait;
211
225
  export {
212
226
  APIError_default as APIError,
213
227
  addDaysToDate_default as addDaysToDate,
@@ -223,5 +237,6 @@ export {
223
237
  randomiseArray_default as randomiseArray,
224
238
  range_default as range,
225
239
  truncate_default as truncate,
240
+ validateUUID_default as validateUUID,
226
241
  wait_default as wait
227
242
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alextheman/utility",
3
- "version": "1.13.2",
3
+ "version": "1.14.0",
4
4
  "main": "dist/index.cjs",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",