Skip to content

Commit

Permalink
add t.Integer to standard types
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed Mar 24, 2016
1 parent c0970d4 commit 5b79c2c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

- **New Feature**
- Chrome Dev Tools custom formatter for tcomb types
- add `t.Integer` to standard types

# v3.0.0

Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 4 additions & 0 deletions lib/Integer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var refinement = require('./refinement');
var Number = require('./Number');

module.exports = refinement(Number, function (x) { return x % 1 === 0; }, 'Integer');
14 changes: 14 additions & 0 deletions test/refinement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

});

});

0 comments on commit 5b79c2c

Please sign in to comment.