@local901/validator 0.0.3 → 0.0.4
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/README.md +29 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# js-validator
|
|
2
|
+
|
|
3
|
+
Validator for javascript and typescript. Do you have an object with uncertain contents. USe a validator to make sure what you have.
|
|
4
|
+
|
|
5
|
+
Quick start:
|
|
6
|
+
```shell
|
|
7
|
+
npm install @local901/validator
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
Example:
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { v } from "@local901/validator";
|
|
14
|
+
|
|
15
|
+
type Example = {
|
|
16
|
+
message: string;
|
|
17
|
+
isPublic?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const validator = v.object<Example>({
|
|
21
|
+
message: v.string({ min: 6 }),
|
|
22
|
+
isPublic: v.optional(v.boolean()),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
validator.validate({ message: "example" }) // returns true
|
|
26
|
+
validator.validate({ message: "short" }) // returns false
|
|
27
|
+
|
|
28
|
+
validator.validateOrThrow(15) // throws error.
|
|
29
|
+
```
|