Comparing version 1.6.0 to 1.6.1-beta.1
118
dist/shim.js
@@ -14,2 +14,4 @@ "use strict"; | ||
var dfn = Object.defineProperty; | ||
var isArray = Array.isArray || function (value) { | ||
@@ -19,34 +21,52 @@ return Object.prototype.toString.call(value) === '[object Array]'; | ||
var type = function type(props) { | ||
return Object.assign({ | ||
def: function def(v) { | ||
if (v === undefined && !this.default) { | ||
function type(name, props, validable) { | ||
if (validable === void 0) { | ||
validable = false; | ||
} | ||
var descriptors = { | ||
_vueTypes_name: { | ||
value: name | ||
}, | ||
def: { | ||
value: function value(v) { | ||
if (v === undefined && !this.default) { | ||
return this; | ||
} | ||
if (isArray(v)) { | ||
this.default = function () { | ||
return [].concat(v); | ||
}; | ||
} else if ((0, _isPlainObject.default)(v)) { | ||
this.default = function () { | ||
return Object.assign({}, v); | ||
}; | ||
} else { | ||
this.default = v; | ||
} | ||
return this; | ||
} | ||
if (isArray(v)) { | ||
this.default = function () { | ||
return [].concat(v); | ||
}; | ||
} else if ((0, _isPlainObject.default)(v)) { | ||
this.default = function () { | ||
return Object.assign({}, v); | ||
}; | ||
} else { | ||
this.default = v; | ||
}, | ||
isRequired: { | ||
get: function get() { | ||
this.required = true; | ||
return this; | ||
} | ||
} | ||
}; | ||
return this; | ||
}, | ||
if (validable) { | ||
descriptors.validate = { | ||
value: function value() {} | ||
}; | ||
} | ||
get isRequired() { | ||
this.required = true; | ||
return this; | ||
}, | ||
return Object.assign(Object.defineProperties({ | ||
validator: function validator() { | ||
return true; | ||
} | ||
}, props); | ||
}; | ||
}, descriptors), props); | ||
} | ||
@@ -66,3 +86,2 @@ var vueTypes = (0, _sensibles.setDefaults)({ | ||
number: Number, | ||
integer: Number, | ||
array: Array, | ||
@@ -77,3 +96,3 @@ object: Object, | ||
function createValidator(root, name, getter, props) { | ||
function createValidator(root, name, props, getter, validable) { | ||
var _descr; | ||
@@ -85,27 +104,30 @@ | ||
if (validable === void 0) { | ||
validable = false; | ||
} | ||
var prop = getter ? 'get' : 'value'; | ||
var descr = (_descr = {}, _descr[prop] = function () { | ||
return type(props).def(getter ? vueTypes.sensibleDefaults[name] : undefined); | ||
return type(name, props, validable).def(getter ? vueTypes.sensibleDefaults[name] : undefined); | ||
}, _descr); | ||
return Object.defineProperty(root, name, descr); | ||
return dfn(root, name, descr); | ||
} | ||
getters.forEach(function (p) { | ||
return createValidator(vueTypes, p, true, { | ||
type: typeMap[p] || null, | ||
validate: function validate() {} | ||
}); | ||
}); | ||
methods.forEach(function (p) { | ||
return createValidator(vueTypes, p, false, { | ||
type: typeMap[p] || null | ||
}); | ||
}); | ||
createValidator(vueTypes, 'integer', true, { | ||
function recurseValidator(root, getter, validable) { | ||
return function (name) { | ||
return createValidator(root, name, { | ||
type: typeMap[name] || null | ||
}, getter, validable); | ||
}; | ||
} | ||
getters.forEach(recurseValidator(vueTypes, true, true)); | ||
methods.forEach(recurseValidator(vueTypes, false)); | ||
createValidator(vueTypes, 'integer', { | ||
type: Number | ||
}); // does not have a validate method | ||
}, true); // does not have a validate method | ||
Object.defineProperty(vueTypes, 'shape', { | ||
dfn(vueTypes, 'shape', { | ||
value: function value() { | ||
return Object.defineProperty(type({ | ||
return dfn(type('shape', { | ||
type: Object | ||
@@ -115,4 +137,3 @@ }), 'loose', { | ||
return this; | ||
}, | ||
enumerable: false | ||
} | ||
}); | ||
@@ -129,6 +150,5 @@ } | ||
type = _props$type === void 0 ? null : _props$type; | ||
return createValidator(vueTypes, name, getter, { | ||
type: type, | ||
validate: validate ? function () {} : undefined | ||
}); | ||
return createValidator(vueTypes, name, { | ||
type: type | ||
}, getter, !!validate); | ||
}; | ||
@@ -135,0 +155,0 @@ /* eslint-disable no-console */ |
@@ -174,2 +174,3 @@ "use strict"; | ||
* @param {object} obj - Object to enhance | ||
* @param {boolean} [validateFn=false] - add the `validate()` method to the type object | ||
* @returns {object} | ||
@@ -176,0 +177,0 @@ */ |
117
es/shim.js
import Vue from 'vue'; | ||
import isPlainObject from 'is-plain-object'; | ||
import { setDefaults } from './sensibles'; | ||
var dfn = Object.defineProperty; | ||
@@ -9,34 +10,52 @@ var isArray = Array.isArray || function (value) { | ||
var type = function type(props) { | ||
return Object.assign({ | ||
def: function def(v) { | ||
if (v === undefined && !this.default) { | ||
function type(name, props, validable) { | ||
if (validable === void 0) { | ||
validable = false; | ||
} | ||
var descriptors = { | ||
_vueTypes_name: { | ||
value: name | ||
}, | ||
def: { | ||
value: function value(v) { | ||
if (v === undefined && !this.default) { | ||
return this; | ||
} | ||
if (isArray(v)) { | ||
this.default = function () { | ||
return [].concat(v); | ||
}; | ||
} else if (isPlainObject(v)) { | ||
this.default = function () { | ||
return Object.assign({}, v); | ||
}; | ||
} else { | ||
this.default = v; | ||
} | ||
return this; | ||
} | ||
if (isArray(v)) { | ||
this.default = function () { | ||
return [].concat(v); | ||
}; | ||
} else if (isPlainObject(v)) { | ||
this.default = function () { | ||
return Object.assign({}, v); | ||
}; | ||
} else { | ||
this.default = v; | ||
}, | ||
isRequired: { | ||
get: function get() { | ||
this.required = true; | ||
return this; | ||
} | ||
} | ||
}; | ||
return this; | ||
}, | ||
if (validable) { | ||
descriptors.validate = { | ||
value: function value() {} | ||
}; | ||
} | ||
get isRequired() { | ||
this.required = true; | ||
return this; | ||
}, | ||
return Object.assign(Object.defineProperties({ | ||
validator: function validator() { | ||
return true; | ||
} | ||
}, props); | ||
}; | ||
}, descriptors), props); | ||
} | ||
@@ -56,3 +75,2 @@ var vueTypes = setDefaults({ | ||
number: Number, | ||
integer: Number, | ||
array: Array, | ||
@@ -67,3 +85,3 @@ object: Object, | ||
function createValidator(root, name, getter, props) { | ||
function createValidator(root, name, props, getter, validable) { | ||
var _descr; | ||
@@ -75,27 +93,30 @@ | ||
if (validable === void 0) { | ||
validable = false; | ||
} | ||
var prop = getter ? 'get' : 'value'; | ||
var descr = (_descr = {}, _descr[prop] = function () { | ||
return type(props).def(getter ? vueTypes.sensibleDefaults[name] : undefined); | ||
return type(name, props, validable).def(getter ? vueTypes.sensibleDefaults[name] : undefined); | ||
}, _descr); | ||
return Object.defineProperty(root, name, descr); | ||
return dfn(root, name, descr); | ||
} | ||
getters.forEach(function (p) { | ||
return createValidator(vueTypes, p, true, { | ||
type: typeMap[p] || null, | ||
validate: function validate() {} | ||
}); | ||
}); | ||
methods.forEach(function (p) { | ||
return createValidator(vueTypes, p, false, { | ||
type: typeMap[p] || null | ||
}); | ||
}); | ||
createValidator(vueTypes, 'integer', true, { | ||
function recurseValidator(root, getter, validable) { | ||
return function (name) { | ||
return createValidator(root, name, { | ||
type: typeMap[name] || null | ||
}, getter, validable); | ||
}; | ||
} | ||
getters.forEach(recurseValidator(vueTypes, true, true)); | ||
methods.forEach(recurseValidator(vueTypes, false)); | ||
createValidator(vueTypes, 'integer', { | ||
type: Number | ||
}); // does not have a validate method | ||
}, true); // does not have a validate method | ||
Object.defineProperty(vueTypes, 'shape', { | ||
dfn(vueTypes, 'shape', { | ||
value: function value() { | ||
return Object.defineProperty(type({ | ||
return dfn(type('shape', { | ||
type: Object | ||
@@ -105,4 +126,3 @@ }), 'loose', { | ||
return this; | ||
}, | ||
enumerable: false | ||
} | ||
}); | ||
@@ -119,6 +139,5 @@ } | ||
type = _props$type === void 0 ? null : _props$type; | ||
return createValidator(vueTypes, name, getter, { | ||
type: type, | ||
validate: validate ? function () {} : undefined | ||
}); | ||
return createValidator(vueTypes, name, { | ||
type: type | ||
}, getter, !!validate); | ||
}; | ||
@@ -125,0 +144,0 @@ /* eslint-disable no-console */ |
@@ -139,2 +139,3 @@ import isPlainObject from 'is-plain-object'; | ||
* @param {object} obj - Object to enhance | ||
* @param {boolean} [validateFn=false] - add the `validate()` method to the type object | ||
* @returns {object} | ||
@@ -141,0 +142,0 @@ */ |
{ | ||
"name": "vue-types", | ||
"version": "1.6.0", | ||
"version": "1.6.1-beta.1", | ||
"description": "Prop types utility for Vue", | ||
@@ -5,0 +5,0 @@ "author": "Marco Solazzi", |
195
README.md
@@ -5,20 +5,19 @@ # vue-types | ||
<!-- TOC depthTo:3 --> | ||
- [Introduction](#introduction) | ||
- [When to use](#when-to-use) | ||
- [When to use](#when-to-use) | ||
- [Installation](#installation) | ||
- [NPM package](#npm-package) | ||
- [CDN delivered `<script>`](#cdn-delivered-script) | ||
- [NPM package](#npm-package) | ||
- [CDN delivered `<script>`](#cdn-delivered-script) | ||
- [Usage with `eslint-plugin-vue`](#usage-with-eslint-plugin-vue) | ||
- [Production build](#production-build) | ||
- [Webpack](#webpack) | ||
- [Rollup](#rollup) | ||
- [Webpack](#webpack) | ||
- [Rollup](#rollup) | ||
- [Documentation](#documentation) | ||
- [Native Types](#native-types) | ||
- [Native Types Configuration](#native-types-configuration) | ||
- [Custom Types](#custom-types) | ||
- [Extending VueTypes](#extending-vuetypes) | ||
- [Utilities](#utilities) | ||
- [Native Types](#native-types) | ||
- [Native Types Configuration](#native-types-configuration) | ||
- [Custom Types](#custom-types) | ||
- [Extending VueTypes](#extending-vuetypes) | ||
- [Utilities](#utilities) | ||
- [License](#license) | ||
@@ -46,7 +45,7 @@ | ||
type: Number, | ||
default: 10 | ||
default: 10, | ||
}, | ||
name: { | ||
type: String, | ||
required: true | ||
required: true, | ||
}, | ||
@@ -57,10 +56,10 @@ age: { | ||
return Number.isInteger(value) | ||
} | ||
}, | ||
}, | ||
nationality: String | ||
nationality: String, | ||
}, | ||
methods: { | ||
// ... | ||
} | ||
}; | ||
}, | ||
} | ||
``` | ||
@@ -71,5 +70,4 @@ | ||
```js | ||
import VueTypes from 'vue-types' | ||
import VueTypes from 'vue-types'; | ||
export default { | ||
@@ -81,11 +79,10 @@ props: { | ||
// No need for `default` or `required` key, so keep it simple | ||
nationality: String | ||
nationality: String, | ||
}, | ||
methods: { | ||
// ... | ||
} | ||
}, | ||
} | ||
``` | ||
## Installation | ||
@@ -95,3 +92,3 @@ | ||
``` bash | ||
```bash | ||
npm install vue-types --save | ||
@@ -105,2 +102,3 @@ # or | ||
add the following script tags before your code | ||
```html | ||
@@ -144,5 +142,8 @@ <script src="https://unpkg.com/vue-types"></script> | ||
alias: { | ||
'vue-types': process.env.NODE_ENV === 'production' ? 'vue-types/es/shim.js' : undefined | ||
} | ||
} | ||
// ... other aliases | ||
...(process.env.NODE_ENV === 'production' && { | ||
'vue-types': require.resolve('vue-types/es/shim.js'), | ||
}), | ||
}, | ||
}, | ||
} | ||
@@ -157,3 +158,3 @@ ``` | ||
// rollup.config.js | ||
import alias from 'rollup-plugin-alias'; | ||
import alias from 'rollup-plugin-alias' | ||
@@ -163,6 +164,9 @@ return { | ||
plugins: [ | ||
process.env.NODE_ENV === 'production' ? alias({ | ||
'vue-types': './node_modules/vue-types/es/shim.js' | ||
}) | ||
] | ||
// ...other plugins | ||
...(process.env.NODE_ENV === 'production' && [ | ||
alias({ | ||
'vue-types': require.resolve('vue-types/es/shim.js'), | ||
}), | ||
]), | ||
], | ||
} | ||
@@ -179,6 +183,6 @@ ``` | ||
* a default value (not available in `.any` and `.symbol`). | ||
* a `.def(any)` method to reassign the default value for the current prop. The passed-in value will be validated against the type configuration in order to prevent invalid values. | ||
* a `isRequired` flag to set the `required: true` key. | ||
* a `validate(function)` method to set a custom validator function (not available in `.integer`). | ||
- a default value (not available in `.any` and `.symbol`). | ||
- a `.def(any)` method to reassign the default value for the current prop. The passed-in value will be validated against the type configuration in order to prevent invalid values. | ||
- a `isRequired` flag to set the `required: true` key. | ||
- a `validate(function)` method to set a custom validator function (not available in `.integer`). | ||
@@ -211,3 +215,3 @@ ```js | ||
* default: an empty array | ||
- default: an empty array | ||
@@ -220,3 +224,3 @@ _Note: [Vue prop validation](https://vuejs.org/v2/guide/components-props.html#Prop-Validation) requires Array definitions to provide default value as a factory function. `VueTypes.array.def()` accepts both factory functions and arrays. In the latter case, VueTypes will convert the value to a factory function for you._ | ||
* default: `true` | ||
- default: `true` | ||
@@ -227,3 +231,3 @@ #### `VueTypes.func` | ||
* default: an empty function | ||
- default: an empty function | ||
@@ -234,3 +238,3 @@ #### `VueTypes.number` | ||
* default: `0` | ||
- default: `0` | ||
@@ -241,3 +245,3 @@ #### `VueTypes.integer` | ||
* default: `0` | ||
- default: `0` | ||
@@ -248,3 +252,3 @@ #### `VueTypes.object` | ||
* default: an empty object | ||
- default: an empty object | ||
@@ -257,3 +261,3 @@ _Note: [Vue prop validation](https://vuejs.org/v2/guide/components-props.html#Prop-Validation) requires Object definitions to provide default value as a factory function. `VueTypes.object.def()` accepts both factory functions and plain objects. In the latter case, VueTypes will convert the value to a factory function for you._ | ||
* default: `''` | ||
- default: `''` | ||
@@ -268,3 +272,3 @@ #### `VueTypes.symbol` | ||
* default: none | ||
- default: none | ||
@@ -285,3 +289,3 @@ ### Native Types Configuration | ||
VueTypes.sensibleDefaults = { | ||
string: 'mystringdefault' | ||
string: 'mystringdefault', | ||
//... | ||
@@ -314,6 +318,6 @@ } | ||
* **doesn't have** any sensible default value | ||
* **doesn't have** a `validate` method | ||
* has a `.def()` method to assign a default value on the current prop | ||
* has an `isRequired` flag to set the `required: true` key | ||
- **doesn't have** any sensible default value | ||
- **doesn't have** a `validate` method | ||
- has a `.def()` method to assign a default value on the current prop | ||
- has an `isRequired` flag to set the `required: true` key | ||
@@ -341,4 +345,4 @@ ```js | ||
props: { | ||
user: VueTypes.instanceOf(Person) | ||
} | ||
user: VueTypes.instanceOf(Person), | ||
}, | ||
} | ||
@@ -356,4 +360,4 @@ ``` | ||
props: { | ||
genre: VueTypes.oneOf(['action', 'thriller']) | ||
} | ||
genre: VueTypes.oneOf(['action', 'thriller']), | ||
}, | ||
} | ||
@@ -372,5 +376,5 @@ ``` | ||
VueTypes.integer, | ||
VueTypes.instanceOf(Person) | ||
]) | ||
} | ||
VueTypes.instanceOf(Person), | ||
]), | ||
}, | ||
} | ||
@@ -386,4 +390,4 @@ ``` | ||
props: { | ||
theProp: VueTypes.arrayOf(String) | ||
} | ||
theProp: VueTypes.arrayOf(String), | ||
}, | ||
} | ||
@@ -402,4 +406,4 @@ | ||
props: { | ||
userData: VueTypes.objectOf(String) | ||
} | ||
userData: VueTypes.objectOf(String), | ||
}, | ||
} | ||
@@ -413,3 +417,3 @@ | ||
Validates that a prop is an object taking on a particular shape. Accepts both simple and `vue-types` types. You can set shape's properties as `required` but (obviously) you cannot use `.def()`. On the other hand you can use `def()` to set a default value for the shape itself. Like `VueTypes.array` and `VueTypes.object`, you can pass to `.def()` either a factory function returning an object or a plain object. | ||
Validates that a prop is an object taking on a particular shape. Accepts both simple and `vue-types` types. You can set shape's properties as `required` but (obviously) you cannot use `.def()`. On the other hand you can use `def()` to set a default value for the shape itself. Like `VueTypes.array` and `VueTypes.object`, you can pass to `.def()` either a factory function returning an object or a plain object. | ||
@@ -422,5 +426,5 @@ ```js | ||
age: VueTypes.integer, | ||
id: VueTypes.integer.isRequired | ||
}).def(() => ({ name: 'John' })) | ||
} | ||
id: VueTypes.integer.isRequired, | ||
}).def(() => ({ name: 'John' })), | ||
}, | ||
} | ||
@@ -441,9 +445,9 @@ | ||
name: String, | ||
id: VueTypes.integer.isRequired | ||
id: VueTypes.integer.isRequired, | ||
}), | ||
userDataLoose: VueTypes.shape({ | ||
name: String, | ||
id: VueTypes.integer.isRequired | ||
}).loose | ||
} | ||
id: VueTypes.integer.isRequired, | ||
}).loose, | ||
}, | ||
} | ||
@@ -461,11 +465,10 @@ | ||
```js | ||
function minLength(value) { | ||
return typeof value === 'string' && value.length >= 6 | ||
} | ||
return typeof value === 'string' && value.length >= 6 | ||
} | ||
export default { | ||
props: { | ||
theProp: VueTypes.custom(minLength) | ||
} | ||
theProp: VueTypes.custom(minLength), | ||
}, | ||
} | ||
@@ -483,4 +486,4 @@ | ||
function minLength(value) { | ||
return typeof value === 'string' && value.length >= 6 | ||
} | ||
return typeof value === 'string' && value.length >= 6 | ||
} | ||
@@ -491,5 +494,5 @@ export default { | ||
minLength, | ||
'theProp is not a string or is too short' | ||
) | ||
} | ||
'theProp is not a string or is too short', | ||
), | ||
}, | ||
} | ||
@@ -507,2 +510,3 @@ ``` | ||
Examples: | ||
```js | ||
@@ -514,3 +518,3 @@ // as an accessor type | ||
type: Number, | ||
validator: (v) => v < 0 | ||
validator: (v) => v < 0, | ||
}) | ||
@@ -524,3 +528,3 @@ | ||
type: Number, | ||
validator: (v) => v < 0 | ||
validator: (v) => v < 0, | ||
}) | ||
@@ -538,3 +542,3 @@ | ||
type: String, | ||
validator: (max, v) => v.length <= max | ||
validator: (max, v) => v.length <= max, | ||
}) | ||
@@ -569,3 +573,3 @@ | ||
type: String, | ||
validator: (max: number, v: string) => v.length <= max | ||
validator: (max: number, v: string) => v.length <= max, | ||
}) | ||
@@ -581,14 +585,14 @@ | ||
<template> | ||
<!-- template here --> | ||
<!-- template here --> | ||
</template> | ||
<script lang="ts"> | ||
import Vue from "vue"; | ||
import VueTypes from "./prop-types"; | ||
import Vue from 'vue' | ||
import VueTypes from './prop-types' | ||
export default Vue.extend({ | ||
name: "MyComponent", | ||
props: { | ||
msg: VueTypes.maxLength(2) | ||
} | ||
}); | ||
export default Vue.extend({ | ||
name: 'MyComponent', | ||
props: { | ||
msg: VueTypes.maxLength(2), | ||
}, | ||
}) | ||
</script> | ||
@@ -618,3 +622,3 @@ ``` | ||
return value.length === 'John' | ||
} | ||
}, | ||
} | ||
@@ -636,3 +640,3 @@ | ||
return value.length > 10 | ||
} | ||
}, | ||
} | ||
@@ -644,6 +648,5 @@ | ||
props: { | ||
password: passwordType.isRequired | ||
} | ||
password: passwordType.isRequired, | ||
}, | ||
} | ||
``` | ||
@@ -655,2 +658,2 @@ | ||
Copyright (c) 2018 Marco Solazzi | ||
Copyright (c) 2019 Marco Solazzi |
@@ -5,2 +5,4 @@ import Vue from 'vue' | ||
const dfn = Object.defineProperty | ||
const isArray = | ||
@@ -12,6 +14,9 @@ Array.isArray || | ||
const type = (props) => | ||
Object.assign( | ||
{ | ||
def(v) { | ||
function type(name, props, validable = false) { | ||
const descriptors = { | ||
_vueTypes_name: { | ||
value: name, | ||
}, | ||
def: { | ||
value(v) { | ||
if (v === undefined && !this.default) { | ||
@@ -29,12 +34,26 @@ return this | ||
}, | ||
get isRequired() { | ||
}, | ||
isRequired: { | ||
get() { | ||
this.required = true | ||
return this | ||
}, | ||
validator() { | ||
return true | ||
}, | ||
} | ||
if (validable) { | ||
descriptors.validate = { | ||
value() {}, | ||
} | ||
} | ||
return Object.assign( | ||
Object.defineProperties( | ||
{ | ||
validator: () => true, | ||
}, | ||
}, | ||
descriptors, | ||
), | ||
props, | ||
) | ||
} | ||
@@ -53,3 +72,2 @@ const vueTypes = setDefaults({ | ||
number: Number, | ||
integer: Number, | ||
array: Array, | ||
@@ -81,30 +99,36 @@ object: Object, | ||
function createValidator(root, name, getter = false, props) { | ||
function createValidator(root, name, props, getter = false, validable = false) { | ||
const prop = getter ? 'get' : 'value' | ||
const descr = { | ||
[prop]: () => | ||
type(props).def(getter ? vueTypes.sensibleDefaults[name] : undefined), | ||
type(name, props, validable).def( | ||
getter ? vueTypes.sensibleDefaults[name] : undefined, | ||
), | ||
} | ||
return Object.defineProperty(root, name, descr) | ||
return dfn(root, name, descr) | ||
} | ||
getters.forEach((p) => | ||
createValidator(vueTypes, p, true, { | ||
type: typeMap[p] || null, | ||
validate() {}, | ||
}), | ||
) | ||
methods.forEach((p) => | ||
createValidator(vueTypes, p, false, { type: typeMap[p] || null }), | ||
) | ||
createValidator(vueTypes, 'integer', true, { type: Number }) // does not have a validate method | ||
function recurseValidator(root, getter, validable) { | ||
return (name) => | ||
createValidator( | ||
root, | ||
name, | ||
{ type: typeMap[name] || null }, | ||
getter, | ||
validable, | ||
) | ||
} | ||
Object.defineProperty(vueTypes, 'shape', { | ||
getters.forEach(recurseValidator(vueTypes, true, true)) | ||
methods.forEach(recurseValidator(vueTypes, false)) | ||
createValidator(vueTypes, 'integer', { type: Number }, true) // does not have a validate method | ||
dfn(vueTypes, 'shape', { | ||
value() { | ||
return Object.defineProperty(type({ type: Object }), 'loose', { | ||
return dfn(type('shape', { type: Object }), 'loose', { | ||
get() { | ||
return this | ||
}, | ||
enumerable: false, | ||
}) | ||
@@ -116,6 +140,3 @@ }, | ||
const { name, validate, getter = false, type = null } = props | ||
return createValidator(vueTypes, name, getter, { | ||
type, | ||
validate: validate ? () => {} : undefined, | ||
}) | ||
return createValidator(vueTypes, name, { type }, getter, !!validate) | ||
} | ||
@@ -122,0 +143,0 @@ |
@@ -142,2 +142,3 @@ import isPlainObject from 'is-plain-object' | ||
* @param {object} obj - Object to enhance | ||
* @param {boolean} [validateFn=false] - add the `validate()` method to the type object | ||
* @returns {object} | ||
@@ -144,0 +145,0 @@ */ |
/*! vue-types - v1.6.0 | ||
/*! vue-types - v1.6.1-beta.1 | ||
* https://github.com/dwightjack/vue-types | ||
@@ -201,2 +201,3 @@ * Copyright (c) 2019 - Marco Solazzi; | ||
* @param {object} obj - Object to enhance | ||
* @param {boolean} [validateFn=false] - add the `validate()` method to the type object | ||
* @returns {object} | ||
@@ -203,0 +204,0 @@ */ |
@@ -1,2 +0,2 @@ | ||
/*! vue-types - v1.6.0 | ||
/*! vue-types - v1.6.1-beta.1 | ||
* https://github.com/dwightjack/vue-types | ||
@@ -3,0 +3,0 @@ * Copyright (c) 2019 - Marco Solazzi; |
@@ -1,2 +0,2 @@ | ||
/*! vue-types - v1.6.0 | ||
/*! vue-types - v1.6.1-beta.1 | ||
* https://github.com/dwightjack/vue-types | ||
@@ -13,3 +13,3 @@ * Copyright (c) 2019 - Marco Solazzi; | ||
*/ | ||
function r(e){return!0=== | ||
function u(e){return!0=== | ||
/*! | ||
@@ -21,3 +21,3 @@ * isobject <https://github.com/jonschlinkert/isobject> | ||
*/ | ||
function(e){return null!=e&&"object"==typeof e&&!1===Array.isArray(e)}(e)&&"[object Object]"===Object.prototype.toString.call(e)}e=e&&e.hasOwnProperty("default")?e.default:e;function i(e){return Object.assign({def:function(e){return(void 0!==e||this.default)&&(u(e)?this.default=function(){return[].concat(e)}:!function(e){var t,n;return!1!==r(e)&&("function"==typeof(t=e.constructor)&&(!1!==r(n=t.prototype)&&!1!==n.hasOwnProperty("isPrototypeOf")))}(e)?this.default=e:this.default=function(){return Object.assign({},e)}),this},get isRequired(){return this.required=!0,this},validator:function(){return!0}},e)}var t,n,u=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},c=(t={utils:{toType:i,validate:function(){return!0}}},n={func:function(){},bool:!0,string:"",number:0,array:function(){return[]},object:function(){return{}},integer:0},Object.defineProperty(t,"sensibleDefaults",{enumerable:!1,set:function(e){n=!1===e?{}:!0===e?{func:function(){},bool:!0,string:"",number:0,array:function(){return[]},object:function(){return{}},integer:0}:e},get:function(){return n}})),o={func:Function,bool:Boolean,string:String,number:Number,integer:Number,array:Array,object:Object,arrayOf:Array,objectOf:Object,shape:Object};function f(e,t,n,r){var u;void 0===n&&(n=!1);var o=((u={})[n?"get":"value"]=function(){return i(r).def(n?c.sensibleDefaults[t]:void 0)},u);return Object.defineProperty(e,t,o)}return["any","func","bool","string","number","array","object","symbol"].forEach(function(e){return f(c,e,!0,{type:o[e]||null,validate:function(){}})}),["oneOf","custom","instanceOf","oneOfType","arrayOf","objectOf"].forEach(function(e){return f(c,e,!1,{type:o[e]||null})}),f(c,"integer",!0,{type:Number}),Object.defineProperty(c,"shape",{value:function(){return Object.defineProperty(i({type:Object}),"loose",{get:function(){return this},enumerable:!1})}}),c.extend=function(e){var t=e.name,n=e.validate,r=e.getter,u=void 0!==r&&r,o=e.type;return f(c,t,u,{type:void 0===o?null:o,validate:n?function(){}:void 0})},c}); | ||
function(e){return null!=e&&"object"==typeof e&&!1===Array.isArray(e)}(e)&&"[object Object]"===Object.prototype.toString.call(e)}e=e&&e.hasOwnProperty("default")?e.default:e;var c=Object.defineProperty,o=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)};function f(e,t,n){void 0===n&&(n=!1);var r={_vueTypes_name:{value:e},def:{value:function(e){return(void 0!==e||this.default)&&(o(e)?this.default=function(){return[].concat(e)}:!function(e){var t,n;return!1!==u(e)&&("function"==typeof(t=e.constructor)&&(!1!==u(n=t.prototype)&&!1!==n.hasOwnProperty("isPrototypeOf")))}(e)?this.default=e:this.default=function(){return Object.assign({},e)}),this}},isRequired:{get:function(){return this.required=!0,this}}};return n&&(r.validate={value:function(){}}),Object.assign(Object.defineProperties({validator:function(){return!0}},r),t)}var t,n,a=(t={utils:{toType:f,validate:function(){return!0}}},n={func:function(){},bool:!0,string:"",number:0,array:function(){return[]},object:function(){return{}},integer:0},Object.defineProperty(t,"sensibleDefaults",{enumerable:!1,set:function(e){n=!1===e?{}:!0===e?{func:function(){},bool:!0,string:"",number:0,array:function(){return[]},object:function(){return{}},integer:0}:e},get:function(){return n}})),i={func:Function,bool:Boolean,string:String,number:Number,array:Array,object:Object,arrayOf:Array,objectOf:Object,shape:Object};function s(e,t,n,r,u){var o;void 0===r&&(r=!1),void 0===u&&(u=!1);var i=((o={})[r?"get":"value"]=function(){return f(t,n,u).def(r?a.sensibleDefaults[t]:void 0)},o);return c(e,t,i)}function r(t,n,r){return function(e){return s(t,e,{type:i[e]||null},n,r)}}return["any","func","bool","string","number","array","object","symbol"].forEach(r(a,!0,!0)),["oneOf","custom","instanceOf","oneOfType","arrayOf","objectOf"].forEach(r(a,!1)),s(a,"integer",{type:Number},!0),c(a,"shape",{value:function(){return c(f("shape",{type:Object}),"loose",{get:function(){return this}})}}),a.extend=function(e){var t=e.name,n=e.validate,r=e.getter,u=void 0!==r&&r,o=e.type;return s(a,t,{type:void 0===o?null:o},u,!!n)},a}); | ||
//# sourceMappingURL=vue-types.shim.min.js.map |
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
177801
2823
618
3