lets-validate-username 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/README.md +63 -0
  2. package/package.json +9 -4
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # **Username Validator Tool**
2
+
3
+ A lightweight and easy-to-use npm package to validate usernames based on configurable rules. This tool checks for length, allowed characters, and uniqueness, making it perfect for user registration systems.
4
+
5
+ ---
6
+
7
+ ## **Features**
8
+ - ✅ Validate username length (default: 3-15 characters).
9
+ - ✅ Ensure usernames contain only letters, numbers, and underscores (`_`).
10
+ - ✅ Check if a username is already taken.
11
+ - ✅ Detailed validation messages for better user feedback.
12
+
13
+ ---
14
+
15
+ ## **Installation**
16
+
17
+ Install the package via npm:
18
+
19
+ ```bash
20
+ npm install username-validator-tool
21
+ ```
22
+ ## **API**
23
+
24
+ ### `validateUsername(username, existingUsernames)`
25
+
26
+ **Parameters**:
27
+ - `username` (string): The username to validate.
28
+ - `existingUsernames` (array): List of existing usernames to check for uniqueness.
29
+
30
+ **Returns**:
31
+ An object with the following structure:
32
+ ```
33
+ valid: Boolean, // true if valid, false if invalid
34
+ message: String, // Success message (if valid)
35
+ errors: Array // List of error messages (if invalid)
36
+ ```
37
+
38
+ ### **Examples**
39
+
40
+ #### 1. Valid Username
41
+ ```
42
+ validateUsername('valid_user', ['john_doe', 'jane123']);
43
+ // Output:
44
+ // { valid: true, message: 'Username is valid!' }
45
+ ```
46
+
47
+ #### 2. Username too Short
48
+ ````
49
+ Output:
50
+ // { valid: false, errors: ['Username must be between 3 and 15 characters.'] }
51
+ ````
52
+
53
+ #### 3. Invalid Characters
54
+ ```validateUsername('invalid@name', []);
55
+ // Output:
56
+ // { valid: false, errors: ['Username can only contain letters, numbers, and underscores.'] }
57
+ ```
58
+ #### 4. Username Already Taken
59
+ ```
60
+ validateUsername('john_doe', ['john_doe', 'jane123']);
61
+ // Output:
62
+ // { valid: false, errors: ['Username is already taken.'] }
63
+ ```
package/package.json CHANGED
@@ -1,12 +1,17 @@
1
1
  {
2
- "name": "lets-validate-username",
3
- "version": "1.0.0",
2
+ "name": "lets-validate-username",
3
+ "version": "1.0.1",
4
4
  "description": "A simple npm package to validate usernames based on length, allowed characters, and uniqueness.",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "node test.js"
8
8
  },
9
- "keywords": ["username", "validator", "npm-package", "validation"],
10
- "author": "Zoha",
9
+ "keywords": [
10
+ "username",
11
+ "validator",
12
+ "npm-package",
13
+ "validation"
14
+ ],
15
+ "author": "Zoha",
11
16
  "license": "MIT"
12
17
  }