The lodash method isInteger exported as a module for checking if a value is an integer
npx @tessl/cli install tessl/npm-lodash--isinteger@4.0.00
# lodash.isinteger
1
2
lodash.isinteger is a modularized version of lodash's isInteger utility function that checks if a given value is an integer. It performs type checking to ensure the input is a number and validates that it equals its integer conversion, effectively filtering out decimals, strings, and other non-integer data types.
3
4
## Package Information
5
6
- **Package Name**: lodash.isinteger
7
- **Package Type**: npm
8
- **Language**: JavaScript
9
- **Installation**: `npm install lodash.isinteger`
10
11
## Core Imports
12
13
```javascript
14
var isInteger = require('lodash.isinteger');
15
```
16
17
For ES6 modules (with transpiler):
18
19
```javascript
20
import isInteger from 'lodash.isinteger';
21
```
22
23
## Basic Usage
24
25
```javascript
26
var isInteger = require('lodash.isinteger');
27
28
// Check various values
29
console.log(isInteger(3)); // => true
30
console.log(isInteger(3.0)); // => true
31
console.log(isInteger(3.2)); // => false
32
console.log(isInteger(Number.MIN_VALUE)); // => false
33
console.log(isInteger(Infinity)); // => false
34
console.log(isInteger('3')); // => false
35
console.log(isInteger(null)); // => false
36
console.log(isInteger(undefined)); // => false
37
```
38
39
## Capabilities
40
41
### Integer Validation
42
43
Checks if a value is an integer by validating it's a number type and equals its integer conversion.
44
45
```javascript { .api }
46
/**
47
* Checks if `value` is an integer.
48
*
49
* Note: This method is based on Number.isInteger.
50
*
51
* @param {any} value The value to check.
52
* @returns {boolean} Returns `true` if `value` is an integer, else `false`.
53
*/
54
function isInteger(value);
55
```
56
57
**Parameter Details:**
58
- `value` (any): The value to check - can be any type
59
60
**Return Value:**
61
- `boolean`: Returns `true` if value is an integer, `false` otherwise
62
63
**Behavior:**
64
- Returns `true` for whole numbers (positive, negative, or zero)
65
- Returns `false` for decimal numbers, strings, objects, null, undefined
66
- Returns `false` for special number values like `Infinity`, `-Infinity`, and `NaN`
67
- Handles edge cases like `Number.MIN_VALUE` correctly (returns `false`)
68
69
**Examples:**
70
71
```javascript
72
// Integer values
73
isInteger(0); // => true
74
isInteger(-1); // => true
75
isInteger(42); // => true
76
isInteger(3.0); // => true (mathematically an integer)
77
78
// Non-integer values
79
isInteger(3.14); // => false (decimal)
80
isInteger('3'); // => false (string)
81
isInteger([]); // => false (array)
82
isInteger({}); // => false (object)
83
isInteger(null); // => false
84
isInteger(undefined); // => false
85
86
// Special number values
87
isInteger(Infinity); // => false
88
isInteger(-Infinity); // => false
89
isInteger(NaN); // => false
90
isInteger(Number.MIN_VALUE); // => false (very small decimal)
91
```