1.0.40 • Published 5 years ago
@skema/basic v1.0.40
@skema/basic
skema
type definitions for basic javascript types, including:
String
('string'
)Number
('number'
)Date
('date'
)RegExp
('regexp'
)Object
('object'
)Function
('function'
)Error
('error'
)Symbol
('symbol'
)
install
npm i @skema/basic
LOOSE
The basic type definitions that it convert the properties of wrong values into the right ones if possible.
import {defaults} from 'skema'
import {LOOSE} from '@skema/basic'
const {
skema
} = defaults({
types: LOOSE
})
const User = skema({
id: Number, // To use 'number' is also ok
name: 'string' // To use String is also ok
})
const user = User.from({
id: '1', // id will be converted to `1`
name: 'Steve'
})
console.log(user)
// {
// id: 1,
// name: 'Steve'
// }
const Order = skema({
id: String,
createTime: Date
})
Order.from({
id: '6352534847126241280',
createTime: 'hahahaha' // Oh, this date is gone too far!
})
// Error thrown
STRICT
The very strict type definition, that it will throw if the given data doesn't match the type of the schema.
import {defaults} from 'skema'
import {STRICT} from '@skema/basic'
const {
skema
} = defaults({
types: STRICT
})
const User = skema({
id: Number,
name: String
})
const user = User.from({
// id must be a number
id: '1',
name: 'Steve'
})
// Error thrown
1.0.39
5 years ago
1.0.40
5 years ago
1.0.36
6 years ago
1.0.35
6 years ago
1.0.34
6 years ago
1.0.33
6 years ago
1.0.32
6 years ago
1.0.31
6 years ago
1.0.30
6 years ago
1.0.29
6 years ago
1.0.28
7 years ago
1.0.27
7 years ago
1.0.26
7 years ago
1.0.25
7 years ago
1.0.24
7 years ago
1.0.23
7 years ago
1.0.22
7 years ago
1.0.21
7 years ago
1.0.20
7 years ago
1.0.19
7 years ago
1.0.18
7 years ago
1.0.17
7 years ago
1.0.16
7 years ago
1.0.15
7 years ago
1.0.14
7 years ago
1.0.13
7 years ago
1.0.12
7 years ago
1.0.11
7 years ago
1.0.10
7 years ago
1.0.9
7 years ago
1.0.8
7 years ago
1.0.7
7 years ago
1.0.6
7 years ago
1.0.5
7 years ago
1.0.4
7 years ago
1.0.3
7 years ago
1.0.2
7 years ago
1.0.1
7 years ago