form-sakhi 0.0.0-stage → 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/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+
2
+ MIT License
3
+
4
+ Copyright (c) 2026 Sahasra
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
package/README.md CHANGED
@@ -1,3 +1,159 @@
1
- # Temporary Holding Version
1
+ # Form Sakhi
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **A lightweight JavaScript form validation utility**
4
+
5
+ Form Sakhi is a simple and reusable JavaScript package that helps developers validate form inputs and clean text. It includes commonly used validation functions for Indian mobile numbers, email addresses, PIN codes, and passwords.
6
+
7
+ ## Features
8
+
9
+ - Indian mobile number validation
10
+ - Email address validation
11
+ - Indian PIN code validation
12
+ - Strong password validation
13
+ - Empty field detection
14
+ - Text cleaning
15
+ - Multiple form field validation
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install form-sakhi
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```javascript
26
+ const {
27
+ isValidIndianMobile,
28
+ isValidEmail,
29
+ isValidPincode,
30
+ isStrongPassword,
31
+ isEmpty,
32
+ cleanText,
33
+ validateForm
34
+ } = require("form-sakhi");
35
+ ```
36
+
37
+ ## Available Functions
38
+
39
+ ### 1. isValidIndianMobile(number)
40
+
41
+ Checks whether a number is a valid 10-digit Indian mobile number beginning with 6, 7, 8, or 9.
42
+
43
+ ```javascript
44
+ isValidIndianMobile("9876543210"); // true
45
+ isValidIndianMobile("1234567890"); // false
46
+ ```
47
+
48
+ ### 2. isValidEmail(email)
49
+
50
+ Checks whether an email address follows a basic email format.
51
+
52
+ ```javascript
53
+ isValidEmail("hello@gmail.com"); // true
54
+ isValidEmail("hello.com"); // false
55
+ ```
56
+
57
+ ### 3. isValidPincode(pincode)
58
+
59
+ Checks whether an Indian PIN code contains exactly six digits and does not begin with zero.
60
+
61
+ ```javascript
62
+ isValidPincode("411001"); // true
63
+ isValidPincode("123"); // false
64
+ ```
65
+
66
+ ### 4. isStrongPassword(password)
67
+
68
+ Checks whether a password contains at least eight characters, one uppercase letter, one lowercase letter, one number, and one special character.
69
+
70
+ ```javascript
71
+ isStrongPassword("Hello@123"); // true
72
+ isStrongPassword("hello"); // false
73
+ ```
74
+
75
+ ### 5. isEmpty(value)
76
+
77
+ Checks whether a value is null, undefined, an empty string, or contains only whitespace.
78
+
79
+ ```javascript
80
+ isEmpty(""); // true
81
+ isEmpty("Hello"); // false
82
+ ```
83
+
84
+ ### 6. cleanText(text)
85
+
86
+ Removes leading and trailing spaces and replaces multiple spaces with a single space.
87
+
88
+ ```javascript
89
+ cleanText(" Hello World "); // "Hello World"
90
+ ```
91
+
92
+ ### 7. validateForm(data, rules)
93
+
94
+ Validates multiple form fields using specified rules.
95
+
96
+ ```javascript
97
+ const result = validateForm(
98
+ {
99
+ name: "Sahasra",
100
+ email: "hello@gmail.com",
101
+ mobile: "9876543210"
102
+ },
103
+ {
104
+ name: ["required"],
105
+ email: ["required", "email"],
106
+ mobile: ["required", "mobile"]
107
+ }
108
+ );
109
+
110
+ console.log(result);
111
+ ```
112
+
113
+ The function returns an object containing:
114
+ - `isValid`: true if all fields pass validation, otherwise false.
115
+ - `errors`: an object containing validation error messages for invalid fields.
116
+
117
+ Supported rules: `required`, `email`, and `mobile`.
118
+
119
+ ## Running Tests
120
+
121
+ Clone the repository and install any required dependencies (this package currently uses Node.js built-in testing modules).
122
+
123
+ Run:
124
+
125
+ ```bash
126
+ npm test
127
+ ```
128
+
129
+ ## Project Structure
130
+
131
+ ```text
132
+ form-sakhi/
133
+ ├── src/
134
+ │ ├── index.js
135
+ │ ├── validators.js
136
+ │ └── helpers.js
137
+ ├── test/
138
+ │ ├── validators.test.js
139
+ │ └── helpers.test.js
140
+ ├── .gitignore
141
+ ├── LICENSE
142
+ ├── README.md
143
+ └── package.json
144
+ ```
145
+
146
+ ## Technologies Used
147
+
148
+ - JavaScript
149
+ - Node.js
150
+ - NPM
151
+ - Node.js built-in test runner
152
+
153
+ ## Author
154
+
155
+ Sahasra
156
+
157
+ ## License
158
+
159
+ This project is licensed under the MIT License.
package/package.json CHANGED
@@ -1,6 +1,32 @@
1
+
1
2
  {
2
3
  "name": "form-sakhi",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
4
+ "version": "1.0.0",
5
+ "description": "A lightweight JavaScript form validation utility",
6
+ "main": "src/index.js",
7
+ "files": [
8
+ "src"
9
+ ],
10
+ "scripts": {
11
+ "test": "node --test"
12
+ },
13
+ "keywords": [
14
+ "validation",
15
+ "form-validation",
16
+ "javascript",
17
+ "indian-mobile-validation",
18
+ "npm"
19
+ ],
20
+ "author": "Sahasra",
21
+ "license": "MIT",
22
+ "type": "commonjs",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "https://github.com/sahasrasetty07-ship-it/form-sakhi.git"
26
+ },
27
+ "bugs": {
28
+ "url": "https://github.com/sahasrasetty07-ship-it/form-sakhi/issues"
29
+ },
30
+ "homepage": "https://github.com/sahasrasetty07-ship-it/form-sakhi#readme"
31
+ }
32
+
package/src/helpers.js ADDED
@@ -0,0 +1,57 @@
1
+
2
+ // Import validation functions
3
+ const {
4
+ isValidEmail,
5
+ isValidIndianMobile
6
+ } = require("./validators");
7
+
8
+ // 1. Check whether a value is empty
9
+ function isEmpty(value) {
10
+ return value === null ||
11
+ value === undefined ||
12
+ String(value).trim() === "";
13
+ }
14
+
15
+ // 2. Remove unnecessary spaces from text
16
+ function cleanText(text) {
17
+ return String(text).trim().replace(/\s+/g, " ");
18
+ }
19
+
20
+ // 3. Validate multiple form fields
21
+ function validateForm(data, rules) {
22
+ const errors = {};
23
+
24
+ for (const field in rules) {
25
+ const value = data[field];
26
+
27
+ for (const rule of rules[field]) {
28
+
29
+ if (rule === "required" && isEmpty(value)) {
30
+ errors[field] = "This field is required";
31
+ break;
32
+ }
33
+
34
+ if (rule === "email" && !isValidEmail(value)) {
35
+ errors[field] = "Invalid email";
36
+ break;
37
+ }
38
+
39
+ if (rule === "mobile" && !isValidIndianMobile(value)) {
40
+ errors[field] = "Invalid mobile number";
41
+ break;
42
+ }
43
+ }
44
+ }
45
+
46
+ return {
47
+ isValid: Object.keys(errors).length === 0,
48
+ errors
49
+ };
50
+ }
51
+
52
+ // Export all helper functions
53
+ module.exports = {
54
+ isEmpty,
55
+ cleanText,
56
+ validateForm
57
+ };
package/src/index.js ADDED
@@ -0,0 +1,9 @@
1
+
2
+ const validators = require("./validators");
3
+ const helpers = require("./helpers");
4
+
5
+ // Export all functions from one place
6
+ module.exports = {
7
+ ...validators,
8
+ ...helpers
9
+ };
@@ -0,0 +1,28 @@
1
+
2
+ // 1. Validate Indian mobile number
3
+ function isValidIndianMobile(number) {
4
+ return /^[6-9]\d{9}$/.test(String(number));
5
+ }
6
+
7
+ // 2. Validate email address
8
+ function isValidEmail(email) {
9
+ return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(String(email));
10
+ }
11
+
12
+ // 3. Validate Indian PIN code
13
+ function isValidPincode(pincode) {
14
+ return /^[1-9]\d{5}$/.test(String(pincode));
15
+ }
16
+
17
+ // 4. Check password strength
18
+ function isStrongPassword(password) {
19
+ return /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{8,}$/.test(String(password));
20
+ }
21
+
22
+ // Export all validation functions
23
+ module.exports = {
24
+ isValidIndianMobile,
25
+ isValidEmail,
26
+ isValidPincode,
27
+ isStrongPassword
28
+ };