Skip to content

Commit 3e83d56

Browse files
zmaroufzeid
authored andcommitted
Update readme
1 parent ab78b45 commit 3e83d56

File tree

5 files changed

+47
-47
lines changed

5 files changed

+47
-47
lines changed

README.md

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
* fast! Really!
1515
* 13 built-in validators
1616
* custom validators
17-
* nested object & array handling
17+
* nested objects & array handling
1818
* multiple validators
1919
* customizable error messages
2020
* programmable error object
2121
* no dependencies
22-
* unit tests & 100% cover
22+
* unit tests & 100% coverage
2323

2424
# How fast?
25-
Very fast! ~5 million validation/sec (on Intel i7-4770K, Node.JS: 8.11.0)
25+
Very fast! ~5 million validations/sec (on Intel i7-4770K, Node.JS: 8.11.0)
2626
```
2727
√ validate with pre-compiled schema 5,460,129 rps
2828
```
@@ -56,7 +56,7 @@ $ yarn add fastest-validator
5656

5757
### Simple method
5858
Call the `validate` method with the `object` and the `schema`.
59-
> If the performance is important, you won't use this method.
59+
> If performance is important, you won't use this method.
6060
6161
```js
6262
let Validator = require("fastest-validator");
@@ -80,16 +80,16 @@ console.log(v.validate({ id: 5, name: "Al", status: true }, schema));
8080
expected: 3,
8181
actual: 2,
8282
field: 'name',
83-
message: 'The \'name\' field length must be larger than or equal to 3 characters long!'
83+
message: 'The \'name\' field length must be greater than or equal to 3 characters long!'
8484
}
8585
]
8686
*/
8787
```
8888
[Try it on Runkit](https://runkit.com/icebob/fastest-validator-usage-simple)
8989

9090
### Fast method
91-
In this case, the first step is to compile the schema to a compiled "checker" function. After it if you would like to validate your object, just call this "checker" function with your object.
92-
> This method is ~10x faster than "simple method".
91+
In this case, the first step is to compile the schema to a compiled "checker" function. After that, to validate your object, just call this "checker" function.
92+
> This method is ~10x faster than the "simple method".
9393
9494
```js
9595
let Validator = require("fastest-validator");
@@ -141,7 +141,7 @@ console.log(check({ id: 5, name: "John", status: true }));
141141
```
142142

143143
# Optional & required fields
144-
Every fields in the schema will be required field. If you would like to define optional fields, set `optional: true`.
144+
Every field in the schema will be required by default. If you'd like to define optional fields, set `optional: true`.
145145

146146
```js
147147
let schema = {
@@ -155,7 +155,7 @@ v.validate({ age: 42 }, schema); // Fail
155155
```
156156

157157
# Multiple validators
158-
There is possible to define more validators for a field. In this case if one of all validators is success, the field will be valid.
158+
It is possible to define more validators for a field. In this case, only one validator needs to succeed for the field to be valid.
159159

160160
```js
161161
let schema = {
@@ -173,7 +173,7 @@ v.validate({ cache: 150 }, schema); // Fail
173173
# Built-in validators
174174

175175
## `any`
176-
This is not validate the type of value. Accept any types.
176+
This does not do type validation. Accepts any types.
177177

178178
```js
179179
let schema = {
@@ -199,7 +199,7 @@ v.validate({ roles: [] }, schema); // Valid
199199
v.validate({ roles: "user" }, schema); // Fail
200200
```
201201

202-
**Example with only positive number:**
202+
**Example with only positive numbers:**
203203
```js
204204
let schema = {
205205
list: { type: "array", min: 2, items: {
@@ -213,7 +213,7 @@ v.validate({ list: [1] }, schema); // Fail (min 2 elements)
213213
v.validate({ list: [1, -7] }, schema); // Fail (negative number)
214214
```
215215

216-
**Example with object list:**
216+
**Example with an object list:**
217217
```js
218218
let schema = {
219219
users: { type: "array", items: {
@@ -238,11 +238,11 @@ v.validate({
238238
### Properties
239239
Property | Default | Description
240240
-------- | -------- | -----------
241-
`empty` | `true` | If true, the validator accepts empty array `[]`.
241+
`empty` | `true` | If true, the validator accepts an empty array `[]`.
242242
`min` | `null` | Minimum count of elements.
243243
`max` | `null` | Maximum count of elements.
244244
`length` | `null` | Fix count of elements.
245-
`contains` | `null` | The array must contains this element too.
245+
`contains` | `null` | The array must contain this element too.
246246
`enum` | `null` | Every element must be an element of the `enum` array.
247247

248248
**Example for `enum`:**
@@ -331,7 +331,7 @@ Property | Default | Description
331331

332332

333333
## `forbidden`
334-
This validator gives error if the property is exists in the object.
334+
This validator returns an error if the property exists in the object.
335335

336336
```js
337337
let schema = {
@@ -343,7 +343,7 @@ v.validate({ user: "John", password: "pass1234" }, schema); // Fail
343343
```
344344

345345
## `function`
346-
The type of value must be `Function`.
346+
This a `Function`validator.
347347

348348
```js
349349
let schema = {
@@ -357,7 +357,7 @@ v.validate({ show: null }, schema); // Fail
357357

358358

359359
## `number`
360-
This is a number validator. The type of value must be `Number`.
360+
This is a `Number` validator.
361361

362362
```js
363363
let schema = {
@@ -374,12 +374,12 @@ Property | Default | Description
374374
-------- | -------- | -----------
375375
`min` | `null` | Minimum value.
376376
`max` | `null` | Maximum value.
377-
`equal` | `null` | Fix value.
378-
`notEqual` | `null` | Can't be equal with this value.
377+
`equal` | `null` | Fixed value.
378+
`notEqual` | `null` | Can't be equal to this value.
379379
`integer` | `false` | The value must be a non-decimal value.
380-
`positive` | `false`| The value must be larger than zero.
380+
`positive` | `false`| The value must be greater than zero.
381381
`negative` | `false`| The value must be less than zero.
382-
`convert` | `false`| if `true` and the type is not `Number`, try to convert with `parseFloat`.
382+
`convert` | `false`| if `true` and the type is not `Number`, tries to convert with `parseFloat`.
383383

384384
## `object`
385385
This is a nested object validator.
@@ -410,7 +410,7 @@ v.validate({
410410

411411

412412
## `string`
413-
This is a `string` validator. The type of value must be `String`.
413+
This is a `String`.
414414

415415
```js
416416
let schema = {
@@ -425,12 +425,12 @@ v.validate({ name: 123 }, schema); // Fail
425425
### Properties
426426
Property | Default | Description
427427
-------- | -------- | -----------
428-
`empty` | `true` | If true, the validator accepts empty string `""`.
429-
`min` | `null` | Minimum length of value.
430-
`max` | `null` | Maximum length of value.
431-
`length` | `null` | Fix length of value.
428+
`empty` | `true` | If true, the validator accepts an empty string `""`.
429+
`min` | `null` | Minimum value length.
430+
`max` | `null` | Maximum value length.
431+
`length` | `null` | Fixed value length.
432432
`pattern` | `null` | Regex pattern.
433-
`contains` | `null` | The value must contains this text.
433+
`contains` | `null` | The value must contain this text.
434434
`enum` | `null` | The value must be an element of the `enum` array.
435435

436436

@@ -486,12 +486,12 @@ console.log(v.validate({ name: "John", age: 19 }, schema));
486486
*/
487487
```
488488

489-
Or you can use the `custom` type with inline checker function:
489+
Or you can use the `custom` type with an inline checker function:
490490
```js
491491
let v = new Validator({
492492
messages: {
493493
// Register our new error message text
494-
weightMin: "The weight must be larger than {expected}! Actual: {actual}"
494+
weightMin: "The weight must be greater than {expected}! Actual: {actual}"
495495
}
496496
});
497497

@@ -518,13 +518,13 @@ console.log(v.validate({ name: "John", weight: 8 }, schema));
518518
expected: 10,
519519
actual: 8,
520520
field: 'weight',
521-
message: 'The weight must be larger than 10! Actual: 8'
521+
message: 'The weight must be greater than 10! Actual: 8'
522522
}]
523523
*/
524524
```
525525

526526
# Custom error messages (l10n)
527-
You can set your custom messages in constructor of validator.
527+
You can set your custom messages in the validator constructor.
528528

529529
```js
530530
const Validator = require("fastest-validator");
@@ -555,14 +555,14 @@ Name | Default text
555555
`required` | The '{field}' field is required!
556556
`string` | The '{field}' field must be a string!
557557
`stringEmpty` | The '{field}' field must not be empty!
558-
`stringMin` | The '{field}' field length must be larger than or equal to {expected} characters long!
558+
`stringMin` | The '{field}' field length must be greater than or equal to {expected} characters long!
559559
`stringMax` | The '{field}' field length must be less than or equal to {expected} characters long!
560560
`stringLength` | The '{field}' field length must be {expected} characters long!
561561
`stringPattern` | The '{field}' field fails to match the required pattern!
562562
`stringContains` | The '{field}' field must contain the '{expected}' text!
563563
`stringEnum` | The '{field}' field does not match any of the allowed values!
564564
`number` | The '{field}' field must be a number!
565-
`numberMin` | The '{field}' field must be larger than or equal to {expected}!
565+
`numberMin` | The '{field}' field must be greater than or equal to {expected}!
566566
`numberMax` | The '{field}' field must be less than or equal to {expected}!
567567
`numberEqual` | The '{field}' field must be equal with {expected}!
568568
`numberNotEqual` | The '{field}' field can't be equal with {expected}!
@@ -579,18 +579,18 @@ Name | Default text
579579
`boolean` | The '{field}' field must be a boolean!
580580
`function` | The '{field}' field must be a function!
581581
`date` | The '{field}' field must be a Date!
582-
`dateMin` | The '{field}' field must be larger than or equal to {expected}!
582+
`dateMin` | The '{field}' field must be greater than or equal to {expected}!
583583
`dateMax` | The '{field}' field must be less than or equal to {expected}!
584584
`forbidden` | The '{field}' field is forbidden!
585585
`email` | The '{field}' field must be a valid e-mail!
586586

587587
## Message fields
588588
Name | Description
589589
----------- | -------------
590-
`field` | Name of field
591-
`expected` | The expected value of field
592-
`actual` | The actual value of field
593-
`type` | Type of field
590+
`field` | The field name
591+
`expected` | The expected value
592+
`actual` | The actual value
593+
`type` | The field type
594594

595595
## Development
596596
```
@@ -627,7 +627,7 @@ All files | 100 | 100 | 100 | 100 | |
627627
```
628628

629629
## Contribution
630-
Please send pull requests improving the usage and fixing bugs, improving documentation and providing better examples, or providing some testing, because these things are important.
630+
Please send pull requests improving the usage and fixing bugs, improving documentation and providing better examples, or providing some tests, because these things are important.
631631

632632
## License
633633
fastest-validator is available under the [MIT license](https://tldrlegal.com/license/mit-license).

examples/custom.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ let v = new Validator({
44
messages: {
55
// Register our new error message text
66
evenNumber: "The '{field}' field must be an even number! Actual: {actual}",
7-
weightMin: "The weight must be larger than {expected}! Actual: {actual}"
7+
weightMin: "The weight must be greater than {expected}! Actual: {actual}"
88
}
99
});
1010

@@ -54,6 +54,6 @@ console.log(v.validate({ name: "John", age: 20, weight: 8 }, schema));
5454
expected: 10,
5555
actual: 8,
5656
field: 'weight',
57-
message: 'The weight must be larger than 10! Actual: 8'
57+
message: 'The weight must be greater than 10! Actual: 8'
5858
}]
5959
*/

examples/start.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ console.log(v.validate({ id: 5, name: "Al", status: true }, schema));
2121
2
2222
],
2323
field: 'name',
24-
message: 'The \'name\' field length must be larger than or equal to 3 characters long!'
24+
message: 'The \'name\' field length must be greater than or equal to 3 characters long!'
2525
}
2626
]
2727
*/

lib/messages.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ module.exports = {
55

66
string: "The '{field}' field must be a string!",
77
stringEmpty: "The '{field}' field must not be empty!",
8-
stringMin: "The '{field}' field length must be larger than or equal to {expected} characters long!",
8+
stringMin: "The '{field}' field length must be greater than or equal to {expected} characters long!",
99
stringMax: "The '{field}' field length must be less than or equal to {expected} characters long!",
1010
stringLength: "The '{field}' field length must be {expected} characters long!",
1111
stringPattern: "The '{field}' field fails to match the required pattern!",
1212
stringContains: "The '{field}' field must contain the '{expected}' text!",
1313
stringEnum: "The '{field}' field does not match any of the allowed values!",
1414

1515
number: "The '{field}' field must be a number!",
16-
numberMin: "The '{field}' field must be larger than or equal to {expected}!",
16+
numberMin: "The '{field}' field must be greater than or equal to {expected}!",
1717
numberMax: "The '{field}' field must be less than or equal to {expected}!",
1818
numberEqual: "The '{field}' field must be equal with {expected}!",
1919
numberNotEqual: "The '{field}' field can't be equal with {expected}!",
@@ -34,7 +34,7 @@ module.exports = {
3434
function: "The '{field}' field must be a function!",
3535

3636
date: "The '{field}' field must be a Date!",
37-
dateMin: "The '{field}' field must be larger than or equal to {expected}!",
37+
dateMin: "The '{field}' field must be greater than or equal to {expected}!",
3838
dateMax: "The '{field}' field must be less than or equal to {expected}!",
3939

4040
forbidden: "The '{field}' field is forbidden!",

test/validator.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ describe("Test compile (integration test)", () => {
284284
expect(res[0]).toEqual({
285285
type: "stringMin",
286286
field: "name",
287-
message: "The 'name' field length must be larger than or equal to 5 characters long!",
287+
message: "The 'name' field length must be greater than or equal to 5 characters long!",
288288
expected: 5,
289289
actual: 4
290290
});
@@ -397,7 +397,7 @@ describe("Test 3 level nested schema", () => {
397397
expect(res.length).toBe(1);
398398
expect(res[0].type).toBe("stringMin");
399399
expect(res[0].field).toBe("a.b.c");
400-
expect(res[0].message).toBe("The 'a.b.c' field length must be larger than or equal to 5 characters long!");
400+
expect(res[0].message).toBe("The 'a.b.c' field length must be greater than or equal to 5 characters long!");
401401
});
402402

403403
});

0 commit comments

Comments
 (0)