-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisInteger.js
More file actions
35 lines (33 loc) · 994 Bytes
/
isInteger.js
File metadata and controls
35 lines (33 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import isNumber from './isNumber'
/**
* 检测测试数据是否为整数
* ========================================================================
* @method isInteger
* @since 0.2.0
* @category Number
* @param {*} val - 要检测的数据
* @returns {Boolean} 'val' 是整数,返回 true,否则返回 false
* @example
*
* // False
* isInteger(2.4) // -> false
* isInteger(3.4234E3) // -> false
* isInteger('1') // -> false
* isInteger(Number('3.4556645445E7')) // -> false
* isInteger(NaN) // -> false
* isInteger(Infinity) // -> false
* isInteger(-Infinity) // -> false
*
* // True
* isInteger(2) // -> true
* isInteger(2.0) // -> true
* isInteger(3.4234E4) // -> true
* isInteger(0xffffff) // -> true
* isInteger(Number('1')) // -> true
* isInteger(parseInt('1.0', 10)) // -> true
* isInteger(Math.ceil(2.6)) // -> true
*/
const isInteger = (val) => {
return isNumber(val) && !isNaN(val) && Number(val) === val && val % 1 === 0
}
export default isInteger