@mightyplow/jslib
Version:
js helpers library
30 lines (25 loc) • 1.08 kB
JavaScript
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var checkType = function checkType(type) {
return function (value) {
// console.log(type, value);
if (type === null) {
return value === null;
} else if (typeof type === 'string') {
return (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === type;
} else if (typeof type === 'function') {
return value instanceof type;
} else if ((typeof type === 'undefined' ? 'undefined' : _typeof(type)) === 'object') {
return type.isPrototypeOf(value);
}
return false;
};
};
/**
* @memberOf function
*/
var checkTypes = function checkTypes(values, types) {
return values.every(function (value, index) {
return checkType(types[index])(value);
});
};
export default checkTypes;