1.0.40 • Published 4 years ago

@skema/basic v1.0.40

Weekly downloads
338
License
MIT
Repository
github
Last release
4 years ago

@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

4 years ago

1.0.40

4 years ago

1.0.36

5 years ago

1.0.35

5 years ago

1.0.34

5 years ago

1.0.33

5 years ago

1.0.32

5 years ago

1.0.31

5 years ago

1.0.30

5 years ago

1.0.29

5 years ago

1.0.28

6 years ago

1.0.27

6 years ago

1.0.26

6 years ago

1.0.25

6 years ago

1.0.24

6 years ago

1.0.23

6 years ago

1.0.22

6 years ago

1.0.21

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago