Comparing version 1.5.6 to 1.5.7
"use strict"; | ||
exports.__esModule = true; | ||
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; | ||
exports.getType = getType; | ||
exports.getNativeType = getNativeType; | ||
exports.noop = noop; | ||
exports.withDefault = withDefault; | ||
exports.withRequired = withRequired; | ||
exports.withValidate = withValidate; | ||
exports.toType = toType; | ||
exports.validateType = validateType; | ||
exports.warn = exports.isFunction = exports.isArray = exports.isInteger = exports.has = exports.hasOwn = void 0; | ||
@@ -18,15 +26,13 @@ var _isPlainObject = _interopRequireDefault(require("lodash/isPlainObject")); | ||
var getType = function getType(fn) { | ||
function getType(fn) { | ||
var type = fn !== null && fn !== undefined ? fn.type ? fn.type : fn : null; | ||
var match = type && type.toString().match(FN_MATCH_REGEXP); | ||
return match && match[1]; | ||
}; | ||
} | ||
exports.getType = getType; | ||
var getNativeType = function getNativeType(value) { | ||
function getNativeType(value) { | ||
if (value === null || value === undefined) return null; | ||
var match = value.constructor.toString().match(FN_MATCH_REGEXP); | ||
return match && match[1]; | ||
}; | ||
} | ||
/** | ||
@@ -37,5 +43,3 @@ * No-op function | ||
exports.getNativeType = getNativeType; | ||
var noop = function noop() {}; | ||
function noop() {} | ||
/** | ||
@@ -46,7 +50,6 @@ * Checks for a own property in an object | ||
* @param {string} prop - Property to check | ||
* @returns {boolean} | ||
*/ | ||
exports.noop = noop; | ||
var has = function has(obj, prop) { | ||
@@ -66,3 +69,3 @@ return hasOwn.call(obj, prop); | ||
var isInteger = Number.isInteger || function (value) { | ||
var isInteger = Number.isInteger || function isInteger(value) { | ||
return typeof value === 'number' && isFinite(value) && Math.floor(value) === value; | ||
@@ -80,3 +83,3 @@ }; | ||
var isArray = Array.isArray || function (value) { | ||
var isArray = Array.isArray || function isArray(value) { | ||
return toString.call(value) === '[object Array]'; | ||
@@ -107,3 +110,3 @@ }; | ||
var withDefault = function withDefault(type) { | ||
function withDefault(type) { | ||
return Object.defineProperty(type, 'def', { | ||
@@ -137,3 +140,3 @@ value: function value(def) { | ||
}); | ||
}; | ||
} | ||
/** | ||
@@ -147,5 +150,3 @@ * Adds a `isRequired` getter returning a new object with `required: true` key-value | ||
exports.withDefault = withDefault; | ||
var withRequired = function withRequired(type) { | ||
function withRequired(type) { | ||
return Object.defineProperty(type, 'isRequired', { | ||
@@ -158,3 +159,3 @@ get: function get() { | ||
}); | ||
}; | ||
} | ||
/** | ||
@@ -168,5 +169,3 @@ * Adds a validate method useful to set the prop `validator` function. | ||
exports.withRequired = withRequired; | ||
var withValidate = function withValidate(type) { | ||
function withValidate(type) { | ||
return Object.defineProperty(type, 'validate', { | ||
@@ -179,3 +178,3 @@ value: function value(fn) { | ||
}); | ||
}; | ||
} | ||
/** | ||
@@ -190,5 +189,3 @@ * Adds `isRequired` and `def` modifiers to an object | ||
exports.withValidate = withValidate; | ||
var toType = function toType(name, obj, validateFn) { | ||
function toType(name, obj, validateFn) { | ||
if (validateFn === void 0) { | ||
@@ -214,3 +211,3 @@ validateFn = false; | ||
return obj; | ||
}; | ||
} | ||
/** | ||
@@ -226,5 +223,3 @@ * Validates a given value against a prop type object | ||
exports.toType = toType; | ||
var validateType = function validateType(type, value, silent) { | ||
function validateType(type, value, silent) { | ||
if (silent === void 0) { | ||
@@ -247,2 +242,10 @@ silent = false; | ||
if (hasOwn.call(typeToCheck, 'type') && typeToCheck.type !== null) { | ||
if (typeToCheck.type === undefined) { | ||
throw new TypeError("[VueTypes error]: Setting type to undefined is not allowed."); | ||
} | ||
if (!typeToCheck.required && value === undefined) { | ||
return valid; | ||
} | ||
if (isArray(typeToCheck.type)) { | ||
@@ -291,5 +294,4 @@ valid = typeToCheck.type.some(function (type) { | ||
return valid; | ||
}; | ||
} | ||
exports.validateType = validateType; | ||
var warn = noop; | ||
@@ -300,3 +302,3 @@ exports.warn = warn; | ||
var hasConsole = typeof console !== 'undefined'; | ||
exports.warn = warn = hasConsole ? function (msg) { | ||
exports.warn = warn = hasConsole ? function warn(msg) { | ||
// eslint-disable-next-line no-console | ||
@@ -303,0 +305,0 @@ _vue.default.config.silent === false && console.warn("[VueTypes warn]: " + msg); |
@@ -8,12 +8,12 @@ import isPlainObject from 'lodash/isPlainObject'; | ||
export var getType = function getType(fn) { | ||
export function getType(fn) { | ||
var type = fn !== null && fn !== undefined ? fn.type ? fn.type : fn : null; | ||
var match = type && type.toString().match(FN_MATCH_REGEXP); | ||
return match && match[1]; | ||
}; | ||
export var getNativeType = function getNativeType(value) { | ||
} | ||
export function getNativeType(value) { | ||
if (value === null || value === undefined) return null; | ||
var match = value.constructor.toString().match(FN_MATCH_REGEXP); | ||
return match && match[1]; | ||
}; | ||
} | ||
/** | ||
@@ -23,3 +23,3 @@ * No-op function | ||
export var noop = function noop() {}; | ||
export function noop() {} | ||
/** | ||
@@ -30,2 +30,3 @@ * Checks for a own property in an object | ||
* @param {string} prop - Property to check | ||
* @returns {boolean} | ||
*/ | ||
@@ -44,3 +45,3 @@ | ||
export var isInteger = Number.isInteger || function (value) { | ||
export var isInteger = Number.isInteger || function isInteger(value) { | ||
return typeof value === 'number' && isFinite(value) && Math.floor(value) === value; | ||
@@ -55,3 +56,3 @@ }; | ||
export var isArray = Array.isArray || function (value) { | ||
export var isArray = Array.isArray || function isArray(value) { | ||
return toString.call(value) === '[object Array]'; | ||
@@ -76,3 +77,3 @@ }; | ||
export var withDefault = function withDefault(type) { | ||
export function withDefault(type) { | ||
return Object.defineProperty(type, 'def', { | ||
@@ -106,3 +107,3 @@ value: function value(def) { | ||
}); | ||
}; | ||
} | ||
/** | ||
@@ -115,3 +116,3 @@ * Adds a `isRequired` getter returning a new object with `required: true` key-value | ||
export var withRequired = function withRequired(type) { | ||
export function withRequired(type) { | ||
return Object.defineProperty(type, 'isRequired', { | ||
@@ -124,3 +125,3 @@ get: function get() { | ||
}); | ||
}; | ||
} | ||
/** | ||
@@ -133,3 +134,3 @@ * Adds a validate method useful to set the prop `validator` function. | ||
export var withValidate = function withValidate(type) { | ||
export function withValidate(type) { | ||
return Object.defineProperty(type, 'validate', { | ||
@@ -142,3 +143,3 @@ value: function value(fn) { | ||
}); | ||
}; | ||
} | ||
/** | ||
@@ -152,3 +153,3 @@ * Adds `isRequired` and `def` modifiers to an object | ||
export var toType = function toType(name, obj, validateFn) { | ||
export function toType(name, obj, validateFn) { | ||
if (validateFn === void 0) { | ||
@@ -174,3 +175,3 @@ validateFn = false; | ||
return obj; | ||
}; | ||
} | ||
/** | ||
@@ -185,3 +186,3 @@ * Validates a given value against a prop type object | ||
export var validateType = function validateType(type, value, silent) { | ||
export function validateType(type, value, silent) { | ||
if (silent === void 0) { | ||
@@ -204,2 +205,10 @@ silent = false; | ||
if (hasOwn.call(typeToCheck, 'type') && typeToCheck.type !== null) { | ||
if (typeToCheck.type === undefined) { | ||
throw new TypeError("[VueTypes error]: Setting type to undefined is not allowed."); | ||
} | ||
if (!typeToCheck.required && value === undefined) { | ||
return valid; | ||
} | ||
if (isArray(typeToCheck.type)) { | ||
@@ -248,3 +257,3 @@ valid = typeToCheck.type.some(function (type) { | ||
return valid; | ||
}; | ||
} | ||
var warn = noop; | ||
@@ -254,3 +263,3 @@ | ||
var hasConsole = typeof console !== 'undefined'; | ||
warn = hasConsole ? function (msg) { | ||
warn = hasConsole ? function warn(msg) { | ||
// eslint-disable-next-line no-console | ||
@@ -257,0 +266,0 @@ Vue.config.silent === false && console.warn("[VueTypes warn]: " + msg); |
{ | ||
"name": "vue-types", | ||
"version": "1.5.6", | ||
"version": "1.5.7", | ||
"description": "Prop types utility for Vue", | ||
@@ -5,0 +5,0 @@ "author": "Marco Solazzi", |
@@ -11,3 +11,3 @@ import isPlainObject from 'lodash/isPlainObject' | ||
// https://github.com/vuejs/vue/blob/dev/src/core/util/props.js#L177 | ||
export const getType = (fn) => { | ||
export function getType(fn) { | ||
const type = fn !== null && fn !== undefined ? (fn.type ? fn.type : fn) : null | ||
@@ -18,3 +18,3 @@ const match = type && type.toString().match(FN_MATCH_REGEXP) | ||
export const getNativeType = (value) => { | ||
export function getNativeType(value) { | ||
if (value === null || value === undefined) return null | ||
@@ -28,3 +28,3 @@ const match = value.constructor.toString().match(FN_MATCH_REGEXP) | ||
*/ | ||
export const noop = () => {} | ||
export function noop() {} | ||
@@ -36,2 +36,3 @@ /** | ||
* @param {string} prop - Property to check | ||
* @returns {boolean} | ||
*/ | ||
@@ -49,3 +50,3 @@ export const has = (obj, prop) => hasOwn.call(obj, prop) | ||
Number.isInteger || | ||
function(value) { | ||
function isInteger(value) { | ||
return ( | ||
@@ -66,3 +67,3 @@ typeof value === 'number' && | ||
Array.isArray || | ||
function(value) { | ||
function isArray(value) { | ||
return toString.call(value) === '[object Array]' | ||
@@ -86,3 +87,3 @@ } | ||
*/ | ||
export const withDefault = function(type) { | ||
export function withDefault(type) { | ||
return Object.defineProperty(type, 'def', { | ||
@@ -117,3 +118,3 @@ value(def) { | ||
*/ | ||
export const withRequired = function(type) { | ||
export function withRequired(type) { | ||
return Object.defineProperty(type, 'isRequired', { | ||
@@ -134,3 +135,3 @@ get() { | ||
*/ | ||
export const withValidate = function(type) { | ||
export function withValidate(type) { | ||
return Object.defineProperty(type, 'validate', { | ||
@@ -152,3 +153,3 @@ value(fn) { | ||
*/ | ||
export const toType = (name, obj, validateFn = false) => { | ||
export function toType(name, obj, validateFn = false) { | ||
Object.defineProperty(obj, '_vueTypes_name', { | ||
@@ -180,3 +181,3 @@ enumerable: false, | ||
*/ | ||
export const validateType = (type, value, silent = false) => { | ||
export function validateType(type, value, silent = false) { | ||
let typeToCheck = type | ||
@@ -193,2 +194,10 @@ let valid = true | ||
if (hasOwn.call(typeToCheck, 'type') && typeToCheck.type !== null) { | ||
if (typeToCheck.type === undefined) { | ||
throw new TypeError( | ||
`[VueTypes error]: Setting type to undefined is not allowed.`, | ||
) | ||
} | ||
if (!typeToCheck.required && value === undefined) { | ||
return valid | ||
} | ||
if (isArray(typeToCheck.type)) { | ||
@@ -249,3 +258,3 @@ valid = typeToCheck.type.some((type) => validateType(type, value, true)) | ||
warn = hasConsole | ||
? (msg) => { | ||
? function warn(msg) { | ||
// eslint-disable-next-line no-console | ||
@@ -252,0 +261,0 @@ Vue.config.silent === false && console.warn(`[VueTypes warn]: ${msg}`) |
/*! vue-types - v1.5.6 | ||
/*! vue-types - v1.5.7 | ||
* https://github.com/dwightjack/vue-types | ||
@@ -259,12 +259,12 @@ * Copyright (c) 2019 - Marco Solazzi; | ||
var getType = function getType(fn) { | ||
function getType(fn) { | ||
var type = fn !== null && fn !== undefined ? fn.type ? fn.type : fn : null; | ||
var match = type && type.toString().match(FN_MATCH_REGEXP); | ||
return match && match[1]; | ||
}; | ||
var getNativeType = function getNativeType(value) { | ||
} | ||
function getNativeType(value) { | ||
if (value === null || value === undefined) return null; | ||
var match = value.constructor.toString().match(FN_MATCH_REGEXP); | ||
return match && match[1]; | ||
}; | ||
} | ||
/** | ||
@@ -274,3 +274,3 @@ * No-op function | ||
var noop = function noop() {}; | ||
function noop() {} | ||
/** | ||
@@ -284,3 +284,3 @@ * Determines whether the passed value is an integer. Uses `Number.isInteger` if available | ||
var isInteger = Number.isInteger || function (value) { | ||
var isInteger = Number.isInteger || function isInteger(value) { | ||
return typeof value === 'number' && isFinite(value) && Math.floor(value) === value; | ||
@@ -295,3 +295,3 @@ }; | ||
var isArray = Array.isArray || function (value) { | ||
var isArray = Array.isArray || function isArray(value) { | ||
return toString.call(value) === '[object Array]'; | ||
@@ -316,3 +316,3 @@ }; | ||
var withDefault = function withDefault(type) { | ||
function withDefault(type) { | ||
return Object.defineProperty(type, 'def', { | ||
@@ -346,3 +346,3 @@ value: function value(def) { | ||
}); | ||
}; | ||
} | ||
/** | ||
@@ -355,3 +355,3 @@ * Adds a `isRequired` getter returning a new object with `required: true` key-value | ||
var withRequired = function withRequired(type) { | ||
function withRequired(type) { | ||
return Object.defineProperty(type, 'isRequired', { | ||
@@ -364,3 +364,3 @@ get: function get() { | ||
}); | ||
}; | ||
} | ||
/** | ||
@@ -373,3 +373,3 @@ * Adds a validate method useful to set the prop `validator` function. | ||
var withValidate = function withValidate(type) { | ||
function withValidate(type) { | ||
return Object.defineProperty(type, 'validate', { | ||
@@ -382,3 +382,3 @@ value: function value(fn) { | ||
}); | ||
}; | ||
} | ||
/** | ||
@@ -392,3 +392,3 @@ * Adds `isRequired` and `def` modifiers to an object | ||
var toType = function toType(name, obj, validateFn) { | ||
function toType(name, obj, validateFn) { | ||
if (validateFn === void 0) { | ||
@@ -414,3 +414,3 @@ validateFn = false; | ||
return obj; | ||
}; | ||
} | ||
/** | ||
@@ -425,3 +425,3 @@ * Validates a given value against a prop type object | ||
var validateType = function validateType(type, value, silent) { | ||
function validateType(type, value, silent) { | ||
if (silent === void 0) { | ||
@@ -444,2 +444,10 @@ silent = false; | ||
if (hasOwn.call(typeToCheck, 'type') && typeToCheck.type !== null) { | ||
if (typeToCheck.type === undefined) { | ||
throw new TypeError("[VueTypes error]: Setting type to undefined is not allowed."); | ||
} | ||
if (!typeToCheck.required && value === undefined) { | ||
return valid; | ||
} | ||
if (isArray(typeToCheck.type)) { | ||
@@ -488,3 +496,3 @@ valid = typeToCheck.type.some(function (type) { | ||
return valid; | ||
}; | ||
} | ||
var warn = noop; | ||
@@ -494,3 +502,3 @@ | ||
var hasConsole = typeof console !== 'undefined'; | ||
warn = hasConsole ? function (msg) { | ||
warn = hasConsole ? function warn(msg) { | ||
// eslint-disable-next-line no-console | ||
@@ -497,0 +505,0 @@ Vue.config.silent === false && console.warn("[VueTypes warn]: " + msg); |
@@ -1,2 +0,2 @@ | ||
/*! vue-types - v1.5.6 | ||
/*! vue-types - v1.5.7 | ||
* https://github.com/dwightjack/vue-types | ||
@@ -6,3 +6,3 @@ * Copyright (c) 2019 - Marco Solazzi; | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("vue")):"function"==typeof define&&define.amd?define(["vue"],t):(e=e||self).VueTypes=t(e.Vue)}(this,function(e){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e;var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n="object"==typeof t&&t&&t.Object===Object&&t,r="object"==typeof self&&self&&self.Object===Object&&self,o=(n||r||Function("return this")()).Symbol,u=Object.prototype,i=u.hasOwnProperty,a=u.toString,f=o?o.toStringTag:void 0;var c=function(e){var t=i.call(e,f),n=e[f];try{var r=!(e[f]=void 0)}catch(e){}var o=a.call(e);return r&&(t?e[f]=n:delete e[f]),o},l=Object.prototype.toString;var s=function(e){return l.call(e)},y=o?o.toStringTag:void 0;var p=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":y&&y in Object(e)?c(e):s(e)};var b=function(t,n){return function(e){return t(n(e))}}(Object.getPrototypeOf,Object);var d=function(e){return null!=e&&"object"==typeof e},v=Function.prototype,m=Object.prototype,O=v.toString,g=m.hasOwnProperty,j=O.call(Object);function h(e){var t=null!=e?e.type?e.type:e:null,n=t&&t.toString().match(q);return n&&n[1]}function T(){}function w(e){return"[object Function]"===A.call(e)}function _(e,t,n){return void 0===n&&(n=!1),Object.defineProperty(t,"_vueTypes_name",{enumerable:!1,writable:!1,value:e}),function(e){Object.defineProperty(e,"def",{value:function(e){return(void 0!==e||this.default)&&(w(e)||k(this,e)?V(e)?this.default=function(){return[].concat(e)}:x(e)?this.default=function(){return Object.assign({},e)}:this.default=e:E(this._vueTypes_name+' - invalid default value: "'+e+'"',e)),this},enumerable:!1,writable:!1})}(function(e){return Object.defineProperty(e,"isRequired",{get:function(){return this.required=!0,this},enumerable:!1})}(t)),n&&function(e){Object.defineProperty(e,"validate",{value:function(e){return this.validator=e.bind(this),this},enumerable:!1})}(t),w(t.validator)&&(t.validator=t.validator.bind(t)),t}var P,S,x=function(e){if(!d(e)||"[object Object]"!=p(e))return!1;var t=b(e);if(null===t)return!0;var n=g.call(t,"constructor")&&t.constructor;return"function"==typeof n&&n instanceof n&&O.call(n)==j},D=Object.prototype,A=D.toString,F=D.hasOwnProperty,q=/^\s*function (\w+)/,N=Number.isInteger||function(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e},V=Array.isArray||function(e){return"[object Array]"===A.call(e)},k=function t(e,n,r){void 0===r&&(r=!1);var o,u=e,i=!0;x(e)||(u={type:e});var a,f=u._vueTypes_name?u._vueTypes_name+" - ":"";return F.call(u,"type")&&null!==u.type&&(V(u.type)?(i=u.type.some(function(e){return t(e,n,!0)}),o=u.type.map(function(e){return h(e)}).join(" or ")):i="Array"===(o=h(u))?V(n):"Object"===o?x(n):"String"===o||"Number"===o||"Boolean"===o||"Function"===o?function(e){if(null==e)return null;var t=e.constructor.toString().match(q);return t&&t[1]}(n)===o:n instanceof u.type),i?(F.call(u,"validator")&&w(u.validator)&&(r&&(a=E,E=T),i=u.validator(n),a&&(E=a),i||!1!==r||E(f+"custom validation failed")),i):(!1===r&&E(f+'value "'+n+'" should be of type "'+o+'"'),!1)},E=T,L={get any(){return _("any",{type:null},!0)},get func(){return _("function",{type:Function},!0).def(L.sensibleDefaults.func)},get bool(){return _("boolean",{type:Boolean},!0).def(L.sensibleDefaults.bool)},get string(){return _("string",{type:String},!0).def(L.sensibleDefaults.string)},get number(){return _("number",{type:Number},!0).def(L.sensibleDefaults.number)},get array(){return _("array",{type:Array},!0).def(L.sensibleDefaults.array)},get object(){return _("object",{type:Object},!0).def(L.sensibleDefaults.object)},get integer(){return _("integer",{type:Number,validator:function(e){return N(e)}}).def(L.sensibleDefaults.integer)},get symbol(){return _("symbol",{type:null,validator:function(e){return"symbol"==typeof e}},!0)},extend:function(e){void 0===e&&(e={});var t,n=e,o=n.name,r=n.validate,u=void 0!==r&&r,i=n.getter,a=void 0!==i&&i,f=function(e,t){if(null==e)return{};var n,r,o={},u=Object.keys(e);for(r=0;r<u.length;r++)n=u[r],0<=t.indexOf(n)||(o[n]=e[n]);return o}(n,["name","validate","getter"]);if(a)t={get:function(){return _(o,Object.assign({},f),u)},enumerable:!0,configurable:!1};else{var c=f.validator;t={value:function(){var e=_(o,Object.assign({},f),u);if(c){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];e.validator=c.bind.apply(c,[e].concat(n))}return e},writable:!1,enumerable:!0,configurable:!1}}return Object.defineProperty(this,o,t)},custom:function(n,r){if(void 0===r&&(r="custom validation failed"),"function"!=typeof n)throw new TypeError("[VueTypes error]: You must provide a function as argument");return _(n.name||"<<anonymous function>>",{validator:function(e){var t=n(e);return t||E(this._vueTypes_name+" - "+r),t}})},oneOf:function(n){if(!V(n))throw new TypeError("[VueTypes error]: You must provide an array as argument");var r='oneOf - value should be one of "'+n.join('", "')+'"',e=n.reduce(function(e,t){return null!=t&&-1===e.indexOf(t.constructor)&&e.push(t.constructor),e},[]);return _("oneOf",{type:0<e.length?e:null,validator:function(e){var t=-1!==n.indexOf(e);return t||E(r),t}})},instanceOf:function(e){return _("instanceOf",{type:e})},oneOfType:function(n){if(!V(n))throw new TypeError("[VueTypes error]: You must provide an array as argument");var r=!1,e=n.reduce(function(e,t){if(x(t)){if("oneOf"===t._vueTypes_name)return e.concat(t.type||[]);if(t.type&&!w(t.validator)){if(V(t.type))return e.concat(t.type);e.push(t.type)}else w(t.validator)&&(r=!0);return e}return e.push(t),e},[]);if(!r)return _("oneOfType",{type:e});var o=n.map(function(e){return e&&V(e.type)?e.type.map(h):h(e)}).reduce(function(e,t){return e.concat(V(t)?t:[t])},[]).join('", "');return this.custom(function(t){var e=n.some(function(e){return"oneOf"===e._vueTypes_name?!e.type||k(e.type,t,!0):k(e,t,!0)});return e||E('oneOfType - value type should be one of "'+o+'"'),e})},arrayOf:function(n){return _("arrayOf",{type:Array,validator:function(e){var t=e.every(function(e){return k(n,e)});return t||E('arrayOf - value must be an array of "'+h(n)+'"'),t}})},objectOf:function(n){return _("objectOf",{type:Object,validator:function(t){var e=Object.keys(t).every(function(e){return k(n,t[e])});return e||E('objectOf - value must be an object of "'+h(n)+'"'),e}})},shape:function(o){var u=Object.keys(o),e=u.filter(function(e){return o[e]&&!0===o[e].required}),t=_("shape",{type:Object,validator:function(n){var r=this;if(!x(n))return!1;var t=Object.keys(n);return 0<e.length&&e.some(function(e){return-1===t.indexOf(e)})?(E('shape - at least one of required properties "'+e.join('", "')+'" is not present'),!1):t.every(function(e){if(-1===u.indexOf(e))return!0===r._vueTypes_isLoose||(E('shape - object is missing "'+e+'" property'),!1);var t=o[e];return k(t,n[e])})}});return Object.defineProperty(t,"_vueTypes_isLoose",{enumerable:!1,writable:!0,value:!1}),Object.defineProperty(t,"loose",{get:function(){return this._vueTypes_isLoose=!0,this},enumerable:!1}),t}};return P=L,S={func:function(){},bool:!0,string:"",number:0,array:function(){return[]},object:function(){return{}},integer:0},Object.defineProperty(P,"sensibleDefaults",{enumerable:!1,set:function(e){S=!1===e?{}:!0===e?{func:function(){},bool:!0,string:"",number:0,array:function(){return[]},object:function(){return{}},integer:0}:e},get:function(){return S}}),L.utils={validate:function(e,t){return k(t,e,!0)},toType:_},L}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("vue")):"function"==typeof define&&define.amd?define(["vue"],t):(e=e||self).VueTypes=t(e.Vue)}(this,function(e){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e;var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n="object"==typeof t&&t&&t.Object===Object&&t,r="object"==typeof self&&self&&self.Object===Object&&self,o=(n||r||Function("return this")()).Symbol,u=Object.prototype,i=u.hasOwnProperty,a=u.toString,f=o?o.toStringTag:void 0;var c=function(e){var t=i.call(e,f),n=e[f];try{var r=!(e[f]=void 0)}catch(e){}var o=a.call(e);return r&&(t?e[f]=n:delete e[f]),o},l=Object.prototype.toString;var s=function(e){return l.call(e)},y=o?o.toStringTag:void 0;var p=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":y&&y in Object(e)?c(e):s(e)};var d=function(t,n){return function(e){return t(n(e))}}(Object.getPrototypeOf,Object);var b=function(e){return null!=e&&"object"==typeof e},v=Function.prototype,m=Object.prototype,O=v.toString,g=m.hasOwnProperty,j=O.call(Object);var h=function(e){if(!b(e)||"[object Object]"!=p(e))return!1;var t=d(e);if(null===t)return!0;var n=g.call(t,"constructor")&&t.constructor;return"function"==typeof n&&n instanceof n&&O.call(n)==j},T=Object.prototype,w=T.toString,_=T.hasOwnProperty,P=/^\s*function (\w+)/;function S(e){var t=null!=e?e.type?e.type:e:null,n=t&&t.toString().match(P);return n&&n[1]}function x(){}var D=Number.isInteger||function(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e},A=Array.isArray||function(e){return"[object Array]"===w.call(e)},q=function(e){return"[object Function]"===w.call(e)};function F(e,t,n){return void 0===n&&(n=!1),Object.defineProperty(t,"_vueTypes_name",{enumerable:!1,writable:!1,value:e}),function(e){Object.defineProperty(e,"def",{value:function(e){return(void 0!==e||this.default)&&(q(e)||V(this,e)?A(e)?this.default=function(){return[].concat(e)}:h(e)?this.default=function(){return Object.assign({},e)}:this.default=e:E(this._vueTypes_name+' - invalid default value: "'+e+'"',e)),this},enumerable:!1,writable:!1})}(function(e){return Object.defineProperty(e,"isRequired",{get:function(){return this.required=!0,this},enumerable:!1})}(t)),n&&function(e){Object.defineProperty(e,"validate",{value:function(e){return this.validator=e.bind(this),this},enumerable:!1})}(t),q(t.validator)&&(t.validator=t.validator.bind(t)),t}function V(e,t,n){void 0===n&&(n=!1);var r,o=e,u=!0;h(e)||(o={type:e});var i,a=o._vueTypes_name?o._vueTypes_name+" - ":"";if(_.call(o,"type")&&null!==o.type){if(void 0===o.type)throw new TypeError("[VueTypes error]: Setting type to undefined is not allowed.");if(!o.required&&void 0===t)return u;A(o.type)?(u=o.type.some(function(e){return V(e,t,!0)}),r=o.type.map(function(e){return S(e)}).join(" or ")):u="Array"===(r=S(o))?A(t):"Object"===r?h(t):"String"===r||"Number"===r||"Boolean"===r||"Function"===r?function(e){if(null==e)return null;var t=e.constructor.toString().match(P);return t&&t[1]}(t)===r:t instanceof o.type}return u?(_.call(o,"validator")&&q(o.validator)&&(n&&(i=E,E=x),u=o.validator(t),i&&(E=i),u||!1!==n||E(a+"custom validation failed")),u):(!1===n&&E(a+'value "'+t+'" should be of type "'+r+'"'),!1)}var N,k,E=x,L={get any(){return F("any",{type:null},!0)},get func(){return F("function",{type:Function},!0).def(L.sensibleDefaults.func)},get bool(){return F("boolean",{type:Boolean},!0).def(L.sensibleDefaults.bool)},get string(){return F("string",{type:String},!0).def(L.sensibleDefaults.string)},get number(){return F("number",{type:Number},!0).def(L.sensibleDefaults.number)},get array(){return F("array",{type:Array},!0).def(L.sensibleDefaults.array)},get object(){return F("object",{type:Object},!0).def(L.sensibleDefaults.object)},get integer(){return F("integer",{type:Number,validator:function(e){return D(e)}}).def(L.sensibleDefaults.integer)},get symbol(){return F("symbol",{type:null,validator:function(e){return"symbol"==typeof e}},!0)},extend:function(e){void 0===e&&(e={});var t,n=e,o=n.name,r=n.validate,u=void 0!==r&&r,i=n.getter,a=void 0!==i&&i,f=function(e,t){if(null==e)return{};var n,r,o={},u=Object.keys(e);for(r=0;r<u.length;r++)n=u[r],0<=t.indexOf(n)||(o[n]=e[n]);return o}(n,["name","validate","getter"]);if(a)t={get:function(){return F(o,Object.assign({},f),u)},enumerable:!0,configurable:!1};else{var c=f.validator;t={value:function(){var e=F(o,Object.assign({},f),u);if(c){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];e.validator=c.bind.apply(c,[e].concat(n))}return e},writable:!1,enumerable:!0,configurable:!1}}return Object.defineProperty(this,o,t)},custom:function(n,r){if(void 0===r&&(r="custom validation failed"),"function"!=typeof n)throw new TypeError("[VueTypes error]: You must provide a function as argument");return F(n.name||"<<anonymous function>>",{validator:function(e){var t=n(e);return t||E(this._vueTypes_name+" - "+r),t}})},oneOf:function(n){if(!A(n))throw new TypeError("[VueTypes error]: You must provide an array as argument");var r='oneOf - value should be one of "'+n.join('", "')+'"',e=n.reduce(function(e,t){return null!=t&&-1===e.indexOf(t.constructor)&&e.push(t.constructor),e},[]);return F("oneOf",{type:0<e.length?e:null,validator:function(e){var t=-1!==n.indexOf(e);return t||E(r),t}})},instanceOf:function(e){return F("instanceOf",{type:e})},oneOfType:function(n){if(!A(n))throw new TypeError("[VueTypes error]: You must provide an array as argument");var r=!1,e=n.reduce(function(e,t){if(h(t)){if("oneOf"===t._vueTypes_name)return e.concat(t.type||[]);if(t.type&&!q(t.validator)){if(A(t.type))return e.concat(t.type);e.push(t.type)}else q(t.validator)&&(r=!0);return e}return e.push(t),e},[]);if(!r)return F("oneOfType",{type:e});var o=n.map(function(e){return e&&A(e.type)?e.type.map(S):S(e)}).reduce(function(e,t){return e.concat(A(t)?t:[t])},[]).join('", "');return this.custom(function(t){var e=n.some(function(e){return"oneOf"===e._vueTypes_name?!e.type||V(e.type,t,!0):V(e,t,!0)});return e||E('oneOfType - value type should be one of "'+o+'"'),e})},arrayOf:function(n){return F("arrayOf",{type:Array,validator:function(e){var t=e.every(function(e){return V(n,e)});return t||E('arrayOf - value must be an array of "'+S(n)+'"'),t}})},objectOf:function(n){return F("objectOf",{type:Object,validator:function(t){var e=Object.keys(t).every(function(e){return V(n,t[e])});return e||E('objectOf - value must be an object of "'+S(n)+'"'),e}})},shape:function(o){var u=Object.keys(o),e=u.filter(function(e){return o[e]&&!0===o[e].required}),t=F("shape",{type:Object,validator:function(t){var n=this;if(!h(t))return!1;var r=Object.keys(t);return 0<e.length&&e.some(function(e){return-1===r.indexOf(e)})?(E('shape - at least one of required properties "'+e.join('", "')+'" is not present'),!1):r.every(function(e){return-1===u.indexOf(e)?!0===n._vueTypes_isLoose||(E('shape - object is missing "'+e+'" property'),!1):V(o[e],t[e])})}});return Object.defineProperty(t,"_vueTypes_isLoose",{enumerable:!1,writable:!0,value:!1}),Object.defineProperty(t,"loose",{get:function(){return this._vueTypes_isLoose=!0,this},enumerable:!1}),t}};return N=L,k={func:function(){},bool:!0,string:"",number:0,array:function(){return[]},object:function(){return{}},integer:0},Object.defineProperty(N,"sensibleDefaults",{enumerable:!1,set:function(e){k=!1===e?{}:!0===e?{func:function(){},bool:!0,string:"",number:0,array:function(){return[]},object:function(){return{}},integer:0}:e},get:function(){return k}}),L.utils={validate:function(e,t){return V(t,e,!0)},toType:F},L}); | ||
//# sourceMappingURL=vue-types.min.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
184413
2882