Merge branch 'master' into master_add_domElement

This commit is contained in:
Melvin Philips 2017-10-05 14:02:00 -07:00
commit b22d9e88db
4 changed files with 24 additions and 4 deletions

View file

@ -7,7 +7,7 @@ const isOfType = type => x => typeof x === type; // eslint-disable-line valid-ty
const isObjectOfType = type => x => getObjectType(x) === type;
const is = value => {
if (value == null) { // eslint-disable-line no-eq-null, eqeqeq
if (value === null) {
return 'null';
}
@ -61,7 +61,7 @@ is.undefined = isOfType('undefined');
is.null = x => x === null;
is.string = isOfType('string');
is.number = isOfType('number');
is.boolean = isOfType('boolean');
is.boolean = x => x === true || x === false;
is.symbol = isOfType('symbol');
is.array = Array.isArray;
@ -168,4 +168,6 @@ is.domElement = x => {
!is.plainObject(x) && propsToCheck.every(prop => prop in x);
};
is.infinite = x => x === Infinity || x === -Infinity;
module.exports = is;

View file

@ -1,6 +1,6 @@
{
"name": "@sindresorhus/is",
"version": "0.2.0",
"version": "0.2.1",
"description": "Type check values: `is.string('🦄') //=> true`",
"license": "MIT",
"repository": "sindresorhus/is",

View file

@ -149,6 +149,9 @@ is.inRange(3, 10);
Returns `true` if `value` is a DOM Element.
##### .infinite(value)
Check if `value` is `Infinity` or `-Infinity`.
## FAQ

17
test.js
View file

@ -106,6 +106,10 @@ const types = new Map([
document,
document.implementation.createDocumentType('svg:svg', '-//W3C//DTD SVG 1.1//EN', 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'),
document.createDocumentFragment()
]],
['infinite', [
Infinity,
-Infinity
]]
]);
@ -129,6 +133,13 @@ const testType = (t, type, exclude) => {
}
};
test('is', t => {
t.is(m(null), 'null');
t.is(m(undefined), 'undefined');
// TODO: Expand this to all the supported types. Maybe reuse `testType()` somehow.
});
test('is.undefined', t => {
testType(t, 'undefined', ['nullOrUndefined']);
});
@ -142,7 +153,7 @@ test('is.string', t => {
});
test('is.number', t => {
testType(t, 'number', ['nan', 'integer']);
testType(t, 'number', ['nan', 'integer', 'infinite']);
});
test('is.boolean', t => {
@ -380,3 +391,7 @@ test('is.domElement', t => {
testType(t, 'domElement');
t.false(m.domElement({nodeType: 1, nodeName: 'div'}));
});
test('is.infinite', t => {
testType(t, 'infinite', ['number']);
});