Add is.even() and is.odd() (#23)
This commit is contained in:
parent
00974a2fe9
commit
615932d6c2
3 changed files with 32 additions and 0 deletions
4
index.js
4
index.js
|
|
@ -179,6 +179,10 @@ is.domElement = x => is.object(x) && x.nodeType === NODE_TYPE_ELEMENT && is.stri
|
|||
|
||||
is.infinite = x => x === Infinity || x === -Infinity;
|
||||
|
||||
const isAbsoluteMod2 = value => x => is.integer(x) && Math.abs(x % 2) === value;
|
||||
is.even = isAbsoluteMod2(0);
|
||||
is.odd = isAbsoluteMod2(1);
|
||||
|
||||
const isEmptyStringOrArray = x => (is.string(x) || is.array(x)) && x.length === 0;
|
||||
const isEmptyObject = x => !is.map(x) && !is.set(x) && is.object(x) && Object.keys(x).length === 0;
|
||||
const isEmptyMapOrSet = x => (is.map(x) || is.set(x)) && x.size === 0;
|
||||
|
|
|
|||
|
|
@ -170,6 +170,14 @@ Returns `true` if `value` is a DOM Element.
|
|||
|
||||
Check if `value` is `Infinity` or `-Infinity`.
|
||||
|
||||
##### .even(value)
|
||||
|
||||
Returns `true` if `value` is an even integer.
|
||||
|
||||
##### .odd(value)
|
||||
|
||||
Returns `true` if `value` is an odd integer.
|
||||
|
||||
##### .empty(value)
|
||||
|
||||
Returns `true` if `value` is falsy or an empty string, array, object, map, or set.
|
||||
|
|
|
|||
20
test.js
20
test.js
|
|
@ -419,6 +419,26 @@ test('is.infinite', t => {
|
|||
testType(t, 'infinite', ['number']);
|
||||
});
|
||||
|
||||
test('is.even', t => {
|
||||
for (const el of [-6, 2, 4]) {
|
||||
t.true(m.even(el));
|
||||
}
|
||||
|
||||
for (const el of [-3, 1, 5]) {
|
||||
t.false(m.even(el));
|
||||
}
|
||||
});
|
||||
|
||||
test('is.odd', t => {
|
||||
for (const el of [-5, 7, 13]) {
|
||||
t.true(m.odd(el));
|
||||
}
|
||||
|
||||
for (const el of [-8, 8, 10]) {
|
||||
t.false(m.odd(el));
|
||||
}
|
||||
});
|
||||
|
||||
test('is.empty', t => {
|
||||
t.true(m.empty(null));
|
||||
t.true(m.empty(undefined));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue