Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"keyword-spacing": ["warn", {"after": true}],
"jsx-quotes": ["warn", "prefer-double"],
"no-extra-boolean-cast": "off",
"no-console": 0,
"no-multi-spaces": "warn",
"no-spaced-func": "warn",
"no-unused-vars": "warn",
Expand Down
10 changes: 7 additions & 3 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,11 @@ var Validation = function () {
key: 'isFormValid',
value: function isFormValid(state) {
var storage = state[this.validationStorageName];
if ((typeof state === 'undefined' ? 'undefined' : _typeof(state)) !== 'object') {
throw new Error('Invalid state parameter, must be object');
}
if ((typeof storage === 'undefined' ? 'undefined' : _typeof(storage)) !== 'object') {
throw new Error('Invalid fieldsMappedToStatuses object, must be object');
throw new Error('Invalid storage object, must be object');
}

var keys = Object.keys(storage);
Expand All @@ -219,13 +222,14 @@ var Validation = function () {
key: 'isFieldValid',
value: function isFieldValid(state, fieldName) {
var storage = state[this.validationStorageName];
if ((typeof state === 'undefined' ? 'undefined' : _typeof(state)) !== 'object') {
throw new Error('Invalid state parameter, must be object');
}
if ((typeof storage === 'undefined' ? 'undefined' : _typeof(storage)) !== 'object') {
throw new Error('Invalid storage object, must be object');
}
var fieldStatuses = storage[fieldName];
if (!fieldStatuses) {
// TODO: how to disable warnings in production
console.warn("Attempt to validate field that doesn't exist");
return false;
}

Expand Down
10 changes: 7 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,11 @@ class Validation {

isFormValid(state: Object): boolean {
const storage = state[this.validationStorageName];
if (typeof state !== 'object') {
throw new Error('Invalid state parameter, must be object');
}
if (typeof storage !== 'object') {
throw new Error('Invalid fieldsMappedToStatuses object, must be object');
throw new Error('Invalid storage object, must be object');
}

const keys = Object.keys(storage);
Expand All @@ -228,13 +231,14 @@ class Validation {

isFieldValid(state: Object, fieldName: string): boolean {
const storage = state[this.validationStorageName];
if (typeof state !== 'object') {
throw new Error('Invalid state parameter, must be object');
}
if (typeof storage !== 'object') {
throw new Error('Invalid storage object, must be object');
}
const fieldStatuses = storage[fieldName];
if (!fieldStatuses) {
// TODO: how to disable warnings in production
console.warn("Attempt to validate field that doesn't exist");
return false;
}

Expand Down