@alextheman/utility 1.13.2 → 1.15.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
 
@@ -32,10 +42,11 @@ __export(index_exports, {
32
42
  isLeapYear: () => isLeapYear_default,
33
43
  isMonthlyMultiple: () => isMonthlyMultiple_default,
34
44
  isSameDate: () => isSameDate_default,
35
- newEnv: () => Env_default,
45
+ parseEnv: () => Env_default,
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 = {
@@ -242,10 +246,31 @@ var APIError_default = APIError;
242
246
  // src/types/Env.ts
243
247
  var import_zod = require("zod");
244
248
  var envSchema = import_zod.z.enum(["test", "development", "production"]);
245
- function newEnv(data = "development") {
249
+ function parseEnv(data = "development") {
246
250
  return envSchema.parse(data);
247
251
  }
248
- var Env_default = newEnv;
252
+ var Env_default = parseEnv;
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,
@@ -258,9 +283,10 @@ var Env_default = newEnv;
258
283
  isLeapYear,
259
284
  isMonthlyMultiple,
260
285
  isSameDate,
261
- newEnv,
286
+ parseEnv,
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 {
@@ -37,6 +35,10 @@ declare const envSchema: z.ZodEnum<{
37
35
  production: "production";
38
36
  }>;
39
37
  type Env = z.infer<typeof envSchema>;
40
- declare function newEnv(data?: unknown): Env;
38
+ declare function parseEnv(data?: unknown): Env;
39
+
40
+ declare function validateUUID(UUID: string, error?: Error | APIError): string;
41
+
42
+ declare function wait(seconds: number): Promise<void>;
41
43
 
42
- export { APIError, type Env, type HTTPErrorCodes, addDaysToDate, appendSemicolon, convertFileToBase64, formatDateAndTime, getRandomNumber, httpErrorCodeLookup, isLeapYear, isMonthlyMultiple, isSameDate, newEnv, randomiseArray, range, truncate, wait };
44
+ export { APIError, type Env, type HTTPErrorCodes, addDaysToDate, appendSemicolon, convertFileToBase64, formatDateAndTime, getRandomNumber, httpErrorCodeLookup, isLeapYear, isMonthlyMultiple, isSameDate, parseEnv, 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 {
@@ -37,6 +35,10 @@ declare const envSchema: z.ZodEnum<{
37
35
  production: "production";
38
36
  }>;
39
37
  type Env = z.infer<typeof envSchema>;
40
- declare function newEnv(data?: unknown): Env;
38
+ declare function parseEnv(data?: unknown): Env;
39
+
40
+ declare function validateUUID(UUID: string, error?: Error | APIError): string;
41
+
42
+ declare function wait(seconds: number): Promise<void>;
41
43
 
42
- export { APIError, type Env, type HTTPErrorCodes, addDaysToDate, appendSemicolon, convertFileToBase64, formatDateAndTime, getRandomNumber, httpErrorCodeLookup, isLeapYear, isMonthlyMultiple, isSameDate, newEnv, randomiseArray, range, truncate, wait };
44
+ export { APIError, type Env, type HTTPErrorCodes, addDaysToDate, appendSemicolon, convertFileToBase64, formatDateAndTime, getRandomNumber, httpErrorCodeLookup, isLeapYear, isMonthlyMultiple, isSameDate, parseEnv, 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 = {
@@ -204,10 +197,31 @@ var APIError_default = APIError;
204
197
  // src/types/Env.ts
205
198
  import { z } from "zod";
206
199
  var envSchema = z.enum(["test", "development", "production"]);
207
- function newEnv(data = "development") {
200
+ function parseEnv(data = "development") {
208
201
  return envSchema.parse(data);
209
202
  }
210
- var Env_default = newEnv;
203
+ var Env_default = parseEnv;
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,
@@ -219,9 +233,10 @@ export {
219
233
  isLeapYear_default as isLeapYear,
220
234
  isMonthlyMultiple_default as isMonthlyMultiple,
221
235
  isSameDate_default as isSameDate,
222
- Env_default as newEnv,
236
+ Env_default as parseEnv,
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.15.0",
4
4
  "main": "dist/index.cjs",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -11,11 +11,11 @@
11
11
  "scripts": {
12
12
  "test": "vitest run",
13
13
  "test-watch": "vitest",
14
- "format": "prettier --write --parser typescript 'src/**/*.ts' 'tests/**/*.test.ts' && ESLINT_MODE=fix eslint --fix 'src/**/*.ts' 'tests/**/*.ts'",
15
- "lint": "ESLINT_MODE=lint eslint 'src/**/*.ts' 'tests/**/*.ts' && prettier --check --parser typescript 'src/**/*.ts' 'tests/**/*.ts'",
14
+ "format": "prettier --write --parser typescript 'src/**/*.ts' 'tests/**/*.test.ts' && eslint --fix --suppress-all 'src/**/*.ts' 'tests/**/*.ts' && rm -f eslint-suppressions.json",
15
+ "lint": "tsc --noEmit && eslint 'src/**/*.ts' 'tests/**/*.ts' && prettier --check --parser typescript 'src/**/*.ts' 'tests/**/*.ts'",
16
16
  "prepare": "husky",
17
17
  "build": "tsup",
18
- "update-dependencies": "npx npm-check-updates -u && npm install",
18
+ "update-dependencies": "bash -c 'npx npm-check-updates -u \"$@\" && npm install' --",
19
19
  "change-major": "npm version major -m \"Change version number to v%s\"",
20
20
  "change-minor": "npm version minor -m \"Change version number to v%s\"",
21
21
  "change-patch": "npm version patch -m \"Change version number to v%s\""
@@ -25,7 +25,7 @@
25
25
  "license": "ISC",
26
26
  "description": "",
27
27
  "devDependencies": {
28
- "@alextheman/eslint-plugin": "^1.6.8",
28
+ "@alextheman/eslint-plugin": "^1.8.1",
29
29
  "@eslint/js": "^9.34.0",
30
30
  "@types/node": "^24.3.0",
31
31
  "eslint": "^9.34.0",
@@ -37,11 +37,11 @@
37
37
  "prettier": "^3.6.2",
38
38
  "tsup": "^8.5.0",
39
39
  "typescript": "^5.9.2",
40
- "typescript-eslint": "^8.40.0",
40
+ "typescript-eslint": "^8.41.0",
41
41
  "vite-tsconfig-paths": "^5.1.4",
42
42
  "vitest": "^3.2.4"
43
43
  },
44
44
  "dependencies": {
45
- "zod": "^4.1.0"
45
+ "zod": "^4.1.5"
46
46
  }
47
47
  }