@dreyyan/toolkit 1.0.8 → 1.0.11

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.d.mts CHANGED
@@ -1,8 +1,18 @@
1
- declare const VALIDATION_ERRORS: {
2
- INVALID_EMAIL: string;
3
- MISSING_FIELDS: (fields: String[]) => string;
1
+ type AuthErrorCode = "EMAIL_REQUIRED" | "EMAIL_INVALID" | "PASSWORD_REQUIRED" | "PASSWORD_TOO_SHORT";
2
+
3
+ declare function validateSignup(input: {
4
+ email: string;
5
+ password: string;
6
+ }): {
7
+ ok: boolean;
8
+ errors: AuthErrorCode[];
9
+ } | {
10
+ ok: boolean;
11
+ errors?: undefined;
4
12
  };
5
13
 
14
+ declare const AUTH_MESSAGES: Record<AuthErrorCode, string>;
15
+
6
16
  declare const isValidEmail: (email?: string) => boolean;
7
17
 
8
- export { VALIDATION_ERRORS, isValidEmail };
18
+ export { AUTH_MESSAGES, type AuthErrorCode, isValidEmail, validateSignup };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,18 @@
1
- declare const VALIDATION_ERRORS: {
2
- INVALID_EMAIL: string;
3
- MISSING_FIELDS: (fields: String[]) => string;
1
+ type AuthErrorCode = "EMAIL_REQUIRED" | "EMAIL_INVALID" | "PASSWORD_REQUIRED" | "PASSWORD_TOO_SHORT";
2
+
3
+ declare function validateSignup(input: {
4
+ email: string;
5
+ password: string;
6
+ }): {
7
+ ok: boolean;
8
+ errors: AuthErrorCode[];
9
+ } | {
10
+ ok: boolean;
11
+ errors?: undefined;
4
12
  };
5
13
 
14
+ declare const AUTH_MESSAGES: Record<AuthErrorCode, string>;
15
+
6
16
  declare const isValidEmail: (email?: string) => boolean;
7
17
 
8
- export { VALIDATION_ERRORS, isValidEmail };
18
+ export { AUTH_MESSAGES, type AuthErrorCode, isValidEmail, validateSignup };
package/dist/index.js CHANGED
@@ -20,24 +20,38 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
- VALIDATION_ERRORS: () => VALIDATION_ERRORS,
24
- isValidEmail: () => isValidEmail
23
+ AUTH_MESSAGES: () => AUTH_MESSAGES,
24
+ isValidEmail: () => isValidEmail,
25
+ validateSignup: () => validateSignup
25
26
  });
26
27
  module.exports = __toCommonJS(index_exports);
27
28
 
28
- // src/ui-messages/errors/validation.ts
29
- var VALIDATION_ERRORS = {
30
- INVALID_EMAIL: "Please enter a valid email address (e.g. name@example.com).",
31
- MISSING_FIELDS: (fields) => `Missing required fields: ${fields.join(", ")}`
32
- };
33
-
34
- // src/validators/email.ts
29
+ // src/validators/email.validator.ts
35
30
  var isValidEmail = (email) => {
36
31
  if (!email) return false;
37
32
  return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
38
33
  };
34
+
35
+ // src/auth/signup.validator.ts
36
+ function validateSignup(input) {
37
+ const errors = [];
38
+ if (!input.email) errors.push("EMAIL_REQUIRED");
39
+ else if (!isValidEmail(input.email)) errors.push("EMAIL_INVALID");
40
+ if (!input.password) errors.push("PASSWORD_REQUIRED");
41
+ else if (input.password.length < 8) errors.push("PASSWORD_TOO_SHORT");
42
+ return errors.length ? { ok: false, errors } : { ok: true };
43
+ }
44
+
45
+ // src/ui-messages/auth.messages.ts
46
+ var AUTH_MESSAGES = {
47
+ EMAIL_REQUIRED: "Email is required.",
48
+ EMAIL_INVALID: "Please enter a valid email address (e.g. name@example.com).",
49
+ PASSWORD_REQUIRED: "Password is required.",
50
+ PASSWORD_TOO_SHORT: "Password must be at least 8 characters long."
51
+ };
39
52
  // Annotate the CommonJS export names for ESM import in node:
40
53
  0 && (module.exports = {
41
- VALIDATION_ERRORS,
42
- isValidEmail
54
+ AUTH_MESSAGES,
55
+ isValidEmail,
56
+ validateSignup
43
57
  });
package/dist/index.mjs CHANGED
@@ -1,15 +1,28 @@
1
- // src/ui-messages/errors/validation.ts
2
- var VALIDATION_ERRORS = {
3
- INVALID_EMAIL: "Please enter a valid email address (e.g. name@example.com).",
4
- MISSING_FIELDS: (fields) => `Missing required fields: ${fields.join(", ")}`
5
- };
6
-
7
- // src/validators/email.ts
1
+ // src/validators/email.validator.ts
8
2
  var isValidEmail = (email) => {
9
3
  if (!email) return false;
10
4
  return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
11
5
  };
6
+
7
+ // src/auth/signup.validator.ts
8
+ function validateSignup(input) {
9
+ const errors = [];
10
+ if (!input.email) errors.push("EMAIL_REQUIRED");
11
+ else if (!isValidEmail(input.email)) errors.push("EMAIL_INVALID");
12
+ if (!input.password) errors.push("PASSWORD_REQUIRED");
13
+ else if (input.password.length < 8) errors.push("PASSWORD_TOO_SHORT");
14
+ return errors.length ? { ok: false, errors } : { ok: true };
15
+ }
16
+
17
+ // src/ui-messages/auth.messages.ts
18
+ var AUTH_MESSAGES = {
19
+ EMAIL_REQUIRED: "Email is required.",
20
+ EMAIL_INVALID: "Please enter a valid email address (e.g. name@example.com).",
21
+ PASSWORD_REQUIRED: "Password is required.",
22
+ PASSWORD_TOO_SHORT: "Password must be at least 8 characters long."
23
+ };
12
24
  export {
13
- VALIDATION_ERRORS,
14
- isValidEmail
25
+ AUTH_MESSAGES,
26
+ isValidEmail,
27
+ validateSignup
15
28
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dreyyan/toolkit",
3
- "version": "1.0.8",
3
+ "version": "1.0.11",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",