Comparing version
@@ -0,1 +1,5 @@ | ||
### v4.0.0 (2019-05-03): | ||
* *BREAKING*: Fixed bug allowing empty string values for predefined types, even when required ([#76](https://github.com/psvet/obey/issues/76)). | ||
### v3.0.5 (2019-04-19): | ||
@@ -2,0 +6,0 @@ |
{ | ||
"name": "obey", | ||
"version": "3.0.5", | ||
"version": "4.0.0", | ||
"description": "Data modelling and validation library", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -57,4 +57,6 @@ /* | ||
} | ||
// Account for stray empties | ||
const isEmptyOrUndefined = value === undefined || value === '' | ||
// Don't run if undefined on required | ||
if (def.required && value === undefined && !def.opts.partial) { | ||
if (def.required && isEmptyOrUndefined && !def.opts.partial) { | ||
errors.push({ type: 'required', sub: 'default', key, value, message: `Property '${key}' is required` }) | ||
@@ -61,0 +63,0 @@ return value |
@@ -6,3 +6,3 @@ const email = { | ||
default: context => { | ||
if (context.value === null || context.value && !context.value.toString().match(email._regex.default)) { | ||
if (context.value == null || !context.value || !context.value.toString().match(email._regex.default)) { | ||
context.fail('Value must be a valid email') | ||
@@ -9,0 +9,0 @@ } |
@@ -7,3 +7,3 @@ const ip = { | ||
v4: context => { | ||
if (context.value === null || context.value && !context.value.toString().match(ip._regex.v4)) { | ||
if (context.value == null || !context.value.length || !context.value.toString().match(ip._regex.v4)) { | ||
context.fail('Value must be a valid IPv4 address') | ||
@@ -13,3 +13,3 @@ } | ||
v6: context => { | ||
if (context.value === null || context.value && !context.value.toString().match(ip._regex.v6)) { | ||
if (context.value == null || !context.value.length || !context.value.toString().match(ip._regex.v6)) { | ||
context.fail('Value must be a valid IPv6 address') | ||
@@ -16,0 +16,0 @@ } |
@@ -7,3 +7,4 @@ const phone = { | ||
default: context => { | ||
if (context.value === null || context.value && !context.value.toString().match(phone._regex.default)) { | ||
const stringified = context.value != null && context.value.toString() | ||
if (!stringified || !stringified.length || !stringified.toString().match(phone._regex.default)) { | ||
context.fail('Value must be a valid phone number') | ||
@@ -13,3 +14,4 @@ } | ||
numeric: context => { | ||
if (context.value === null || context.value && !context.value.toString().match(phone._regex.numeric)) { | ||
const stringified = context.value != null && context.value.toString() | ||
if (!stringified || !stringified.length || !stringified.toString().match(phone._regex.numeric)) { | ||
context.fail('Value must be a numeric phone number') | ||
@@ -16,0 +18,0 @@ } |
@@ -11,3 +11,3 @@ const string = { | ||
alphanumeric: context => { | ||
if (context.value === null || context.value && !context.value.toString().match(string._regex.alphanumeric)) { | ||
if (context.value == null || !context.value.length || !context.value.toString().match(string._regex.alphanumeric)) { | ||
context.fail('Value must contain only letters and/or numbers') | ||
@@ -14,0 +14,0 @@ } |
@@ -6,3 +6,3 @@ const url = { | ||
default: context => { | ||
if (context.value === null || context.value && !context.value.toString().match(url._regex.default)) { | ||
if (context.value == null || !context.value.length || !context.value.toString().match(url._regex.default)) { | ||
context.fail('Value must be a valid URL') | ||
@@ -9,0 +9,0 @@ } |
@@ -6,3 +6,3 @@ const uuid = { | ||
default: context => { | ||
if (context.value === null || context.value && !context.value.toString().match(uuid._regex.default)) { | ||
if (context.value == null || !context.value.length || !context.value.toString().match(uuid._regex.default)) { | ||
context.fail('Value must be a valid UUID') | ||
@@ -9,0 +9,0 @@ } |
@@ -7,3 +7,3 @@ const zip = { | ||
default: context => { | ||
if (context.value === null || context.value && !context.value.toString().match(zip._regex.default)) { | ||
if (context.value == null || !context.value.length || !context.value.toString().match(zip._regex.default)) { | ||
context.fail('Value must be a valid US zip code') | ||
@@ -13,3 +13,3 @@ } | ||
ca: context => { | ||
if (context.value === null || context.value && !context.value.toString().match(zip._regex.ca)) { | ||
if (context.value == null || !context.value.length || !context.value.toString().match(zip._regex.ca)) { | ||
context.fail('Value must be a valid Canadian zip code') | ||
@@ -16,0 +16,0 @@ } |
77783
9.28%30
3.45%848
0.47%