forked from tjmehta/is-positive-integer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
22 lines (19 loc) · 657 Bytes
/
index.js
File metadata and controls
22 lines (19 loc) · 657 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/* $lab:coverage:off$ */
var MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER || -9007199254740991
/* $lab:coverage:on$ */
module.exports = isNegativeInteger
module.exports.isSafeNegativeInteger = isSafeNegativeInteger
function isNegativeInteger (x) {
// Is it a number?
return Object.prototype.toString.call(x) === '[object Number]' &&
// Is it an integer?
x % 1 === 0 &&
// Is it negative?
x < 0
}
// strict negative integer check:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER
function isSafeNegativeInteger (x) {
return isNegativeInteger(x) &&
x >= MIN_SAFE_INTEGER
}