Skip to content

Commit b73b643

Browse files
committed
Merge branch 'hotfix/55' into develop
2 parents 1ddb47c + 976c3fa commit b73b643

10 files changed

+145
-87
lines changed

dist/utils.js

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
"use strict";
22

33
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;
513

614
var _isPlainObject = _interopRequireDefault(require("lodash/isPlainObject"));
715

@@ -15,37 +23,32 @@ var hasOwn = ObjProto.hasOwnProperty;
1523
exports.hasOwn = hasOwn;
1624
var FN_MATCH_REGEXP = /^\s*function (\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-
4952
var has = function has(obj, prop) {
5053
return hasOwn.call(obj, prop);
5154
};
@@ -60,7 +63,7 @@ var has = function has(obj, prop) {
6063

6164
exports.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

7477
exports.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

100103
exports.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;
279281
var warn = noop;
280282
exports.warn = warn;
281283

282284
if (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;

es/utils.js

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,27 @@ var toString = ObjProto.toString;
55
export var hasOwn = ObjProto.hasOwnProperty;
66
var FN_MATCH_REGEXP = /^\s*function (\w+)/; // https://github.com/vuejs/vue/blob/dev/src/core/util/props.js#L177
77

8-
export var getType = function getType(fn) {
8+
export function getType(fn) {
99
var type = fn !== null && fn !== undefined ? fn.type ? fn.type : fn : null;
1010
var match = type && type.toString().match(FN_MATCH_REGEXP);
1111
return match && match[1];
12-
};
13-
export var getNativeType = function getNativeType(value) {
12+
}
13+
export function getNativeType(value) {
1414
if (value === null || value === undefined) return null;
1515
var match = value.constructor.toString().match(FN_MATCH_REGEXP);
1616
return match && match[1];
17-
};
17+
}
1818
/**
1919
* No-op function
2020
*/
2121

22-
export var noop = function noop() {};
22+
export function noop() {}
2323
/**
2424
* Checks for a own property in an object
2525
*
2626
* @param {object} obj - Object
2727
* @param {string} prop - Property to check
28+
* @returns {boolean}
2829
*/
2930

3031
export var has = function has(obj, prop) {
@@ -38,7 +39,7 @@ export var has = function has(obj, prop) {
3839
* @returns {boolean}
3940
*/
4041

41-
export var isInteger = Number.isInteger || function (value) {
42+
export var isInteger = Number.isInteger || function isInteger(value) {
4243
return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
4344
};
4445
/**
@@ -48,7 +49,7 @@ export var isInteger = Number.isInteger || function (value) {
4849
* @returns {boolean}
4950
*/
5051

51-
export var isArray = Array.isArray || function (value) {
52+
export var isArray = Array.isArray || function isArray(value) {
5253
return toString.call(value) === '[object Array]';
5354
};
5455
/**
@@ -68,7 +69,7 @@ export var isFunction = function isFunction(value) {
6869
* @returns {object} the passed-in prop type
6970
*/
7071

71-
export var withDefault = function withDefault(type) {
72+
export function withDefault(type) {
7273
return Object.defineProperty(type, 'def', {
7374
value: function value(def) {
7475
if (def === undefined && !this.default) {
@@ -97,39 +98,39 @@ export var withDefault = function withDefault(type) {
9798
enumerable: false,
9899
writable: false
99100
});
100-
};
101+
}
101102
/**
102103
* Adds a `isRequired` getter returning a new object with `required: true` key-value
103104
*
104105
* @param {object} type - Object to enhance
105106
* @returns {object} the passed-in prop type
106107
*/
107108

108-
export var withRequired = function withRequired(type) {
109+
export function withRequired(type) {
109110
return Object.defineProperty(type, 'isRequired', {
110111
get: function get() {
111112
this.required = true;
112113
return this;
113114
},
114115
enumerable: false
115116
});
116-
};
117+
}
117118
/**
118119
* Adds a validate method useful to set the prop `validator` function.
119120
*
120121
* @param {object} type Prop type to extend
121122
* @returns {object} the passed-in prop type
122123
*/
123124

124-
export var withValidate = function withValidate(type) {
125+
export function withValidate(type) {
125126
return Object.defineProperty(type, 'validate', {
126127
value: function value(fn) {
127128
this.validator = fn.bind(this);
128129
return this;
129130
},
130131
enumerable: false
131132
});
132-
};
133+
}
133134
/**
134135
* Adds `isRequired` and `def` modifiers to an object
135136
*
@@ -138,7 +139,7 @@ export var withValidate = function withValidate(type) {
138139
* @returns {object}
139140
*/
140141

141-
export var toType = function toType(name, obj, validateFn) {
142+
export function toType(name, obj, validateFn) {
142143
if (validateFn === void 0) {
143144
validateFn = false;
144145
}
@@ -159,7 +160,7 @@ export var toType = function toType(name, obj, validateFn) {
159160
}
160161

161162
return obj;
162-
};
163+
}
163164
/**
164165
* Validates a given value against a prop type object
165166
*
@@ -169,7 +170,7 @@ export var toType = function toType(name, obj, validateFn) {
169170
* @returns {boolean}
170171
*/
171172

172-
export var validateType = function validateType(type, value, silent) {
173+
export function validateType(type, value, silent) {
173174
if (silent === void 0) {
174175
silent = false;
175176
}
@@ -187,6 +188,14 @@ export var validateType = function validateType(type, value, silent) {
187188
var namePrefix = typeToCheck._vueTypes_name ? typeToCheck._vueTypes_name + ' - ' : '';
188189

189190
if (hasOwn.call(typeToCheck, 'type') && typeToCheck.type !== null) {
191+
if (typeToCheck.type === undefined) {
192+
throw new TypeError("[VueTypes error]: Setting type to undefined is not allowed.");
193+
}
194+
195+
if (!typeToCheck.required && value === undefined) {
196+
return valid;
197+
}
198+
190199
if (isArray(typeToCheck.type)) {
191200
valid = typeToCheck.type.some(function (type) {
192201
return validateType(type, value, true);
@@ -230,12 +239,12 @@ export var validateType = function validateType(type, value, silent) {
230239
}
231240

232241
return valid;
233-
};
242+
}
234243
var warn = noop;
235244

236245
if (process.env.NODE_ENV !== 'production') {
237246
var hasConsole = typeof console !== 'undefined';
238-
warn = hasConsole ? function (msg) {
247+
warn = hasConsole ? function warn(msg) {
239248
// eslint-disable-next-line no-console
240249
Vue.config.silent === false && console.warn("[VueTypes warn]: " + msg);
241250
} : noop;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-types",
3-
"version": "1.5.6",
3+
"version": "1.5.7",
44
"description": "Prop types utility for Vue",
55
"author": "Marco Solazzi",
66
"license": "MIT",

0 commit comments

Comments
 (0)