Skip to content

Commit

Permalink
Merge pull request #118 from imbrn/fix/integer-rule
Browse files Browse the repository at this point in the history
Fix bug with `integer` rule
  • Loading branch information
imbrn authored Aug 29, 2018
2 parents 286b97b + f4bb141 commit 7fac227
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- Bug with polyfill for `integer` rule

## [1.2.1] - 2018-08-17

### Changed
Expand Down
9 changes: 7 additions & 2 deletions src/v8n.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const availableRules = {
return testIncludes(expected);
},

integer: () => value => Number.isInteger(value) || testIntegerPolyfill(value),
integer: () => testInteger(),

schema: schema => testSchema(schema),

Expand Down Expand Up @@ -221,7 +221,12 @@ function testIncludes(expected) {
return value => value.indexOf(expected) !== -1;
}

function testIntegerPolyfill(value) {
function testInteger() {
const isInteger = Number.isInteger || isIntegerPolyfill;
return value => isInteger(value);
}

function isIntegerPolyfill(value) {
return (
typeof value === "number" && isFinite(value) && Math.floor(value) === value
);
Expand Down

0 comments on commit 7fac227

Please sign in to comment.