number-type

0.2.1 • Public • Published

number-type npm

Build Status Code Climate Test Coverage downloads license

The number type.

Usage

var NumberType  = require('number-type')
var Number      = NumberType('number')
var Int         = NumberType('int')
var PositiveInt = Int.createType min:0
 
var n = PositiveInt.create(123)
console.log(1 + n)
//=124
console.log(n.isValid())
//=true
console.log(n.toJson()))
//='123'
console.log(n.toJson({withType:true})))
//='{"value":123,"name":"Int","min":0}'
console.log(PositiveInt.isValid(-1))
//=false
n.assign(-1)
//=TypeError: "-1" is an invalid Int
console.log(n.assign(2)+0)
//=2

API

See abstract-type

TODO

License

MIT

Package Sidebar

Install

npm i number-type

Weekly Downloads

10

Version

0.2.1

License

MIT

Last publish

Collaborators

  • riceball