From 5b79c2ce893bf074a7ad64cbd5a675a65cbc6471 Mon Sep 17 00:00:00 2001 From: gcanti Date: Thu, 24 Mar 2016 07:58:57 +0100 Subject: [PATCH] add `t.Integer` to standard types --- CHANGELOG.md | 1 + index.js | 1 + lib/Integer.js | 4 ++++ test/refinement.js | 14 ++++++++++++++ 4 files changed, 20 insertions(+) create mode 100644 lib/Integer.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 21d3185..f720e98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - **New Feature** - Chrome Dev Tools custom formatter for tcomb types + - add `t.Integer` to standard types # v3.0.0 diff --git a/index.js b/index.js index 3030594..3a093a1 100644 --- a/index.js +++ b/index.js @@ -18,6 +18,7 @@ t.Error = require('./lib/Error'); t.Function = require('./lib/Function'); t.Nil = require('./lib/Nil'); t.Number = require('./lib/Number'); +t.Integer = require('./lib/Integer'); t.Object = require('./lib/Object'); t.RegExp = require('./lib/RegExp'); t.String = require('./lib/String'); diff --git a/lib/Integer.js b/lib/Integer.js new file mode 100644 index 0000000..9ace852 --- /dev/null +++ b/lib/Integer.js @@ -0,0 +1,4 @@ +var refinement = require('./refinement'); +var Number = require('./Number'); + +module.exports = refinement(Number, function (x) { return x % 1 === 0; }, 'Integer'); diff --git a/test/refinement.js b/test/refinement.js index 88ca25f..8723f62 100644 --- a/test/refinement.js +++ b/test/refinement.js @@ -112,4 +112,18 @@ describe('t.refinement(type, predicate, [name])', function () { }); + describe('Integer type', function () { + + it('should type check integers', function () { + assert.equal(t.Integer.is(0), true); + assert.equal(t.Integer.is(-0), true); + assert.equal(t.Integer.is(0.0), true); + assert.equal(t.Integer.is(10), true); + assert.equal(t.Integer.is(-10), true); + assert.equal(t.Integer.is(0.5), false); + assert.equal(t.Integer.is(-0.5), false); + }); + + }); + });