Comparing version 0.4.0 to 0.5.0
@@ -13,3 +13,3 @@ 'use strict'; | ||
var VueTypes = { | ||
var VuePropTypes = { | ||
@@ -151,13 +151,29 @@ get any() { | ||
var keys = Object.keys(obj); | ||
return this.custom(function (value) { | ||
if (!(0, _lodash2.default)(value)) { | ||
return false; | ||
} | ||
return Object.keys(value).every(function (key) { | ||
if (keys.indexOf(key) === -1) { | ||
var requiredKeys = keys.filter(function (key) { | ||
return obj[key] && obj[key].required === true; | ||
}); | ||
return (0, _utils.toType)({ | ||
type: Object, | ||
validator: function validator(value) { | ||
if (!(0, _lodash2.default)(value)) { | ||
return false; | ||
} | ||
var type = obj[key]; | ||
return (0, _utils.validateType)(type, value[key]); | ||
}); | ||
var valueKeys = Object.keys(value); | ||
// check for required keys (if any) | ||
if (requiredKeys.length > 0 && requiredKeys.some(function (req) { | ||
return valueKeys.indexOf(req) === -1; | ||
})) { | ||
return false; | ||
} | ||
return valueKeys.every(function (key) { | ||
if (keys.indexOf(key) === -1) { | ||
return false; | ||
} | ||
var type = obj[key]; | ||
return (0, _utils.validateType)(type, value[key]); | ||
}); | ||
} | ||
}); | ||
@@ -167,3 +183,3 @@ } | ||
exports.default = VueTypes; | ||
exports.default = VuePropTypes; | ||
module.exports = exports['default']; |
import isPlainObject from 'lodash.isplainobject'; | ||
import { noop, toType, isFunction, validateType, isInteger, isArray } from './utils'; | ||
import { noop, toType, isFunction, validateType, isInteger, isArray, has } from './utils'; | ||
var VueTypes = { | ||
var VuePropTypes = { | ||
@@ -141,13 +141,29 @@ get any() { | ||
var keys = Object.keys(obj); | ||
return this.custom(function (value) { | ||
if (!isPlainObject(value)) { | ||
return false; | ||
} | ||
return Object.keys(value).every(function (key) { | ||
if (keys.indexOf(key) === -1) { | ||
var requiredKeys = keys.filter(function (key) { | ||
return obj[key] && obj[key].required === true; | ||
}); | ||
return toType({ | ||
type: Object, | ||
validator: function validator(value) { | ||
if (!isPlainObject(value)) { | ||
return false; | ||
} | ||
var type = obj[key]; | ||
return validateType(type, value[key]); | ||
}); | ||
var valueKeys = Object.keys(value); | ||
// check for required keys (if any) | ||
if (requiredKeys.length > 0 && requiredKeys.some(function (req) { | ||
return valueKeys.indexOf(req) === -1; | ||
})) { | ||
return false; | ||
} | ||
return valueKeys.every(function (key) { | ||
if (keys.indexOf(key) === -1) { | ||
return false; | ||
} | ||
var type = obj[key]; | ||
return validateType(type, value[key]); | ||
}); | ||
} | ||
}); | ||
@@ -157,2 +173,2 @@ } | ||
export default VueTypes; | ||
export default VuePropTypes; |
{ | ||
"name": "vue-types", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "Prop types utility for Vue", | ||
@@ -56,2 +56,3 @@ "author": "Marco Solazzi", | ||
"karma-safari-launcher": "1.0.0", | ||
"karma-sauce-launcher": "1.1.0", | ||
"karma-sourcemap-loader": "0.3.7", | ||
@@ -58,0 +59,0 @@ "karma-webpack": "1.8.0", |
@@ -240,3 +240,3 @@ # vue-types | ||
Validates that a prop is an object taking on a particular shape. Accepts both simple and `vue-types` types. | ||
Validates that a prop is an object taking on a particular shape. Accepts both simple and `vue-types` types. You can set shape's types as `required` but (obviously) you cannot use `.def()` | ||
@@ -248,3 +248,4 @@ ```js | ||
name: String, | ||
age: VueTypes.integer | ||
age: VueTypes.integer, | ||
id: VueTypes.integer.isRequired | ||
}) | ||
@@ -254,4 +255,5 @@ } | ||
//accepts: userData = {name: 'John', age: 30} | ||
//rejects: userData = {name: 'John', age: 'wrong data'} | ||
//accepts: userData = {name: 'John', age: 30, id: 1} | ||
//rejects: userData = {name: 'John', age: 'wrong data', id: 1} | ||
//rejects: userData = {name: 'John', age: 'wrong data'} --> missing required `id` key | ||
``` | ||
@@ -264,2 +266,1 @@ | ||
Copyright (c) 2016 Marco Solazzi | ||
import isPlainObject from 'lodash.isplainobject' | ||
import { noop, toType, isFunction, validateType, isInteger, isArray } from './utils' | ||
import { noop, toType, isFunction, validateType, isInteger, isArray, has } from './utils' | ||
const VueTypes = { | ||
const VuePropTypes = { | ||
@@ -138,13 +138,25 @@ get any() { | ||
const keys = Object.keys(obj) | ||
return this.custom((value) => { | ||
if (!isPlainObject(value)) { | ||
return false | ||
} | ||
return Object.keys(value).every((key) => { | ||
if (keys.indexOf(key) === -1) { | ||
const requiredKeys = keys.filter((key) => obj[key] && obj[key].required === true) | ||
return toType({ | ||
type: Object, | ||
validator(value) { | ||
if (!isPlainObject(value)) { | ||
return false | ||
} | ||
const type = obj[key] | ||
return validateType(type, value[key]) | ||
}) | ||
const valueKeys = Object.keys(value) | ||
// check for required keys (if any) | ||
if (requiredKeys.length > 0 && requiredKeys.some((req) => valueKeys.indexOf(req) === -1)) { | ||
return false | ||
} | ||
return valueKeys.every((key) => { | ||
if (keys.indexOf(key) === -1) { | ||
return false | ||
} | ||
const type = obj[key] | ||
return validateType(type, value[key]) | ||
}) | ||
} | ||
}) | ||
@@ -155,2 +167,2 @@ } | ||
export default VueTypes | ||
export default VuePropTypes |
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
33077
858
263
26