@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,
name: 'string'
})
const user = User.from({
id: '1',
name: 'Steve'
})
console.log(user)
const Order = skema({
id: String,
createTime: Date
})
Order.from({
id: '6352534847126241280',
createTime: 'hahahaha'
})
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: '1',
name: 'Steve'
})