@serum-enterprises/schema 2.0.1-beta.2 → 3.0.0-beta.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/README.md +15 -25
- package/build/index.js +1031 -0
- package/build/index.js.map +7 -0
- package/package.json +13 -11
- package/test.ts +13 -0
- package/types/Validator.d.ts +9 -0
- package/types/index.d.ts +33 -0
- package/types/lib/util.d.ts +29 -0
- package/types/validators/Array.d.ts +37 -0
- package/types/validators/Boolean.d.ts +21 -0
- package/types/validators/JSON.d.ts +14 -0
- package/types/validators/Number.d.ts +30 -0
- package/types/validators/Object.d.ts +56 -0
- package/types/validators/String.d.ts +27 -0
- package/build/Schema.js +0 -667
- package/src/Schema.ts +0 -887
- package/tsconfig.json +0 -30
- package/types/Schema.d.ts +0 -99
package/README.md
CHANGED
|
@@ -5,40 +5,30 @@ Modern Schema Validation Library inspired by Joi.dev
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install --save @serum-enterprises/schema
|
|
8
|
+
npm install --save @serum-enterprises/schema@3.0.0-beta.1
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
13
|
```typescript
|
|
14
|
-
import Schema from '@serum-enterprises/schema';
|
|
15
|
-
|
|
16
|
-
const schema = Schema.Object
|
|
17
|
-
.
|
|
18
|
-
.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
friends: Schema.Array
|
|
22
|
-
.every(
|
|
23
|
-
Schema.Or.oneOf([
|
|
24
|
-
Schema.Object
|
|
25
|
-
.schema({
|
|
26
|
-
name: Schema.String,
|
|
27
|
-
age: Schema.Number.min(18).max(99)
|
|
28
|
-
}),
|
|
29
|
-
Schema.String
|
|
30
|
-
])
|
|
31
|
-
)
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
schema.validate({ name: 'John', age: 20, friends: [{ name: "Maria", age: 22 }] });
|
|
35
|
-
```
|
|
14
|
+
import {Schema} from '@serum-enterprises/schema';
|
|
15
|
+
|
|
16
|
+
const schema = Schema.Object.nullable().shape({
|
|
17
|
+
name: Schema.String,
|
|
18
|
+
age: Schema.Number.integer().min(18).max(99),
|
|
19
|
+
friends: Schema.Array.every(Schema.String)
|
|
20
|
+
}).exact();
|
|
36
21
|
|
|
37
|
-
|
|
22
|
+
const person = schema.validate({name: 'John', age: 20, friends: ["Jane", "Mary"]});
|
|
23
|
+
|
|
24
|
+
console.log(person.name);
|
|
25
|
+
console.log(person.age);
|
|
26
|
+
console.log(person.friends.join(', '));
|
|
27
|
+
```
|
|
38
28
|
|
|
39
29
|
## API
|
|
40
30
|
|
|
41
|
-
Please check [
|
|
31
|
+
Please check [index.d.ts](./types/index.d.ts) for the full API.
|
|
42
32
|
|
|
43
33
|
## LICENSE
|
|
44
34
|
|