🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

@skema/basic

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@skema/basic

Basic types for skema

latest
Source
npmnpm
Version
1.0.40
Version published
Weekly downloads
138
-26.6%
Maintainers
1
Weekly downloads
 
Created
Source

@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

Keywords

skema

FAQs

Package last updated on 05 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts