11"use strict" ;
22
33exports . __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 ;
513
614var _isPlainObject = _interopRequireDefault ( require ( "lodash/isPlainObject" ) ) ;
715
@@ -15,37 +23,32 @@ var hasOwn = ObjProto.hasOwnProperty;
1523exports . hasOwn = hasOwn ;
1624var 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
1725
18- var getType = function getType ( fn ) {
26+ function getType ( fn ) {
1927 var type = fn !== null && fn !== undefined ? fn . type ? fn . type : fn : null ;
2028 var match = type && type . toString ( ) . match ( FN_MATCH_REGEXP ) ;
2129 return match && match [ 1 ] ;
22- } ;
30+ }
2331
24- exports . getType = getType ;
25-
26- var getNativeType = function getNativeType ( value ) {
32+ function getNativeType ( value ) {
2733 if ( value === null || value === undefined ) return null ;
2834 var match = value . constructor . toString ( ) . match ( FN_MATCH_REGEXP ) ;
2935 return match && match [ 1 ] ;
30- } ;
36+ }
3137/**
3238 * No-op function
3339 */
3440
3541
36- exports . getNativeType = getNativeType ;
37-
38- var noop = function noop ( ) { } ;
42+ function noop ( ) { }
3943/**
4044 * Checks for a own property in an object
4145 *
4246 * @param {object } obj - Object
4347 * @param {string } prop - Property to check
48+ * @returns {boolean }
4449 */
4550
4651
47- exports . noop = noop ;
48-
4952var has = function has ( obj , prop ) {
5053 return hasOwn . call ( obj , prop ) ;
5154} ;
@@ -60,7 +63,7 @@ var has = function has(obj, prop) {
6063
6164exports . has = has ;
6265
63- var isInteger = Number . isInteger || function ( value ) {
66+ var isInteger = Number . isInteger || function isInteger ( value ) {
6467 return typeof value === 'number' && isFinite ( value ) && Math . floor ( value ) === value ;
6568} ;
6669/**
@@ -73,7 +76,7 @@ var isInteger = Number.isInteger || function (value) {
7376
7477exports . isInteger = isInteger ;
7578
76- var isArray = Array . isArray || function ( value ) {
79+ var isArray = Array . isArray || function isArray ( value ) {
7780 return toString . call ( value ) === '[object Array]' ;
7881} ;
7982/**
@@ -99,7 +102,7 @@ var isFunction = function isFunction(value) {
99102
100103exports . isFunction = isFunction ;
101104
102- var withDefault = function withDefault ( type ) {
105+ function withDefault ( type ) {
103106 return Object . defineProperty ( type , 'def' , {
104107 value : function value ( def ) {
105108 if ( def === undefined && ! this . default ) {
@@ -128,7 +131,7 @@ var withDefault = function withDefault(type) {
128131 enumerable : false ,
129132 writable : false
130133 } ) ;
131- } ;
134+ }
132135/**
133136 * Adds a `isRequired` getter returning a new object with `required: true` key-value
134137 *
@@ -137,17 +140,15 @@ var withDefault = function withDefault(type) {
137140 */
138141
139142
140- exports . withDefault = withDefault ;
141-
142- var withRequired = function withRequired ( type ) {
143+ function withRequired ( type ) {
143144 return Object . defineProperty ( type , 'isRequired' , {
144145 get : function get ( ) {
145146 this . required = true ;
146147 return this ;
147148 } ,
148149 enumerable : false
149150 } ) ;
150- } ;
151+ }
151152/**
152153 * Adds a validate method useful to set the prop `validator` function.
153154 *
@@ -156,17 +157,15 @@ var withRequired = function withRequired(type) {
156157 */
157158
158159
159- exports . withRequired = withRequired ;
160-
161- var withValidate = function withValidate ( type ) {
160+ function withValidate ( type ) {
162161 return Object . defineProperty ( type , 'validate' , {
163162 value : function value ( fn ) {
164163 this . validator = fn . bind ( this ) ;
165164 return this ;
166165 } ,
167166 enumerable : false
168167 } ) ;
169- } ;
168+ }
170169/**
171170 * Adds `isRequired` and `def` modifiers to an object
172171 *
@@ -176,9 +175,7 @@ var withValidate = function withValidate(type) {
176175 */
177176
178177
179- exports . withValidate = withValidate ;
180-
181- var toType = function toType ( name , obj , validateFn ) {
178+ function toType ( name , obj , validateFn ) {
182179 if ( validateFn === void 0 ) {
183180 validateFn = false ;
184181 }
@@ -199,7 +196,7 @@ var toType = function toType(name, obj, validateFn) {
199196 }
200197
201198 return obj ;
202- } ;
199+ }
203200/**
204201 * Validates a given value against a prop type object
205202 *
@@ -210,9 +207,7 @@ var toType = function toType(name, obj, validateFn) {
210207 */
211208
212209
213- exports . toType = toType ;
214-
215- var validateType = function validateType ( type , value , silent ) {
210+ function validateType ( type , value , silent ) {
216211 if ( silent === void 0 ) {
217212 silent = false ;
218213 }
@@ -230,6 +225,14 @@ var validateType = function validateType(type, value, silent) {
230225 var namePrefix = typeToCheck . _vueTypes_name ? typeToCheck . _vueTypes_name + ' - ' : '' ;
231226
232227 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+
233236 if ( isArray ( typeToCheck . type ) ) {
234237 valid = typeToCheck . type . some ( function ( type ) {
235238 return validateType ( type , value , true ) ;
@@ -273,15 +276,14 @@ var validateType = function validateType(type, value, silent) {
273276 }
274277
275278 return valid ;
276- } ;
279+ }
277280
278- exports . validateType = validateType ;
279281var warn = noop ;
280282exports . warn = warn ;
281283
282284if ( process . env . NODE_ENV !== 'production' ) {
283285 var hasConsole = typeof console !== 'undefined' ;
284- exports . warn = warn = hasConsole ? function ( msg ) {
286+ exports . warn = warn = hasConsole ? function warn ( msg ) {
285287 // eslint-disable-next-line no-console
286288 _vue . default . config . silent === false && console . warn ( "[VueTypes warn]: " + msg ) ;
287289 } : noop ;
0 commit comments