Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feature)Add in Number.IsInteger #214

Merged
merged 1 commit into from Aug 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions README.md
Expand Up @@ -141,6 +141,7 @@ then Lodash/Underscore is the better option.*
1. [_.gte](#_gte)
1. [_.isEmpty](#_isempty)
1. [_.isFinite](#_isfinite)
1. [_.isInteger](#_isInteger)
1. [_.isNaN](#_isnan)
1. [_.isNil](#_isnil)
1. [_.isNull](#_isnull)
Expand Down Expand Up @@ -1719,6 +1720,31 @@ Converts value to a finite number.

**[⬆ back to top](#quick-links)**

### _.isInteger

Checks if value is an integer.

```js
// Lodash
console.log(_.isInteger(3))
cylim marked this conversation as resolved.
Show resolved Hide resolved
// output: true
console.log(_.isInteger('3'))
// output: false

// Native
console.log(Number.isInteger(3))
// output: true
console.log(Number.isInteger('3'))
// output: false
```
#### Browser Support for `Number.isInteger()`

![Chrome][chrome-image] | ![Edge][edge-image] | ![Firefox][firefox-image] | ![IE][ie-image] | ![Opera][opera-image] | ![Safari][safari-image]
:-: | :-: | :-: | :-: | :-: | :-: |
✔ | 12 ✔ | 16.0 ✔ | ✖ | ✔ | ✔ |

**[⬆ back to top](#quick-links)**

### _.isNaN

Checks if a value is NaN.
Expand Down
6 changes: 6 additions & 0 deletions lib/rules/rules.json
Expand Up @@ -148,6 +148,12 @@
"compatible": true,
"alternative": "Number.isFinite()"
},
"isInteger": {
"ruleName": "is-integer",
"compatible": true,
"alternative": "Number.isInteger()",
"ES6": true
},
"isNaN": {
"ruleName": "is-nan",
"compatible": true,
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/rules/all.js
Expand Up @@ -4,7 +4,7 @@ const assert = require('assert');
const rules = require('../../../lib/rules/all');
const allRules = require('../../../lib/rules/rules');

assert.equal(Object.keys(allRules).length, 57, 'Don\'t miss a rule 😄');
assert.equal(Object.keys(allRules).length, 58, 'Don\'t miss a rule 😄');

const ruleTester = new RuleTester({
parserOptions: { ecmaVersion: 2018, sourceType: "module" }
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/all.js
Expand Up @@ -204,6 +204,32 @@ describe('code snippet example', () => {
)
})
})
describe('isInteger', () => {
it('_.isInteger(3)', () => {
assert.equal(
_.isInteger(3),
Number.isInteger(3)
)
})
it('_.isInteger("3")', () => {
assert.equal(
_.isInteger("3"),
Number.isInteger("3")
)
})
it('_.isInteger(2.9)', () => {
assert.equal(
_.isInteger(2.9),
Number.isInteger(2.9)
)
})
it('_.isInteger(NaN)', () => {
assert.equal(
_.isInteger(NaN),
Number.isInteger(NaN)
)
})
})
describe('get', () => {
const get = (obj, path, defaultValue) => {
const result = String.prototype.split.call(path, /[,[\].]+?/)
Expand Down