-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathis_numeric.js
More file actions
91 lines (80 loc) · 2.83 KB
/
is_numeric.js
File metadata and controls
91 lines (80 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { PRINTABLE_ASCII } from '../const';
import v from '../voca';
describe('isNumeric', function() {
it('should return true for a number', function() {
expect(v.isNumeric(0)).toBe(true);
expect(v.isNumeric(+0)).toBe(true);
expect(v.isNumeric(1000)).toBe(true);
expect(v.isNumeric(-1000)).toBe(true);
expect(v.isNumeric(0xff)).toBe(true);
expect(v.isNumeric(1.56)).toBe(true);
expect(v.isNumeric(-10.888)).toBe(true);
expect(v.isNumeric(125e5)).toBe(true);
expect(v.isNumeric(125e-3)).toBe(true);
});
it('should return true for a numeric string', function() {
expect(v.isNumeric('0')).toBe(true);
expect(v.isNumeric('+0')).toBe(true);
expect(v.isNumeric('0.0')).toBe(true);
expect(v.isNumeric('1000')).toBe(true);
expect(v.isNumeric('-1000')).toBe(true);
expect(v.isNumeric('0xFF')).toBe(true);
expect(v.isNumeric('1.56')).toBe(true);
expect(v.isNumeric('-10.888')).toBe(true);
expect(v.isNumeric('125e5')).toBe(true);
expect(v.isNumeric('125e-3')).toBe(true);
});
it('should return true for a numeric string representation of an object', function() {
expect(v.isNumeric([0])).toBe(true);
expect(v.isNumeric(['0'])).toBe(true);
expect(v.isNumeric(['0.0'])).toBe(true);
expect(
v.isNumeric({
toString: function() {
return '100';
},
})
).toBe(true);
});
it('should return false for a non numeric string', function() {
expect(v.isNumeric('FF')).toBe(false);
expect(v.isNumeric('0FF')).toBe(false);
expect(v.isNumeric('Hello World!')).toBe(false);
expect(v.isNumeric('!0')).toBe(false);
expect(v.isNumeric('1.0 0')).toBe(false);
expect(v.isNumeric('Infinity')).toBe(false);
expect(v.isNumeric('NaN')).toBe(false);
expect(v.isNumeric(' ')).toBe(false);
expect(v.isNumeric(PRINTABLE_ASCII)).toBe(false);
});
it('should return false for a non numeric string representation of an object', function() {
expect(v.isNumeric(['Hello World!'])).toBe(false);
expect(
v.isNumeric({
toString: function() {
return 'NaN';
},
})
).toBe(false);
});
it('should return false for a boolean', function() {
expect(v.isNumeric(true)).toBe(false);
expect(v.isNumeric(false)).toBe(false);
});
it('should return false for an undefined', function() {
expect(v.isNumeric(undefined)).toBe(false);
expect(v.isNumeric()).toBe(false);
});
it('should return false for a null', function() {
expect(v.isNumeric(null)).toBe(false);
});
it('should return false for an Inifinty', function() {
expect(v.isNumeric(null)).toBe(false);
});
it('should return false for a NaN', function() {
expect(v.isNumeric(null)).toBe(false);
});
it('should return false for an empty string', function() {
expect(v.isNumeric('')).toBe(false);
});
});