Add is.infinite()
This commit is contained in:
parent
11b98171c8
commit
24c964a7c7
3 changed files with 16 additions and 2 deletions
2
index.js
2
index.js
|
|
@ -161,4 +161,6 @@ is.inRange = (x, range) => {
|
|||
throw new TypeError(`Invalid range: ${util.inspect(range)}`);
|
||||
};
|
||||
|
||||
is.infinite = x => x === Infinity || x === -Infinity;
|
||||
|
||||
module.exports = is;
|
||||
|
|
|
|||
|
|
@ -145,6 +145,10 @@ Check if `value` (number) is in the range of `0` to `upperBound`.
|
|||
is.inRange(3, 10);
|
||||
```
|
||||
|
||||
##### .infinite(value)
|
||||
|
||||
Check if `value` is `Infinity` or `-Infinity`.
|
||||
|
||||
|
||||
## FAQ
|
||||
|
||||
|
|
|
|||
12
test.js
12
test.js
|
|
@ -89,7 +89,11 @@ const types = new Map([
|
|||
Object.create(null),
|
||||
new Object() // eslint-disable-line no-new-object
|
||||
]],
|
||||
['integer', 6]
|
||||
['integer', 6],
|
||||
['infinite', [
|
||||
Infinity,
|
||||
-Infinity
|
||||
]]
|
||||
]);
|
||||
|
||||
// This ensures a certain method matches only the types
|
||||
|
|
@ -132,7 +136,7 @@ test('is.string', t => {
|
|||
});
|
||||
|
||||
test('is.number', t => {
|
||||
testType(t, 'number', ['nan', 'integer']);
|
||||
testType(t, 'number', ['nan', 'integer', 'infinite']);
|
||||
});
|
||||
|
||||
test('is.boolean', t => {
|
||||
|
|
@ -365,3 +369,7 @@ test('is.inRange', t => {
|
|||
m.inRange(0, [1, 2, 3]);
|
||||
});
|
||||
});
|
||||
|
||||
test('is.infinite', t => {
|
||||
testType(t, 'infinite', ['number']);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue