File tree Expand file tree Collapse file tree 1 file changed +131
-0
lines changed Expand file tree Collapse file tree 1 file changed +131
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * TypeSafe Validator
3
+ * (WIP) Needs Tests
4
+ */
5
+ export default class Type {
6
+ /**
7
+ * Is
8
+ * @param value
9
+ * @return {boolean }
10
+ */
11
+ static isString ( value ) {
12
+ return typeof value === 'string' || value instanceof String
13
+ }
14
+
15
+ /**
16
+ * Is Number
17
+ * @param value
18
+ * @return {boolean }
19
+ */
20
+ static isNumeric ( value ) {
21
+ return this . isFloat ( value ) || this . isInteger ( value )
22
+ }
23
+
24
+ /**
25
+ * Is Float
26
+ * @param value
27
+ * @return {boolean }
28
+ */
29
+ static isFloat ( value ) {
30
+ return value === + value && value !== ( value | 0 ) ;
31
+ }
32
+
33
+ /**
34
+ * Is Integer
35
+ * @param value
36
+ * @return {boolean }
37
+ */
38
+ static isInteger ( value ) {
39
+ return value === + value && value === ( value | 0 ) ;
40
+ }
41
+
42
+ /**
43
+ * Is Array
44
+ * @param value
45
+ * @return {boolean }
46
+ */
47
+ static isArray ( value ) {
48
+ return ( Array . isArray ( value ) )
49
+ }
50
+
51
+ /**
52
+ * Is Function
53
+ * @param value
54
+ * @return {boolean }
55
+ */
56
+ static isFunction ( value ) {
57
+ return typeof value === 'function'
58
+ }
59
+
60
+ /**
61
+ * Is Object
62
+ * @param value
63
+ * @return {*|boolean }
64
+ */
65
+ static isObject ( value ) {
66
+ return value && typeof value === 'object' && value . constructor === Object
67
+ }
68
+
69
+ /**
70
+ * Is Null Object
71
+ * @param value
72
+ * @return {boolean }
73
+ */
74
+ static isNull ( value ) {
75
+ return value === null
76
+ }
77
+
78
+ /**
79
+ * Is Undefined
80
+ * @param value
81
+ * @return {boolean }
82
+ */
83
+ static isUndefined ( value ) {
84
+ return typeof value === 'undefined'
85
+ }
86
+
87
+ /**
88
+ * Is Boolean Primitive
89
+ * @param value
90
+ * @return {boolean }
91
+ */
92
+ static isBoolean ( value ) {
93
+ return typeof value === 'boolean'
94
+ }
95
+
96
+ /**
97
+ * Is RegEx Object
98
+ * @param value
99
+ * @return {*|boolean }
100
+ */
101
+ static isRegExp ( value ) {
102
+ return value && typeof value === 'object' && value . constructor === RegExp
103
+ }
104
+
105
+ /**
106
+ * Is Error Object
107
+ * @param value
108
+ * @return {boolean }
109
+ */
110
+ static isError ( value ) {
111
+ return value instanceof Error && typeof value . message !== 'undefined'
112
+ }
113
+
114
+ /**
115
+ * Is Date Object
116
+ * @param value
117
+ * @return {boolean }
118
+ */
119
+ static isDate ( value ) {
120
+ return value instanceof Date
121
+ }
122
+
123
+ /**
124
+ * Is Symbol
125
+ * @param value
126
+ * @return {boolean }
127
+ */
128
+ static isSymbol ( value ) {
129
+ return typeof value === 'symbol'
130
+ }
131
+ }
You can’t perform that action at this time.
0 commit comments