@alextheman/utility 1.13.1 → 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 +43 -17
- package/dist/index.d.cts +10 -8
- package/dist/index.d.ts +10 -8
- package/dist/index.js +32 -17
- package/package.json +1 -1
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,23 +212,8 @@ function truncate(stringToTruncate, maxLength = 5) {
|
|
|
201
212
|
}
|
|
202
213
|
var truncate_default = truncate;
|
|
203
214
|
|
|
204
|
-
// src/functions/
|
|
205
|
-
|
|
206
|
-
return new Promise((resolve, _) => {
|
|
207
|
-
setTimeout(() => {
|
|
208
|
-
resolve();
|
|
209
|
-
}, seconds * 1e3);
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
var wait_default = wait;
|
|
213
|
-
|
|
214
|
-
// src/types/Env.ts
|
|
215
|
-
var import_zod = require("zod");
|
|
216
|
-
var envSchema = import_zod.z.enum(["test", "development", "production"]);
|
|
217
|
-
function newEnv(data = "development") {
|
|
218
|
-
return envSchema.parse(data);
|
|
219
|
-
}
|
|
220
|
-
var Env_default = newEnv;
|
|
215
|
+
// src/functions/validateUUID.ts
|
|
216
|
+
var import_zod2 = __toESM(require("zod"), 1);
|
|
221
217
|
|
|
222
218
|
// src/types/APIError.ts
|
|
223
219
|
var httpErrorCodeLookup = {
|
|
@@ -246,6 +242,35 @@ var APIError = class extends Error {
|
|
|
246
242
|
}
|
|
247
243
|
};
|
|
248
244
|
var APIError_default = APIError;
|
|
245
|
+
|
|
246
|
+
// src/types/Env.ts
|
|
247
|
+
var import_zod = require("zod");
|
|
248
|
+
var envSchema = import_zod.z.enum(["test", "development", "production"]);
|
|
249
|
+
function newEnv(data = "development") {
|
|
250
|
+
return envSchema.parse(data);
|
|
251
|
+
}
|
|
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 APIError_default = APIError;
|
|
|
262
287
|
randomiseArray,
|
|
263
288
|
range,
|
|
264
289
|
truncate,
|
|
290
|
+
validateUUID,
|
|
265
291
|
wait
|
|
266
292
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -22,7 +22,12 @@ 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
|
-
|
|
25
|
+
type HTTPErrorCodes = 400 | 401 | 403 | 404 | 418 | 500;
|
|
26
|
+
declare const httpErrorCodeLookup: Record<HTTPErrorCodes, string>;
|
|
27
|
+
declare class APIError extends Error {
|
|
28
|
+
status: number;
|
|
29
|
+
constructor(status?: number, message?: string, options?: ErrorOptions);
|
|
30
|
+
}
|
|
26
31
|
|
|
27
32
|
declare const envSchema: z.ZodEnum<{
|
|
28
33
|
test: "test";
|
|
@@ -32,11 +37,8 @@ declare const envSchema: z.ZodEnum<{
|
|
|
32
37
|
type Env = z.infer<typeof envSchema>;
|
|
33
38
|
declare function newEnv(data?: unknown): Env;
|
|
34
39
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
declare
|
|
38
|
-
status: number;
|
|
39
|
-
constructor(status?: number, message?: string, options?: ErrorOptions);
|
|
40
|
-
}
|
|
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, newEnv, randomiseArray, range, truncate, validateUUID, wait };
|
package/dist/index.d.ts
CHANGED
|
@@ -22,7 +22,12 @@ 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
|
-
|
|
25
|
+
type HTTPErrorCodes = 400 | 401 | 403 | 404 | 418 | 500;
|
|
26
|
+
declare const httpErrorCodeLookup: Record<HTTPErrorCodes, string>;
|
|
27
|
+
declare class APIError extends Error {
|
|
28
|
+
status: number;
|
|
29
|
+
constructor(status?: number, message?: string, options?: ErrorOptions);
|
|
30
|
+
}
|
|
26
31
|
|
|
27
32
|
declare const envSchema: z.ZodEnum<{
|
|
28
33
|
test: "test";
|
|
@@ -32,11 +37,8 @@ declare const envSchema: z.ZodEnum<{
|
|
|
32
37
|
type Env = z.infer<typeof envSchema>;
|
|
33
38
|
declare function newEnv(data?: unknown): Env;
|
|
34
39
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
declare
|
|
38
|
-
status: number;
|
|
39
|
-
constructor(status?: number, message?: string, options?: ErrorOptions);
|
|
40
|
-
}
|
|
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, newEnv, randomiseArray, range, truncate, validateUUID, wait };
|
package/dist/index.js
CHANGED
|
@@ -163,23 +163,8 @@ function truncate(stringToTruncate, maxLength = 5) {
|
|
|
163
163
|
}
|
|
164
164
|
var truncate_default = truncate;
|
|
165
165
|
|
|
166
|
-
// src/functions/
|
|
167
|
-
|
|
168
|
-
return new Promise((resolve, _) => {
|
|
169
|
-
setTimeout(() => {
|
|
170
|
-
resolve();
|
|
171
|
-
}, seconds * 1e3);
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
var wait_default = wait;
|
|
175
|
-
|
|
176
|
-
// src/types/Env.ts
|
|
177
|
-
import { z } from "zod";
|
|
178
|
-
var envSchema = z.enum(["test", "development", "production"]);
|
|
179
|
-
function newEnv(data = "development") {
|
|
180
|
-
return envSchema.parse(data);
|
|
181
|
-
}
|
|
182
|
-
var Env_default = newEnv;
|
|
166
|
+
// src/functions/validateUUID.ts
|
|
167
|
+
import z2 from "zod";
|
|
183
168
|
|
|
184
169
|
// src/types/APIError.ts
|
|
185
170
|
var httpErrorCodeLookup = {
|
|
@@ -208,6 +193,35 @@ var APIError = class extends Error {
|
|
|
208
193
|
}
|
|
209
194
|
};
|
|
210
195
|
var APIError_default = APIError;
|
|
196
|
+
|
|
197
|
+
// src/types/Env.ts
|
|
198
|
+
import { z } from "zod";
|
|
199
|
+
var envSchema = z.enum(["test", "development", "production"]);
|
|
200
|
+
function newEnv(data = "development") {
|
|
201
|
+
return envSchema.parse(data);
|
|
202
|
+
}
|
|
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
|
};
|