diff --git a/index.js b/index.js index 4c3943d..47b95f7 100644 --- a/index.js +++ b/index.js @@ -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; diff --git a/package.json b/package.json index b19c355..8ef725c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/readme.md b/readme.md index 9662489..cfa849d 100644 --- a/readme.md +++ b/readme.md @@ -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 diff --git a/test.js b/test.js index 3be5de6..abadfa3 100644 --- a/test.js +++ b/test.js @@ -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']); +});