[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var test = require('tape');
|
---|
| 4 | var isNumber = require('../');
|
---|
| 5 | var hasToStringTag = require('has-tostringtag/shams')();
|
---|
| 6 |
|
---|
| 7 | test('not Numbers', function (t) {
|
---|
[79a0317] | 8 | // @ts-expect-error
|
---|
[d565449] | 9 | t.notOk(isNumber(), 'undefined is not Number');
|
---|
| 10 | t.notOk(isNumber(null), 'null is not Number');
|
---|
| 11 | t.notOk(isNumber(false), 'false is not Number');
|
---|
| 12 | t.notOk(isNumber(true), 'true is not Number');
|
---|
| 13 | t.notOk(isNumber('foo'), 'string is not Number');
|
---|
| 14 | t.notOk(isNumber([]), 'array is not Number');
|
---|
| 15 | t.notOk(isNumber({}), 'object is not Number');
|
---|
| 16 | t.notOk(isNumber(function () {}), 'function is not Number');
|
---|
| 17 | t.notOk(isNumber(/a/g), 'regex literal is not Number');
|
---|
| 18 | t.notOk(isNumber(new RegExp('a', 'g')), 'regex object is not Number');
|
---|
| 19 | t.notOk(isNumber(new Date()), 'new Date() is not Number');
|
---|
| 20 | t.end();
|
---|
| 21 | });
|
---|
| 22 |
|
---|
| 23 | test('@@toStringTag', { skip: !hasToStringTag }, function (t) {
|
---|
[79a0317] | 24 | /** @type {{ toString(): string; valueOf(): number; [Symbol.toStringTag]?: string; }} */
|
---|
[d565449] | 25 | var fakeNumber = {
|
---|
| 26 | toString: function () { return '7'; },
|
---|
| 27 | valueOf: function () { return 42; }
|
---|
| 28 | };
|
---|
| 29 | fakeNumber[Symbol.toStringTag] = 'Number';
|
---|
| 30 | t.notOk(isNumber(fakeNumber), 'fake Number with @@toStringTag "Number" is not Number');
|
---|
| 31 | t.end();
|
---|
| 32 | });
|
---|
| 33 |
|
---|
| 34 | test('Numbers', function (t) {
|
---|
| 35 | t.ok(isNumber(42), 'number is Number');
|
---|
| 36 | t.ok(isNumber(Object(42)), 'number object is Number');
|
---|
| 37 | t.ok(isNumber(NaN), 'NaN is Number');
|
---|
| 38 | t.ok(isNumber(Infinity), 'Infinity is Number');
|
---|
| 39 | t.end();
|
---|
| 40 | });
|
---|