23.0.3 • Published 4 months ago
@voltiso/schemar v23.0.3
Schema validation.
Usage
import * as s from '@voltiso/schemar'
const myShape = {
name: s.string,
version: s.string.regex(/^[0-9]+\.[0-9]+\.[0-9]+$/), // simplified
license: s.string.regex(/^[A-Z][0-9]$/).optional,
dependencies: {
'@voltiso/schemar': s.string.default('9.0.0'), // we need this!
},
}
const value = s.schema(myShape).validate({ name: 'a', version: '1.0.0' })
// --> {
// name: 'a',
// version: '1.0.0',
// dependencies: {
// '@voltiso/schemar': '9.0.0',
// },
// }
Infer TS Types
const mySchema = s.schema(myShape)
type MySchema = typeof mySchema.Output
// --> {
// name: string
// version: string
// license?: string
// dependencies: {
// '@voltiso/schemar': string
// }
// }
type MySchemaInput = typeof mySchema.Input
// --> {
// name: string;
// version: string;
// license?: string | undefined;
// dependencies?: {
// "@voltiso/schemar"?: string | undefined;
// } | undefined;
// }
exec
- get full validation information and issues list
import * as s from '@voltiso/schemar'
const myShape = {
field: s.number,
}
const result = s.schema(myShape).exec({ field: 123 })
// --> {
// isValid: true,
// issues: [],
// value: { field: 123 },
// }
23.0.3
4 months ago
23.0.2
5 months ago
23.0.0
6 months ago
23.0.1
6 months ago
22.1.13
6 months ago
22.1.9
1 year ago
22.1.8
1 year ago
22.1.7
1 year ago
22.1.6
1 year ago
22.1.5
1 year ago
22.1.4
1 year ago
22.1.12
1 year ago
22.1.10
1 year ago
22.1.11
1 year ago
22.1.2
1 year ago
22.1.1
1 year ago
22.1.0
1 year ago
22.0.0
1 year ago
22.1.3
1 year ago
21.0.1
1 year ago
21.0.0
1 year ago
19.0.1
1 year ago
19.0.0
1 year ago
18.0.2
1 year ago
18.0.1
1 year ago
18.0.0
1 year ago
17.2.1
1 year ago
17.0.3
1 year ago
17.0.2
2 years ago
17.2.3
1 year ago
17.0.5
1 year ago
17.2.2
1 year ago
17.0.4
1 year ago
17.1.0
1 year ago
17.0.0
2 years ago
20.0.0
1 year ago
16.2.4
2 years ago
16.4.1
2 years ago
16.2.3
2 years ago
16.4.0
2 years ago
16.3.1
2 years ago
16.2.2
2 years ago
16.3.0
2 years ago
16.2.1
2 years ago
16.2.0
2 years ago
16.1.1
2 years ago
16.1.0
2 years ago
16.0.0
2 years ago