@dreyyan/toolkit 1.0.7 → 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 +14 -3
- package/dist/index.d.ts +14 -3
- package/dist/index.js +25 -10
- package/dist/index.mjs +22 -8
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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;
|
|
3
12
|
};
|
|
4
13
|
|
|
14
|
+
declare const AUTH_MESSAGES: Record<AuthErrorCode, string>;
|
|
15
|
+
|
|
5
16
|
declare const isValidEmail: (email?: string) => boolean;
|
|
6
17
|
|
|
7
|
-
export {
|
|
18
|
+
export { AUTH_MESSAGES, type AuthErrorCode, isValidEmail, validateSignup };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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;
|
|
3
12
|
};
|
|
4
13
|
|
|
14
|
+
declare const AUTH_MESSAGES: Record<AuthErrorCode, string>;
|
|
15
|
+
|
|
5
16
|
declare const isValidEmail: (email?: string) => boolean;
|
|
6
17
|
|
|
7
|
-
export {
|
|
18
|
+
export { AUTH_MESSAGES, type AuthErrorCode, isValidEmail, validateSignup };
|
package/dist/index.js
CHANGED
|
@@ -20,23 +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
|
-
|
|
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/
|
|
29
|
-
var VALIDATION_ERRORS = {
|
|
30
|
-
MISSING_FIELDS: (fields) => `Missing required fields: ${fields.join(", ")}`
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// src/validators/email.ts
|
|
29
|
+
// src/validators/email.validator.ts
|
|
34
30
|
var isValidEmail = (email) => {
|
|
35
31
|
if (!email) return false;
|
|
36
32
|
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
|
|
37
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
|
+
};
|
|
38
52
|
// Annotate the CommonJS export names for ESM import in node:
|
|
39
53
|
0 && (module.exports = {
|
|
40
|
-
|
|
41
|
-
isValidEmail
|
|
54
|
+
AUTH_MESSAGES,
|
|
55
|
+
isValidEmail,
|
|
56
|
+
validateSignup
|
|
42
57
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,28 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
var VALIDATION_ERRORS = {
|
|
3
|
-
MISSING_FIELDS: (fields) => `Missing required fields: ${fields.join(", ")}`
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
// src/validators/email.ts
|
|
1
|
+
// src/validators/email.validator.ts
|
|
7
2
|
var isValidEmail = (email) => {
|
|
8
3
|
if (!email) return false;
|
|
9
4
|
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
|
|
10
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
|
+
};
|
|
11
24
|
export {
|
|
12
|
-
|
|
13
|
-
isValidEmail
|
|
25
|
+
AUTH_MESSAGES,
|
|
26
|
+
isValidEmail,
|
|
27
|
+
validateSignup
|
|
14
28
|
};
|