1
1
"use strict" ;
2
2
3
3
exports . __esModule = true ;
4
- exports . warn = exports . validateType = exports . toType = exports . withValidate = exports . withRequired = exports . withDefault = exports . isFunction = exports . isArray = exports . isInteger = exports . has = exports . noop = exports . getNativeType = exports . getType = exports . hasOwn = void 0 ;
4
+ exports . getType = getType ;
5
+ exports . getNativeType = getNativeType ;
6
+ exports . noop = noop ;
7
+ exports . withDefault = withDefault ;
8
+ exports . withRequired = withRequired ;
9
+ exports . withValidate = withValidate ;
10
+ exports . toType = toType ;
11
+ exports . validateType = validateType ;
12
+ exports . warn = exports . isFunction = exports . isArray = exports . isInteger = exports . has = exports . hasOwn = void 0 ;
5
13
6
14
var _isPlainObject = _interopRequireDefault ( require ( "lodash/isPlainObject" ) ) ;
7
15
@@ -15,37 +23,32 @@ var hasOwn = ObjProto.hasOwnProperty;
15
23
exports . hasOwn = hasOwn ;
16
24
var FN_MATCH_REGEXP = / ^ \s * f u n c t i o n ( \w + ) / ; // https://github.com/vuejs/vue/blob/dev/src/core/util/props.js#L177
17
25
18
- var getType = function getType ( fn ) {
26
+ function getType ( fn ) {
19
27
var type = fn !== null && fn !== undefined ? fn . type ? fn . type : fn : null ;
20
28
var match = type && type . toString ( ) . match ( FN_MATCH_REGEXP ) ;
21
29
return match && match [ 1 ] ;
22
- } ;
30
+ }
23
31
24
- exports . getType = getType ;
25
-
26
- var getNativeType = function getNativeType ( value ) {
32
+ function getNativeType ( value ) {
27
33
if ( value === null || value === undefined ) return null ;
28
34
var match = value . constructor . toString ( ) . match ( FN_MATCH_REGEXP ) ;
29
35
return match && match [ 1 ] ;
30
- } ;
36
+ }
31
37
/**
32
38
* No-op function
33
39
*/
34
40
35
41
36
- exports . getNativeType = getNativeType ;
37
-
38
- var noop = function noop ( ) { } ;
42
+ function noop ( ) { }
39
43
/**
40
44
* Checks for a own property in an object
41
45
*
42
46
* @param {object } obj - Object
43
47
* @param {string } prop - Property to check
48
+ * @returns {boolean }
44
49
*/
45
50
46
51
47
- exports . noop = noop ;
48
-
49
52
var has = function has ( obj , prop ) {
50
53
return hasOwn . call ( obj , prop ) ;
51
54
} ;
@@ -60,7 +63,7 @@ var has = function has(obj, prop) {
60
63
61
64
exports . has = has ;
62
65
63
- var isInteger = Number . isInteger || function ( value ) {
66
+ var isInteger = Number . isInteger || function isInteger ( value ) {
64
67
return typeof value === 'number' && isFinite ( value ) && Math . floor ( value ) === value ;
65
68
} ;
66
69
/**
@@ -73,7 +76,7 @@ var isInteger = Number.isInteger || function (value) {
73
76
74
77
exports . isInteger = isInteger ;
75
78
76
- var isArray = Array . isArray || function ( value ) {
79
+ var isArray = Array . isArray || function isArray ( value ) {
77
80
return toString . call ( value ) === '[object Array]' ;
78
81
} ;
79
82
/**
@@ -99,7 +102,7 @@ var isFunction = function isFunction(value) {
99
102
100
103
exports . isFunction = isFunction ;
101
104
102
- var withDefault = function withDefault ( type ) {
105
+ function withDefault ( type ) {
103
106
return Object . defineProperty ( type , 'def' , {
104
107
value : function value ( def ) {
105
108
if ( def === undefined && ! this . default ) {
@@ -128,7 +131,7 @@ var withDefault = function withDefault(type) {
128
131
enumerable : false ,
129
132
writable : false
130
133
} ) ;
131
- } ;
134
+ }
132
135
/**
133
136
* Adds a `isRequired` getter returning a new object with `required: true` key-value
134
137
*
@@ -137,17 +140,15 @@ var withDefault = function withDefault(type) {
137
140
*/
138
141
139
142
140
- exports . withDefault = withDefault ;
141
-
142
- var withRequired = function withRequired ( type ) {
143
+ function withRequired ( type ) {
143
144
return Object . defineProperty ( type , 'isRequired' , {
144
145
get : function get ( ) {
145
146
this . required = true ;
146
147
return this ;
147
148
} ,
148
149
enumerable : false
149
150
} ) ;
150
- } ;
151
+ }
151
152
/**
152
153
* Adds a validate method useful to set the prop `validator` function.
153
154
*
@@ -156,17 +157,15 @@ var withRequired = function withRequired(type) {
156
157
*/
157
158
158
159
159
- exports . withRequired = withRequired ;
160
-
161
- var withValidate = function withValidate ( type ) {
160
+ function withValidate ( type ) {
162
161
return Object . defineProperty ( type , 'validate' , {
163
162
value : function value ( fn ) {
164
163
this . validator = fn . bind ( this ) ;
165
164
return this ;
166
165
} ,
167
166
enumerable : false
168
167
} ) ;
169
- } ;
168
+ }
170
169
/**
171
170
* Adds `isRequired` and `def` modifiers to an object
172
171
*
@@ -176,9 +175,7 @@ var withValidate = function withValidate(type) {
176
175
*/
177
176
178
177
179
- exports . withValidate = withValidate ;
180
-
181
- var toType = function toType ( name , obj , validateFn ) {
178
+ function toType ( name , obj , validateFn ) {
182
179
if ( validateFn === void 0 ) {
183
180
validateFn = false ;
184
181
}
@@ -199,7 +196,7 @@ var toType = function toType(name, obj, validateFn) {
199
196
}
200
197
201
198
return obj ;
202
- } ;
199
+ }
203
200
/**
204
201
* Validates a given value against a prop type object
205
202
*
@@ -210,9 +207,7 @@ var toType = function toType(name, obj, validateFn) {
210
207
*/
211
208
212
209
213
- exports . toType = toType ;
214
-
215
- var validateType = function validateType ( type , value , silent ) {
210
+ function validateType ( type , value , silent ) {
216
211
if ( silent === void 0 ) {
217
212
silent = false ;
218
213
}
@@ -230,6 +225,14 @@ var validateType = function validateType(type, value, silent) {
230
225
var namePrefix = typeToCheck . _vueTypes_name ? typeToCheck . _vueTypes_name + ' - ' : '' ;
231
226
232
227
if ( hasOwn . call ( typeToCheck , 'type' ) && typeToCheck . type !== null ) {
228
+ if ( typeToCheck . type === undefined ) {
229
+ throw new TypeError ( "[VueTypes error]: Setting type to undefined is not allowed." ) ;
230
+ }
231
+
232
+ if ( ! typeToCheck . required && value === undefined ) {
233
+ return valid ;
234
+ }
235
+
233
236
if ( isArray ( typeToCheck . type ) ) {
234
237
valid = typeToCheck . type . some ( function ( type ) {
235
238
return validateType ( type , value , true ) ;
@@ -273,15 +276,14 @@ var validateType = function validateType(type, value, silent) {
273
276
}
274
277
275
278
return valid ;
276
- } ;
279
+ }
277
280
278
- exports . validateType = validateType ;
279
281
var warn = noop ;
280
282
exports . warn = warn ;
281
283
282
284
if ( process . env . NODE_ENV !== 'production' ) {
283
285
var hasConsole = typeof console !== 'undefined' ;
284
- exports . warn = warn = hasConsole ? function ( msg ) {
286
+ exports . warn = warn = hasConsole ? function warn ( msg ) {
285
287
// eslint-disable-next-line no-console
286
288
_vue . default . config . silent === false && console . warn ( "[VueTypes warn]: " + msg ) ;
287
289
} : noop ;
0 commit comments