0.2.1 • Published 3 years ago

number-type v0.2.1

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

number-type npm

Build Status Code Climate Test Coverage downloads license

The number type.

Usage

import { NumberType, Type } from 'number-type'

const Number      = Type.get('number')
const Int         = Type.get('int')

class PositiveInt extends Int {
  static min = 0
}

var n = new PositiveInt(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