@palakpreet/quick-validate 0.0.0-stage → 2.0.1
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 +17 -0
- package/README.md +309 -2
- package/package.json +35 -4
- package/src/index.js +1132 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 quick-validate contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
package/README.md
CHANGED
|
@@ -1,3 +1,310 @@
|
|
|
1
|
-
#
|
|
1
|
+
# quick-validate
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Lightweight, dependency-free JavaScript validation for common inputs and forms.**
|
|
4
|
+
|
|
5
|
+
`@palakpreet/quick-validate` is a collection of reusable JavaScript validation helpers designed to make validating user input simple, consistent, and easy to integrate into applications.
|
|
6
|
+
|
|
7
|
+
It provides individual validators, form and schema validation, custom validation rules, and commonly used Indian input format validations — all without external dependencies.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- Lightweight and dependency-free
|
|
12
|
+
- Written entirely in JavaScript
|
|
13
|
+
- Common input validators
|
|
14
|
+
- Indian-specific validators
|
|
15
|
+
- Password validation and strength checking
|
|
16
|
+
- Schema-based form validation
|
|
17
|
+
- Multiple validation rules per field
|
|
18
|
+
- Custom error messages
|
|
19
|
+
- Custom validation rules
|
|
20
|
+
- Nested object validation
|
|
21
|
+
- Array validation
|
|
22
|
+
- File metadata validation
|
|
23
|
+
- Simple and consistent error reporting
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install @palakpreet/quick-validate
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Quick Start
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
import quickValidate from "@palakpreet/quick-validate";
|
|
35
|
+
|
|
36
|
+
console.log(quickValidate.isEmail("person@example.com"));
|
|
37
|
+
// true
|
|
38
|
+
|
|
39
|
+
console.log(quickValidate.isPAN("ABCDE1234F"));
|
|
40
|
+
// true
|
|
41
|
+
|
|
42
|
+
console.log(quickValidate.isIFSC("HDFC0001234"));
|
|
43
|
+
// true
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Validate Individual Values
|
|
47
|
+
|
|
48
|
+
Use the built-in validators directly:
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
import {
|
|
52
|
+
isEmail,
|
|
53
|
+
isIndianPhone,
|
|
54
|
+
isIndianPinCode,
|
|
55
|
+
isStrongPassword,
|
|
56
|
+
isURL,
|
|
57
|
+
isPAN,
|
|
58
|
+
isGSTIN,
|
|
59
|
+
isIFSC,
|
|
60
|
+
isUPI
|
|
61
|
+
} from "@palakpreet/quick-validate";
|
|
62
|
+
|
|
63
|
+
console.log(isEmail("person@example.com"));
|
|
64
|
+
// true
|
|
65
|
+
|
|
66
|
+
console.log(isIndianPhone("9876543210"));
|
|
67
|
+
// true
|
|
68
|
+
|
|
69
|
+
console.log(isIndianPinCode("411001"));
|
|
70
|
+
// true
|
|
71
|
+
|
|
72
|
+
console.log(isStrongPassword("StrongPass@123"));
|
|
73
|
+
// true
|
|
74
|
+
|
|
75
|
+
console.log(isURL("https://example.com"));
|
|
76
|
+
// true
|
|
77
|
+
|
|
78
|
+
console.log(isPAN("ABCDE1234F"));
|
|
79
|
+
// true
|
|
80
|
+
|
|
81
|
+
console.log(isGSTIN("27ABCDE1234F1Z5"));
|
|
82
|
+
// true
|
|
83
|
+
|
|
84
|
+
console.log(isIFSC("HDFC0001234"));
|
|
85
|
+
// true
|
|
86
|
+
|
|
87
|
+
console.log(isUPI("person@upi"));
|
|
88
|
+
// true
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Individual validators return a boolean indicating whether the value passes the validation check.
|
|
92
|
+
|
|
93
|
+
## Validate a Value Using Rules
|
|
94
|
+
|
|
95
|
+
The `validate()` function allows you to combine multiple rules for a single value.
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
import { validate } from "@palakpreet/quick-validate";
|
|
99
|
+
|
|
100
|
+
const result = validate("bad-email", ["required", "email"]);
|
|
101
|
+
|
|
102
|
+
console.log(result);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Output:
|
|
106
|
+
|
|
107
|
+
```js
|
|
108
|
+
{
|
|
109
|
+
valid: false,
|
|
110
|
+
errors: [
|
|
111
|
+
"Please enter a valid email address."
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Available Rules
|
|
117
|
+
|
|
118
|
+
Rules can be supplied as strings, arrays, rule objects, or custom functions.
|
|
119
|
+
|
|
120
|
+
```js
|
|
121
|
+
const result = validate("hello", [
|
|
122
|
+
"required",
|
|
123
|
+
{ name: "minLength", value: 3 }
|
|
124
|
+
]);
|
|
125
|
+
|
|
126
|
+
console.log(result.valid);
|
|
127
|
+
// true
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Supported parameter-based rules include:
|
|
131
|
+
|
|
132
|
+
| Rule | Description | Example |
|
|
133
|
+
|---|---|---|
|
|
134
|
+
| `minLength` | Minimum string length | `{ name: "minLength", value: 3 }` |
|
|
135
|
+
| `maxLength` | Maximum string length | `{ name: "maxLength", value: 20 }` |
|
|
136
|
+
| `min` | Minimum numeric value | `{ name: "min", value: 18 }` |
|
|
137
|
+
| `max` | Maximum numeric value | `{ name: "max", value: 100 }` |
|
|
138
|
+
| `oneOf` | Value must match one of the allowed values | `{ name: "oneOf", values: ["red", "blue"] }` |
|
|
139
|
+
| `matches` | Value must match a regular expression | `{ name: "matches", pattern: /^[A-Z]+$/ }` |
|
|
140
|
+
|
|
141
|
+
## Validate an Entire Form
|
|
142
|
+
|
|
143
|
+
`validateSchema()` validates multiple fields together and returns field-specific errors.
|
|
144
|
+
|
|
145
|
+
```js
|
|
146
|
+
import { validateSchema } from "@palakpreet/quick-validate";
|
|
147
|
+
|
|
148
|
+
const schema = {
|
|
149
|
+
name: ["required", { name: "minLength", value: 2 }],
|
|
150
|
+
email: ["required", "email"],
|
|
151
|
+
age: [{ name: "min", value: 18 }]
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const data = {
|
|
155
|
+
name: "A",
|
|
156
|
+
email: "bad-email",
|
|
157
|
+
age: 16
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const result = validateSchema(data, schema);
|
|
161
|
+
|
|
162
|
+
console.log(result.valid);
|
|
163
|
+
// false
|
|
164
|
+
|
|
165
|
+
console.log(result.errors);
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Example result:
|
|
169
|
+
|
|
170
|
+
```js
|
|
171
|
+
{
|
|
172
|
+
valid: false,
|
|
173
|
+
errors: {
|
|
174
|
+
name: ["..."],
|
|
175
|
+
email: ["..."],
|
|
176
|
+
age: ["..."]
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Schema validation makes it possible to validate multiple fields and collect their errors in one operation.
|
|
182
|
+
|
|
183
|
+
## Custom Error Messages
|
|
184
|
+
|
|
185
|
+
You can provide your own messages for individual validation rules.
|
|
186
|
+
|
|
187
|
+
```js
|
|
188
|
+
const schema = {
|
|
189
|
+
email: {
|
|
190
|
+
rules: ["required", "email"],
|
|
191
|
+
messages: {
|
|
192
|
+
email: "Please enter a valid email address."
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
This allows error messages to be customized according to your application's needs.
|
|
199
|
+
|
|
200
|
+
## Custom Validation Rules
|
|
201
|
+
|
|
202
|
+
Add your own reusable validation rules using `addValidator()`.
|
|
203
|
+
|
|
204
|
+
```js
|
|
205
|
+
import {
|
|
206
|
+
addValidator,
|
|
207
|
+
validate
|
|
208
|
+
} from "@palakpreet/quick-validate";
|
|
209
|
+
|
|
210
|
+
addValidator("even", value => Number(value) % 2 === 0);
|
|
211
|
+
|
|
212
|
+
const result = validate(6, ["even"]);
|
|
213
|
+
|
|
214
|
+
console.log(result.valid);
|
|
215
|
+
// true
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Custom rules can be reused throughout your application.
|
|
219
|
+
|
|
220
|
+
## Additional Validation Helpers
|
|
221
|
+
|
|
222
|
+
```js
|
|
223
|
+
import {
|
|
224
|
+
validateField,
|
|
225
|
+
validateArray,
|
|
226
|
+
validateNested,
|
|
227
|
+
validateObject,
|
|
228
|
+
isFileValid
|
|
229
|
+
} from "@palakpreet/quick-validate";
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
| Function | Description |
|
|
233
|
+
|---|---|
|
|
234
|
+
| `validateField(data, schema, field)` | Validates a specific field |
|
|
235
|
+
| `validateArray(value, rules, options)` | Validates array values and constraints |
|
|
236
|
+
| `validateNested(data, schema)` | Validates nested objects |
|
|
237
|
+
| `validateObject(data, validatorFunctions)` | Validates an object using custom validator functions |
|
|
238
|
+
| `isFileValid(file, options)` | Validates file metadata such as size and type |
|
|
239
|
+
|
|
240
|
+
## Available Validators
|
|
241
|
+
|
|
242
|
+
### General Validators
|
|
243
|
+
|
|
244
|
+
- Presence and required values
|
|
245
|
+
- Email addresses
|
|
246
|
+
- Phone numbers
|
|
247
|
+
- Postal codes
|
|
248
|
+
- Passwords and password strength
|
|
249
|
+
- URLs and domains
|
|
250
|
+
- UUIDs
|
|
251
|
+
- IPv4 and IPv6 addresses
|
|
252
|
+
- IP addresses
|
|
253
|
+
- Credit card numbers using the Luhn algorithm
|
|
254
|
+
- Dates and date-time values
|
|
255
|
+
- Usernames
|
|
256
|
+
- Slugs
|
|
257
|
+
- Hexadecimal colours
|
|
258
|
+
- Alphanumeric values
|
|
259
|
+
- Numeric values and integers
|
|
260
|
+
- JSON strings
|
|
261
|
+
|
|
262
|
+
### Indian-Specific Validators
|
|
263
|
+
|
|
264
|
+
- Indian mobile numbers
|
|
265
|
+
- Indian PIN codes
|
|
266
|
+
- PAN
|
|
267
|
+
- GSTIN format
|
|
268
|
+
- IFSC
|
|
269
|
+
- UPI IDs
|
|
270
|
+
- Indian vehicle registration numbers
|
|
271
|
+
- Bank account format
|
|
272
|
+
|
|
273
|
+
### Additional Helpers
|
|
274
|
+
|
|
275
|
+
- Confirm password
|
|
276
|
+
- Minimum and maximum length
|
|
277
|
+
- Numeric range
|
|
278
|
+
- Regular expression matching
|
|
279
|
+
- Allowed values
|
|
280
|
+
- Array validation
|
|
281
|
+
- File metadata validation
|
|
282
|
+
|
|
283
|
+
## Running Tests
|
|
284
|
+
|
|
285
|
+
This project uses Node.js's built-in test runner.
|
|
286
|
+
|
|
287
|
+
Run the test suite using:
|
|
288
|
+
|
|
289
|
+
```bash
|
|
290
|
+
npm test
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
## Requirements
|
|
294
|
+
|
|
295
|
+
- Node.js 18 or later
|
|
296
|
+
- JavaScript
|
|
297
|
+
- ES Modules support
|
|
298
|
+
|
|
299
|
+
## Important Notes
|
|
300
|
+
|
|
301
|
+
This package validates input formats and rules. It does not verify values against official databases.
|
|
302
|
+
|
|
303
|
+
- PAN and GSTIN validation checks format, not registration status.
|
|
304
|
+
- IFSC validation checks format, not whether a bank branch currently exists.
|
|
305
|
+
- Credit card validation checks the Luhn algorithm, not whether a card is active or authorized.
|
|
306
|
+
- File validation checks metadata. Uploaded files must still be inspected securely on the server.
|
|
307
|
+
|
|
308
|
+
## License
|
|
309
|
+
|
|
310
|
+
MIT License
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@palakpreet/quick-validate",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "A lightweight JavaScript validation library for forms, objects, and common inputs.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./src/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./src/index.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"src",
|
|
13
|
+
"README.md",
|
|
14
|
+
"LICENSE"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"test": "node --test",
|
|
18
|
+
"demo": "node demo/server.js"
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=18"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"validation",
|
|
25
|
+
"validator",
|
|
26
|
+
"javascript",
|
|
27
|
+
"forms",
|
|
28
|
+
"email",
|
|
29
|
+
"india",
|
|
30
|
+
"npm"
|
|
31
|
+
],
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/Palakpreet-Kaur-Bhullar/quick-validate-v2"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/Palakpreet-Kaur-Bhullar/quick-validate-v2/blob/main/README.md"
|
|
37
|
+
}
|