form-schema
Advanced tools
Comparing version 4.0.0 to 4.0.1
@@ -322,2 +322,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
this._attrs = attrs; | ||
this._validators = []; | ||
} | ||
@@ -324,0 +325,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(r,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["form-schema"]=e():r["form-schema"]=e()}(this,function(){return function(r){function e(n){if(t[n])return t[n].exports;var o=t[n]={exports:{},id:n,loaded:!1};return r[n].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var t={};return e.m=r,e.c=t,e.p="",e(0)}([function(r,e,t){"use strict";function n(r){if(Array.isArray(r)){for(var e=0,t=Array(r.length);e<r.length;e++)t[e]=r[e];return t}return Array.from(r)}function o(r){return r&&"undefined"!=typeof Symbol&&r.constructor===Symbol?"symbol":typeof r}function i(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}function a(){for(var r=arguments.length,e=Array(r),t=0;r>t;t++)e[t]=arguments[t];return new(Function.prototype.bind.apply(m,[null].concat(e)))}function u(){for(var r=arguments.length,e=Array(r),t=0;r>t;t++)e[t]=arguments[t];return new(Function.prototype.bind.apply(p.FormField,[null].concat(e)))}function c(r,e){var t=arguments.length<=2||void 0===arguments[2]?[]:arguments[2],i=arguments.length<=3||void 0===arguments[3]?[]:arguments[3],a="undefined"==typeof r?"undefined":o(r);if(a="object"===a&&Array.isArray(r)?"array":a,e instanceof m){var u=e.validate(r,t,i);return u.errorFactory=d.formError,u}if(e instanceof p.FormField){var u=e.validate(r,t,i);return u.errorFactory=y.formFieldError,u}if(Array.isArray(e)){if(Array.isArray(r)){var f=r.map(function(o,a){return c(o,e[0],[r].concat(n(t)),[a].concat(n(i)))}),s=f.every(function(r){return r.isValid});return{isValid:s,result:f}}return{isValid:!1,errors:["Expected array but got "+a+"."],errorFactory:y.formFieldError}}if("object"===("undefined"==typeof e?"undefined":o(e))){if("object"===a){var l=function(){var o=Object.keys(e).reduce(function(o,a){return o[a]=c(r[a],e[a],[r].concat(n(t)),[a].concat(n(i))),o},{}),a=Object.keys(o).every(function(r){return o[r].isValid});return{v:{isValid:a,result:o}}}();if("object"===("undefined"==typeof l?"undefined":o(l)))return l.v}return{isValid:!1,errors:["Expected object but got "+a+"."],errorFactory:y.formFieldError}}throw new Error("validateHelper(): Not supposed to reach here.")}function f(r){if(r.isValid)return null;if(r.result){var e=function(){var e=r.result;if(Array.isArray(e))return{v:e.map(f)};if("object"===("undefined"==typeof e?"undefined":o(e)))return{v:Object.keys(e).reduce(function(r,t){return r[t]=f(e[t]),r},{})};throw new Error("compactResult(): Not supposed to reach here.")}();if("object"===("undefined"==typeof e?"undefined":o(e)))return e.v}return r.errorFactory(r.errors,r.data)}function s(r,e){var t=c(r,e),n=f(t);return{isValid:t.isValid,errors:n}}var l=function(){function r(r,e){for(var t=0;t<e.length;t++){var n=e[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(r,n.key,n)}}return function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}}();Object.defineProperty(e,"__esModule",{value:!0}),e.FormFieldError=e.FormError=e.Form=void 0,e.form=a,e.field=u,e.validate=s;var d=t(1),p=t(2),y=t(3),m=e.Form=function(){function r(e){i(this,r),this._schema=e}return l(r,[{key:"getSchema",value:function(){return this._schema}},{key:"required",value:function(){return this._isRequired=!0,this}},{key:"validate",value:function(r){if("undefined"==typeof r||null===r&&"object"===("undefined"==typeof r?"undefined":o(r)))return this._isRequired?{isValid:!1,errors:["The form is required."]}:{isValid:!0,errors:[]};for(var e=arguments.length,t=Array(e>1?e-1:0),n=1;e>n;n++)t[n-1]=arguments[n];var i=c.apply(void 0,[r,this._schema].concat(t));return i}}]),r}();e.FormError=d.FormError,e.FormFieldError=y.FormFieldError},function(r,e){"use strict";function t(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}function n(r,e){if(!r)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?r:e}function o(r,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(r,e):r.__proto__=e)}function i(){for(var r=arguments.length,e=Array(r),t=0;r>t;t++)e[t]=arguments[t];return new(Function.prototype.bind.apply(a,[null].concat(e)))}Object.defineProperty(e,"__esModule",{value:!0}),e.formError=i;var a=e.FormError=function(r){function e(r,o){t(this,e);var i=n(this,Object.getPrototypeOf(e).call(this));return i.name="FormError",i.reasons=r,i.data=o,Error.captureStackTrace(i,e),i}return o(e,r),e}(Error)},function(r,e){"use strict";function t(r){return r&&"undefined"!=typeof Symbol&&r.constructor===Symbol?"symbol":typeof r}function n(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}var o=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r},i=function(){function r(r,e){for(var t=0;t<e.length;t++){var n=e[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(r,n.key,n)}}return function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}}();Object.defineProperty(e,"__esModule",{value:!0});e.FormField=function(){function r(e){n(this,r),this._attrs=e}return i(r,[{key:"validators",value:function(){for(var r=arguments.length,e=Array(r),t=0;r>t;t++)e[t]=arguments[t];return this._validators=e,this}},{key:"required",value:function(){return this._isRequired=!0,this}},{key:"isRequired",value:function(){return this._isRequired}},{key:"getAttributes",value:function(){return this._attrs}},{key:"validate",value:function(r){for(var e=arguments.length,n=Array(e>1?e-1:0),i=1;e>i;i++)n[i-1]=arguments[i];if("undefined"==typeof r||null===r&&"object"===("undefined"==typeof r?"undefined":t(r)))return this._isRequired?{isValid:!1,errors:["The field is required."]}:{isValid:!0,errors:[]};var a=this._validators.reduce(function(e,t){var o=e.isValid,i=e.errors,a=t.apply(void 0,[r].concat(n)),u=a.isValid,c=a.error;return u||i.push(c),{isValid:o&&u,errors:i}},{isValid:!0,errors:[]});return o({},a,{data:r})}}]),r}()},function(r,e){"use strict";function t(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}function n(r,e){if(!r)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?r:e}function o(r,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(r,e):r.__proto__=e)}function i(){for(var r=arguments.length,e=Array(r),t=0;r>t;t++)e[t]=arguments[t];return new(Function.prototype.bind.apply(a,[null].concat(e)))}Object.defineProperty(e,"__esModule",{value:!0}),e.formFieldError=i;var a=e.FormFieldError=function(r){function e(r,o){t(this,e);var i=n(this,Object.getPrototypeOf(e).call(this));return i.name="FormFieldError",i.reasons=r,i.data=o,Error.captureStackTrace(i,e),i}return o(e,r),e}(Error)}])}); | ||
!function(r,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["form-schema"]=e():r["form-schema"]=e()}(this,function(){return function(r){function e(n){if(t[n])return t[n].exports;var o=t[n]={exports:{},id:n,loaded:!1};return r[n].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var t={};return e.m=r,e.c=t,e.p="",e(0)}([function(r,e,t){"use strict";function n(r){if(Array.isArray(r)){for(var e=0,t=Array(r.length);e<r.length;e++)t[e]=r[e];return t}return Array.from(r)}function o(r){return r&&"undefined"!=typeof Symbol&&r.constructor===Symbol?"symbol":typeof r}function i(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}function a(){for(var r=arguments.length,e=Array(r),t=0;r>t;t++)e[t]=arguments[t];return new(Function.prototype.bind.apply(m,[null].concat(e)))}function u(){for(var r=arguments.length,e=Array(r),t=0;r>t;t++)e[t]=arguments[t];return new(Function.prototype.bind.apply(p.FormField,[null].concat(e)))}function c(r,e){var t=arguments.length<=2||void 0===arguments[2]?[]:arguments[2],i=arguments.length<=3||void 0===arguments[3]?[]:arguments[3],a="undefined"==typeof r?"undefined":o(r);if(a="object"===a&&Array.isArray(r)?"array":a,e instanceof m){var u=e.validate(r,t,i);return u.errorFactory=d.formError,u}if(e instanceof p.FormField){var u=e.validate(r,t,i);return u.errorFactory=y.formFieldError,u}if(Array.isArray(e)){if(Array.isArray(r)){var f=r.map(function(o,a){return c(o,e[0],[r].concat(n(t)),[a].concat(n(i)))}),s=f.every(function(r){return r.isValid});return{isValid:s,result:f}}return{isValid:!1,errors:["Expected array but got "+a+"."],errorFactory:y.formFieldError}}if("object"===("undefined"==typeof e?"undefined":o(e))){if("object"===a){var l=function(){var o=Object.keys(e).reduce(function(o,a){return o[a]=c(r[a],e[a],[r].concat(n(t)),[a].concat(n(i))),o},{}),a=Object.keys(o).every(function(r){return o[r].isValid});return{v:{isValid:a,result:o}}}();if("object"===("undefined"==typeof l?"undefined":o(l)))return l.v}return{isValid:!1,errors:["Expected object but got "+a+"."],errorFactory:y.formFieldError}}throw new Error("validateHelper(): Not supposed to reach here.")}function f(r){if(r.isValid)return null;if(r.result){var e=function(){var e=r.result;if(Array.isArray(e))return{v:e.map(f)};if("object"===("undefined"==typeof e?"undefined":o(e)))return{v:Object.keys(e).reduce(function(r,t){return r[t]=f(e[t]),r},{})};throw new Error("compactResult(): Not supposed to reach here.")}();if("object"===("undefined"==typeof e?"undefined":o(e)))return e.v}return r.errorFactory(r.errors,r.data)}function s(r,e){var t=c(r,e),n=f(t);return{isValid:t.isValid,errors:n}}var l=function(){function r(r,e){for(var t=0;t<e.length;t++){var n=e[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(r,n.key,n)}}return function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}}();Object.defineProperty(e,"__esModule",{value:!0}),e.FormFieldError=e.FormError=e.Form=void 0,e.form=a,e.field=u,e.validate=s;var d=t(1),p=t(2),y=t(3),m=e.Form=function(){function r(e){i(this,r),this._schema=e}return l(r,[{key:"getSchema",value:function(){return this._schema}},{key:"required",value:function(){return this._isRequired=!0,this}},{key:"validate",value:function(r){if("undefined"==typeof r||null===r&&"object"===("undefined"==typeof r?"undefined":o(r)))return this._isRequired?{isValid:!1,errors:["The form is required."]}:{isValid:!0,errors:[]};for(var e=arguments.length,t=Array(e>1?e-1:0),n=1;e>n;n++)t[n-1]=arguments[n];var i=c.apply(void 0,[r,this._schema].concat(t));return i}}]),r}();e.FormError=d.FormError,e.FormFieldError=y.FormFieldError},function(r,e){"use strict";function t(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}function n(r,e){if(!r)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?r:e}function o(r,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(r,e):r.__proto__=e)}function i(){for(var r=arguments.length,e=Array(r),t=0;r>t;t++)e[t]=arguments[t];return new(Function.prototype.bind.apply(a,[null].concat(e)))}Object.defineProperty(e,"__esModule",{value:!0}),e.formError=i;var a=e.FormError=function(r){function e(r,o){t(this,e);var i=n(this,Object.getPrototypeOf(e).call(this));return i.name="FormError",i.reasons=r,i.data=o,Error.captureStackTrace(i,e),i}return o(e,r),e}(Error)},function(r,e){"use strict";function t(r){return r&&"undefined"!=typeof Symbol&&r.constructor===Symbol?"symbol":typeof r}function n(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}var o=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r},i=function(){function r(r,e){for(var t=0;t<e.length;t++){var n=e[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(r,n.key,n)}}return function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}}();Object.defineProperty(e,"__esModule",{value:!0});e.FormField=function(){function r(e){n(this,r),this._attrs=e,this._validators=[]}return i(r,[{key:"validators",value:function(){for(var r=arguments.length,e=Array(r),t=0;r>t;t++)e[t]=arguments[t];return this._validators=e,this}},{key:"required",value:function(){return this._isRequired=!0,this}},{key:"isRequired",value:function(){return this._isRequired}},{key:"getAttributes",value:function(){return this._attrs}},{key:"validate",value:function(r){for(var e=arguments.length,n=Array(e>1?e-1:0),i=1;e>i;i++)n[i-1]=arguments[i];if("undefined"==typeof r||null===r&&"object"===("undefined"==typeof r?"undefined":t(r)))return this._isRequired?{isValid:!1,errors:["The field is required."]}:{isValid:!0,errors:[]};var a=this._validators.reduce(function(e,t){var o=e.isValid,i=e.errors,a=t.apply(void 0,[r].concat(n)),u=a.isValid,c=a.error;return u||i.push(c),{isValid:o&&u,errors:i}},{isValid:!0,errors:[]});return o({},a,{data:r})}}]),r}()},function(r,e){"use strict";function t(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}function n(r,e){if(!r)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?r:e}function o(r,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(r,e):r.__proto__=e)}function i(){for(var r=arguments.length,e=Array(r),t=0;r>t;t++)e[t]=arguments[t];return new(Function.prototype.bind.apply(a,[null].concat(e)))}Object.defineProperty(e,"__esModule",{value:!0}),e.formFieldError=i;var a=e.FormFieldError=function(r){function e(r,o){t(this,e);var i=n(this,Object.getPrototypeOf(e).call(this));return i.name="FormFieldError",i.reasons=r,i.data=o,Error.captureStackTrace(i,e),i}return o(e,r),e}(Error)}])}); |
@@ -20,2 +20,3 @@ 'use strict'; | ||
this._attrs = attrs; | ||
this._validators = []; | ||
} | ||
@@ -22,0 +23,0 @@ |
{ | ||
"name": "form-schema", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "A form validation tool that traverses the data according to the schema and calls the validators.", | ||
@@ -14,4 +14,5 @@ "main": "lib/index.js", | ||
"prepublish": "npm run lint && npm run test && npm run clean && npm run build", | ||
"test": "scripts/test", | ||
"test:watch": "scripts/test-watch" | ||
"test": "./scripts/test", | ||
"test:watch": "./scripts/test-watch", | ||
"semantic-release": "semantic-release pre && npm publish && semantic-release post" | ||
}, | ||
@@ -35,6 +36,17 @@ "keywords": [ | ||
"chai": "^3.4.1", | ||
"cz-conventional-changelog": "^1.1.5", | ||
"eslint": "^1.10.3", | ||
"mocha": "^2.3.4", | ||
"semantic-release": "^4.3.5", | ||
"webpack": "^1.12.9" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/yaru22/form-schema.git" | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "./node_modules/cz-conventional-changelog" | ||
} | ||
} | ||
} | ||
} |
export class FormField { | ||
constructor(attrs) { | ||
this._attrs = attrs; | ||
this._validators = []; | ||
} | ||
@@ -5,0 +6,0 @@ |
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
77889
23
1354
1
0
13