@dreyyan/toolkit 1.0.8 → 1.0.12

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,20 @@
1
- declare const VALIDATION_ERRORS: {
2
- INVALID_EMAIL: string;
3
- MISSING_FIELDS: (fields: String[]) => string;
1
+ type AuthErrorCode = "FULL_NAME_REQUIRED" | "EMAIL_REQUIRED" | "EMAIL_INVALID" | "PASSWORD_REQUIRED" | "PASSWORD_TOO_SHORT" | "CONFIRM_PASSWORD_REQUIRED" | "PASSWORDS_DO_NOT_MATCH";
2
+
3
+ declare function validateSignup(input: {
4
+ fullName: string;
5
+ email: string;
6
+ password: string;
7
+ confirmPassword: string;
8
+ }): {
9
+ ok: boolean;
10
+ errors: AuthErrorCode[];
11
+ } | {
12
+ ok: boolean;
13
+ errors?: undefined;
4
14
  };
5
15
 
16
+ declare const AUTH_MESSAGES: Record<AuthErrorCode, string>;
17
+
6
18
  declare const isValidEmail: (email?: string) => boolean;
7
19
 
8
- export { VALIDATION_ERRORS, isValidEmail };
20
+ export { AUTH_MESSAGES, type AuthErrorCode, isValidEmail, validateSignup };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,20 @@
1
- declare const VALIDATION_ERRORS: {
2
- INVALID_EMAIL: string;
3
- MISSING_FIELDS: (fields: String[]) => string;
1
+ type AuthErrorCode = "FULL_NAME_REQUIRED" | "EMAIL_REQUIRED" | "EMAIL_INVALID" | "PASSWORD_REQUIRED" | "PASSWORD_TOO_SHORT" | "CONFIRM_PASSWORD_REQUIRED" | "PASSWORDS_DO_NOT_MATCH";
2
+
3
+ declare function validateSignup(input: {
4
+ fullName: string;
5
+ email: string;
6
+ password: string;
7
+ confirmPassword: string;
8
+ }): {
9
+ ok: boolean;
10
+ errors: AuthErrorCode[];
11
+ } | {
12
+ ok: boolean;
13
+ errors?: undefined;
4
14
  };
5
15
 
16
+ declare const AUTH_MESSAGES: Record<AuthErrorCode, string>;
17
+
6
18
  declare const isValidEmail: (email?: string) => boolean;
7
19
 
8
- export { VALIDATION_ERRORS, isValidEmail };
20
+ export { AUTH_MESSAGES, type AuthErrorCode, isValidEmail, validateSignup };
package/dist/index.js CHANGED
@@ -20,24 +20,55 @@ 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.fullName || input.fullName.trim().length === 0) {
39
+ errors.push("FULL_NAME_REQUIRED");
40
+ }
41
+ if (!input.email) {
42
+ errors.push("EMAIL_REQUIRED");
43
+ } else if (!isValidEmail(input.email)) {
44
+ errors.push("EMAIL_INVALID");
45
+ }
46
+ if (!input.password) {
47
+ errors.push("PASSWORD_REQUIRED");
48
+ } else if (input.password.length < 8) {
49
+ errors.push("PASSWORD_TOO_SHORT");
50
+ }
51
+ if (!input.confirmPassword) {
52
+ errors.push("CONFIRM_PASSWORD_REQUIRED");
53
+ } else if (input.password !== input.confirmPassword) {
54
+ errors.push("PASSWORDS_DO_NOT_MATCH");
55
+ }
56
+ return errors.length ? { ok: false, errors } : { ok: true };
57
+ }
58
+
59
+ // src/ui-messages/auth.messages.ts
60
+ var AUTH_MESSAGES = {
61
+ FULL_NAME_REQUIRED: "Full name is required.",
62
+ EMAIL_REQUIRED: "Email is required.",
63
+ EMAIL_INVALID: "Please enter a valid email address (e.g. name@example.com).",
64
+ PASSWORD_REQUIRED: "Password is required.",
65
+ PASSWORD_TOO_SHORT: "Password must be at least 8 characters long.",
66
+ CONFIRM_PASSWORD_REQUIRED: "Please confirm your password.",
67
+ PASSWORDS_DO_NOT_MATCH: "Passwords do not match."
68
+ };
39
69
  // Annotate the CommonJS export names for ESM import in node:
40
70
  0 && (module.exports = {
41
- VALIDATION_ERRORS,
42
- isValidEmail
71
+ AUTH_MESSAGES,
72
+ isValidEmail,
73
+ validateSignup
43
74
  });
package/dist/index.mjs CHANGED
@@ -1,15 +1,45 @@
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.fullName || input.fullName.trim().length === 0) {
11
+ errors.push("FULL_NAME_REQUIRED");
12
+ }
13
+ if (!input.email) {
14
+ errors.push("EMAIL_REQUIRED");
15
+ } else if (!isValidEmail(input.email)) {
16
+ errors.push("EMAIL_INVALID");
17
+ }
18
+ if (!input.password) {
19
+ errors.push("PASSWORD_REQUIRED");
20
+ } else if (input.password.length < 8) {
21
+ errors.push("PASSWORD_TOO_SHORT");
22
+ }
23
+ if (!input.confirmPassword) {
24
+ errors.push("CONFIRM_PASSWORD_REQUIRED");
25
+ } else if (input.password !== input.confirmPassword) {
26
+ errors.push("PASSWORDS_DO_NOT_MATCH");
27
+ }
28
+ return errors.length ? { ok: false, errors } : { ok: true };
29
+ }
30
+
31
+ // src/ui-messages/auth.messages.ts
32
+ var AUTH_MESSAGES = {
33
+ FULL_NAME_REQUIRED: "Full name is required.",
34
+ EMAIL_REQUIRED: "Email is required.",
35
+ EMAIL_INVALID: "Please enter a valid email address (e.g. name@example.com).",
36
+ PASSWORD_REQUIRED: "Password is required.",
37
+ PASSWORD_TOO_SHORT: "Password must be at least 8 characters long.",
38
+ CONFIRM_PASSWORD_REQUIRED: "Please confirm your password.",
39
+ PASSWORDS_DO_NOT_MATCH: "Passwords do not match."
40
+ };
12
41
  export {
13
- VALIDATION_ERRORS,
14
- isValidEmail
42
+ AUTH_MESSAGES,
43
+ isValidEmail,
44
+ validateSignup
15
45
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dreyyan/toolkit",
3
- "version": "1.0.8",
3
+ "version": "1.0.12",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",