number-type

number type info object.

Usage no npm install needed!

<script type="module">
  import numberType from 'https://cdn.skypack.dev/number-type';
</script>

README

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