Skip to content

Commit cc01a06

Browse files
committed
fixed more docs
1 parent 0f5d5ab commit cc01a06

File tree

4 files changed

+83
-28
lines changed

4 files changed

+83
-28
lines changed

docs/.vitepress/config.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default defineConfig({
2828
{
2929
text: "Introduction",
3030
items: [
31-
{ text: "Why?", link: "/why" },
31+
{ text: "Purpose", link: "/purpose" },
3232
{ text: "Getting started", link: "/getting-started" },
3333
{ text: "Examples", link: "/examples" },
3434
{ text: "Terminology", link: "/terminology" },

docs/purpose.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Purpose
2+
3+
Most validation libraries are either hard to use, missing key features, or no longer maintained. It’s tough to find one that lets you reuse rules, supports multiple languages, and still feels easy to work with.
4+
5+
Robust Validator was built to solve that. It makes validation simple, reusable, and flexible. You can define your rules once and use them anywhere, and it works great with multiple languages out of the box.
6+
7+
If you want a validation library that just works, is easy to read, and stays up to date, Robust Validator is a solid choice.
8+
9+
<section class="principles">
10+
<div class="principles-title">Design Principles</div>
11+
<div class="principles-list">
12+
<div class="principles-list-item">⚡ Each validation rule is a standalone function.</div>
13+
<div class="principles-list-item">⚡ Rules can be used on their own.</div>
14+
<div class="principles-list-item">⚡ Definitions can live anywhere such as database, config, memory, or API.</div>
15+
<div class="principles-list-item">⚡ Every rule supports multiple languages out of the box.</div>
16+
<div class="principles-list-item">⚡ Adding new rules is simple and straightforward.</div>
17+
<div class="principles-list-item">⚡ Everything is clearly and practically documented.</div>
18+
</div>
19+
</section>

docs/why.md

Lines changed: 0 additions & 19 deletions
This file was deleted.

readme.md

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ Rule-based data validation in JS. Extendable, function-oriented, i18n-supported
2626

2727
[Documentation](https://validator.axe-api.com/)
2828

29-
## 💡 Why?
29+
## Why?
3030

31-
Discovering a data validation library that seamlessly combines ease of use, the ability to store validation rules for future use, and robust internationalization (i18n) support is a formidable challenge. While numerous data validation libraries exist, finding one that fulfills all these criteria is often elusive. Some libraries that do meet these requirements are unfortunately no longer actively maintained.
31+
Most validation libraries are either hard to use, missing key features, or no longer maintained. It’s tough to find one that lets you reuse rules, supports multiple languages, and still feels easy to work with.
3232

33-
Robust Validator was born out of the need for a versatile data validation solution that not only simplifies the validation process but also empowers developers with the flexibility to preserve and reuse validation rules. This library aims to bridge the gap by offering a user-friendly experience, ensuring your validation needs are met comprehensively.
33+
Robust Validator was built to solve that. It makes validation simple, reusable, and flexible. You can define your rules once and use them anywhere, and it works great with multiple languages out of the box.
3434

35-
Why choose Robust Validator? It's more than just a data validation tool; it's a commitment to providing a reliable, well-maintained, and feature-rich solution for developers who value simplicity and effectiveness in their projects.
35+
If you want a validation library that just works, is easy to read, and stays up to date, Robust Validator is a solid choice.
3636

37-
## 🤞 Principles
37+
## Principles
3838

3939
I decided on some fundamental rules while building this library:
4040

@@ -53,7 +53,7 @@ The library can be installed into an existing project:
5353
$ npm install --save robust-validator
5454
```
5555

56-
## 💪 Usage
56+
## Usage
5757

5858
Using robust-validator is very simple.
5959

@@ -80,14 +80,69 @@ const result = await validate(data, definition);
8080
console.log(result);
8181
```
8282

83-
## 🤝 Contributors
83+
## Nested data validation
84+
85+
This feature allows dynamic traversal of nested data structures, supporting complex validation rules for paths like `users.*.addresses.*.city`.
86+
87+
It is inspired by Laravel's validation system and works seamlessly with arrays and objects, including deeply nested data.
88+
89+
```ts
90+
import { validate, setLocales, en } from "robust-validator";
91+
92+
setLocales(en);
93+
94+
const data = {
95+
secret: "some secret",
96+
users: [
97+
{ addresses: [{ city: "New York" }, { city: "Istanbul" }] },
98+
{ addresses: [{ city: "New York" }, { street: "Wall Street" }] },
99+
],
100+
permissons: { read: true, write: true },
101+
};
102+
103+
const definition = {
104+
secret: "required|min:100",
105+
"users.*.addresses.*.city": "required",
106+
"permissons.read": "required|boolean",
107+
"permissons.delete": "required|boolean",
108+
};
109+
110+
const result = await validate(data, definition);
111+
console.log(result);
112+
```
113+
114+
And this is the content of the `result` variable:
115+
116+
```json
117+
{
118+
"isValid": false,
119+
"isInvalid": true,
120+
"fields": {
121+
"secret": false,
122+
"users.*.addresses.*.city": false,
123+
"permissons.read": true,
124+
"permissons.delete": false
125+
},
126+
"errors": {
127+
"secret": [{ "rule": "min", "message": "The field must be at least 100." }],
128+
"users.1.addresses.1.city": [
129+
{ "rule": "required", "message": "The field is required." }
130+
],
131+
"permissons.delete": [
132+
{ "rule": "required", "message": "The field is required." }
133+
]
134+
}
135+
}
136+
```
137+
138+
## Contributors
84139

85140
<a href="https://github.com/axe-api/validator/graphs/contributors">
86141
<img src="https://contrib.rocks/image?repo=axe-api/validator" />
87142
</a>
88143

89144
Made with [contrib.rocks](https://contrib.rocks).
90145

91-
## ⚖️ License
146+
## License
92147

93148
[MIT License](LICENSE)

0 commit comments

Comments
 (0)