diff --git a/.eslintrc b/.eslintrc index e271786..82bfa38 100644 --- a/.eslintrc +++ b/.eslintrc @@ -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", diff --git a/build/index.js b/build/index.js index 8872926..ca63015 100644 --- a/build/index.js +++ b/build/index.js @@ -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); @@ -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; } diff --git a/src/index.js b/src/index.js index 89f6e20..a0222a8 100644 --- a/src/index.js +++ b/src/index.js @@ -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); @@ -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; }