sepvalidator 1.0.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/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # README
2
+
3
+ A simple JavaScript utility package for validating passwords and email addresses.
4
+
5
+ ## Features
6
+
7
+ * Password strength validation
8
+ * Email format validation
9
+ * Simple and lightweight
10
+ * Easy to integrate
11
+
12
+ ---
13
+
14
+ ## Password Validation
15
+
16
+ ### Rules
17
+
18
+ The password validator checks for:
19
+
20
+ * Minimum length of 8 characters
21
+ * At least one uppercase letter
22
+ * At least one digit
23
+ * At least one special character
24
+
25
+ ### Usage
26
+
27
+ ```js
28
+ import scorePassword from './scorePassword'
29
+
30
+ const result = scorePassword('SecurePass123!')
31
+
32
+ console.log(result)
33
+ ```
34
+
35
+ ### Example Output
36
+
37
+ ```js
38
+ {
39
+ score: 4,
40
+ passedRules: ['minLength', 'uppercase', 'digits', 'special'],
41
+ suggestions: []
42
+ }
43
+ ```
44
+
45
+ ---
46
+
47
+ ## Email Validation
48
+
49
+ ### Usage
50
+
51
+ ```js
52
+ import validateEmail from './validateEmail'
53
+
54
+ const result = validateEmail('test@example.com')
55
+
56
+ console.log(result)
57
+ ```
58
+
59
+ ### Example Output
60
+
61
+ ```js
62
+ {
63
+ valid: true,
64
+ reasons: []
65
+ }
66
+ ```
67
+
68
+ ### Invalid Email Example
69
+
70
+ ```js
71
+ {
72
+ valid: false,
73
+ reasons: ['Invalid email format.']
74
+ }
75
+ ```
76
+
77
+ ---
78
+
79
+ ## Exported Functions
80
+
81
+ | Function | Description |
82
+ | ------------------------- | --------------------------- |
83
+ | `scorePassword(password)` | Validates password strength |
84
+ | `validateEmail(email)` | Validates email format |
85
+
86
+ ---
87
+
package/email.js ADDED
@@ -0,0 +1,20 @@
1
+ const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
2
+
3
+ const validateEmail = (email) => {
4
+ const reasons = []
5
+
6
+ if (!email || !EMAIL_REGEX.test(email)){
7
+ reasons.push('Invalide Email Format.')
8
+ return {
9
+ valid: false,
10
+ reasons
11
+ }
12
+ }
13
+
14
+ return {
15
+ valid: reasons.length === 0,
16
+ reasons
17
+ }
18
+ }
19
+
20
+ export default validateEmail;
package/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import validateEmail from "./email.js"
2
+ import scorePassword from "./password.js"
3
+
4
+ export { validateEmail, scorePassword }
package/package.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "sepvalidator",
3
+ "version": "1.0.0",
4
+ "description": "A simple Email and Password validator",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [],
10
+ "author": "Rubayita",
11
+ "license": "ISC",
12
+ "type": "module"
13
+ }
package/password.js ADDED
@@ -0,0 +1,49 @@
1
+ const scorePassword = (password) => {
2
+ const configs = {
3
+ minLength: 8,
4
+ requireUpperCase: true,
5
+ requireDigits: true,
6
+ requireSpecial: true
7
+ }
8
+
9
+ const passedRules = []
10
+ const suggestions = []
11
+
12
+ const DigEx = /\d/
13
+ const UppEx = /[A-Z]/
14
+ const SpecEx = /[^A-Za-z0-9]/
15
+
16
+ if (password.length >= configs.minLength) {
17
+ passedRules.push('minLength')
18
+ } else {
19
+ suggestions.push(`Password must be ${configs.minLength} characters long.`)
20
+ }
21
+
22
+ if (!configs.requireUpperCase || UppEx.test(password)) {
23
+ passedRules.push("uppercase");
24
+ } else {
25
+ suggestions.push("Add at least one uppercase letter.");
26
+ }
27
+
28
+ if (!configs.requireDigits || DigEx.test(password)) {
29
+ passedRules.push("digits");
30
+ } else {
31
+ suggestions.push("Add at least one digit.");
32
+ }
33
+
34
+ if (!configs.requireSpecial || SpecEx.test(password)) {
35
+ passedRules.push("special");
36
+ } else {
37
+ suggestions.push("Add at least one special character.");
38
+ }
39
+
40
+ const score = passedRules.length;
41
+
42
+ return {
43
+ score, // 0 = Too weal and 4 = strong
44
+ passedRules,
45
+ suggestions
46
+ };
47
+ }
48
+
49
+ export default scorePassword;
package/test.js ADDED
@@ -0,0 +1,10 @@
1
+ import { validateEmail, scorePassword } from './index.js'
2
+
3
+ const testEmail = 'IvBZ2@example.com'
4
+ const testPassword = 'SecurePass123!'
5
+
6
+ const EmailResult = validateEmail(testEmail)
7
+ const PasswordResult = scorePassword(testPassword)
8
+
9
+ console.log('Email Results: ' ,EmailResult)
10
+ console.log('Password Results: ' ,PasswordResult)