immutable-validation
Advanced tools
Comparing version
@@ -71,7 +71,7 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var _facts = __webpack_require__(4); | ||
var _facts = __webpack_require__(!(function webpackMissingModule() { var e = new Error("Cannot find module \"./facts\""); e.code = 'MODULE_NOT_FOUND'; throw e; }())); | ||
var facts = _interopRequireWildcard(_facts); | ||
var _rule = __webpack_require__(5); | ||
var _rule = __webpack_require__(4); | ||
@@ -432,39 +432,2 @@ var _rule2 = _interopRequireDefault(_rule); | ||
/* 4 */ | ||
/***/ function(module, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.required = required; | ||
exports.minLength = minLength; | ||
exports.maxLength = maxLength; | ||
exports.between = between; | ||
function required(val) { | ||
return !!val; | ||
} | ||
function minLength(min) { | ||
return function (val) { | ||
return val.length >= min; | ||
}; | ||
} | ||
function maxLength(max) { | ||
return function (val) { | ||
return val.length <= max; | ||
}; | ||
} | ||
function between(min, max) { | ||
return function (val) { | ||
var nVal = parseInt(val, 10); | ||
return nVal >= min && nVal <= max; | ||
}; | ||
} | ||
/***/ }, | ||
/* 5 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -471,0 +434,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("immutable")):"function"==typeof define&&define.amd?define(["immutable"],e):"object"==typeof exports?exports.ImmutableValidation=e(require("immutable")):t.ImmutableValidation=e(t.Immutable)}(this,function(t){return function(t){function e(r){if(n[r])return n[r].exports;var u=n[r]={exports:{},id:r,loaded:!1};return t[r].call(u.exports,u,u.exports,e),u.loaded=!0,u.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";function r(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e["default"]=t,e}function u(t){return t&&t.__esModule?t:{"default":t}}Object.defineProperty(e,"__esModule",{value:!0});var i=n(1),a=u(i),o=n(4),l=r(o),s=n(5),c=u(s);e["default"]={Validator:a["default"],facts:l,rule:c["default"]},t.exports=e["default"]},function(t,e,n){"use strict";function r(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function u(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t){return function(e,n){var r=o(n,t),u=r.isValid,i=r.message;return u?e:e.add(i)}}function a(t,e){var n=c(e,2),r=n[1];return t===!1?!1:r.has("isValid")?r.get("isValid"):r.has(p)&&r.get(p).count()?!1:r.entrySeq().filter(function(t){var e=c(t,1),n=e[0];return"isValid"!==n&&n!==p}).reduce(a,t)}function o(t,e){var n=t(e);if(!v.call(n,"isValid")||!v.call(n,"message"))throw new Error("Rules must return a result with the properties `isValid` and `message`. Use ImmutableValidation.rule()");return n}function l(t,e,n){var r=e(n);if(!h.isIterable(r))throw new TypeError("`"+t+"` is a non-iterable value. ruleForEach applies a validation rule to each item in an iterable");return r}function s(t,e,n){return t.has(e)&&(n=t.get(e).merge(n)),t.set(e,d.Map(n))}Object.defineProperty(e,"__esModule",{value:!0});var c=function(){function t(t,e){var n=[],r=!0,u=!1,i=void 0;try{for(var a,o=t[Symbol.iterator]();!(r=(a=o.next()).done)&&(n.push(a.value),!e||n.length!==e);r=!0);}catch(l){u=!0,i=l}finally{try{!r&&o["return"]&&o["return"]()}finally{if(u)throw i}}return n}return function(e,n){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),f=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),d=n(2),h=n(3),v=Object.prototype.hasOwnProperty,p="self",y=function(){function t(e){u(this,t),this.getValidator=e}return f(t,[{key:"validate",value:function(t){var e=this.getValidator(t);return b.isInstance(e)?e.validate(t):d.Map({isValid:!0})}}]),t}(),b=function(){function t(){u(this,t),this.ruleSets=[],this.validationState=d.Map({isValid:!0})}return f(t,[{key:"ruleFor",value:function(e,n){for(var r=arguments.length,u=Array(r>2?r-2:0),i=2;r>i;i++)u[i-2]=arguments[i];return t.isInstance(u[0])?this._addValidatorToRuleSets(e,n,u[0]):this._addRuleSetToRuleSets(e,n,u)}},{key:"ruleForEach",value:function(e,n){for(var r=arguments.length,u=Array(r>2?r-2:0),i=2;r>i;i++)u[i-2]=arguments[i];return t.isInstance(u[0])?this._addForEachValidatorToRuleSets(e,n,u[0]):this._addForEachRuleSetToRuleSets(e,n,u)}},{key:"validate",value:function(t){var e=this.ruleSets.reduce(function(e,n){return n(t,e)},d.Map()),n=e.entrySeq().filter(function(t){var e=c(t,1),n=e[0];return"isValid"!==n}).reduce(a,!0);return this.validationState=e.set("isValid",n),this.validationState}},{key:"_addValidatorToRuleSets",value:function(t,e,n){return this.ruleSets.push(function(r,u){var i=e(r),a=n.validate(i);return s(u,t,a)}),this}},{key:"_addRuleSetToRuleSets",value:function(t,e,n){return this.ruleSets.push(function(u,a){var o=a.getIn([t,p])||d.Set(),l=i(e(u)),s=n.reduce(l,o);return a.set(t,d.Map(r({},p,s)))}),this}},{key:"_addForEachValidatorToRuleSets",value:function(t,e,n){return this.ruleSets.push(function(r,u){for(var i=l(t,e,r),a=d.Map(),o=0;o<h.iterableLength(i);o++){var c=n.validate(h.get(i,o));a=a.set(o,c)}return s(u,t,a)}),this}},{key:"_addForEachRuleSetToRuleSets",value:function(t,e,n){return this.ruleSets.push(function(u,a){for(var o=l(t,e,u),c=d.Map(),f=0;f<h.iterableLength(o);f++){var v=i(h.get(o,f)),y=n.reduce(v,d.Set());c=c.set(f,d.Map(r({},p,y)))}return s(a,t,c)}),this}}],[{key:"isInstance",value:function(t){return t?h.isFunction(t.validate):!1}},{key:"which",value:function(t){if(!h.isFunction(t))throw new TypeError("Call Validator.which with a function returning a validator or null");return new y(t)}}]),t}();e["default"]=b,t.exports=e["default"]},function(e,n){e.exports=t},function(t,e){"use strict";function n(t){return t}function r(){return void 0}function u(t){return null===t?"null":void 0===t?"undefined":{}.toString.call(t).match(/\s([a-zA-Z]+)/)[1].toLowerCase()}function i(t){return"function"===u(t)}function a(t){return"string"===u(t)}function o(t){return"object"===u(t)}function l(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];return function(){for(var e=arguments.length,r=Array(e),u=0;e>u;u++)r[u]=arguments[u];return t.apply(this,n.concat(r))}}function s(t){return t&&"object"==typeof t?"length"in t||"count"in t&&i(t.count):!1}function c(t){return s(t)?i(t.count)?t.count():t.length:0}function f(t){return t&&i(t.toJS)?t.toJS():t}function d(t,e){return t&&"object"==typeof t?i(t.get)?t.get(e):t[e]:t}function h(t,e){return i(t)?t:i(e)?l(e,t):"identity"===e?l(n,t):r}Object.defineProperty(e,"__esModule",{value:!0}),e.identity=n,e.noop=r,e.toType=u,e.isFunction=i,e.isString=a,e.isObject=o,e.partial=l,e.isIterable=s,e.iterableLength=c,e.unwrapImmutable=f,e.get=d,e.asCallable=h},function(t,e){"use strict";function n(t){return!!t}function r(t){return function(e){return e.length>=t}}function u(t){return function(e){return e.length<=t}}function i(t,e){return function(n){var r=parseInt(n,10);return r>=t&&e>=r}}Object.defineProperty(e,"__esModule",{value:!0}),e.required=n,e.minLength=r,e.maxLength=u,e.between=i},function(t,e,n){"use strict";function r(t,e){return t=u.asCallable(t,function(){return!0}),e=u.asCallable(e,function(t){return u.isString(t)?t:""}),function(n){var r=t(n),u=e(n);return{isValid:r,message:u}}}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=r;var u=n(3);t.exports=e["default"]}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("immutable")):"function"==typeof define&&define.amd?define(["immutable"],e):"object"==typeof exports?exports.ImmutableValidation=e(require("immutable")):t.ImmutableValidation=e(t.Immutable)}(this,function(t){return function(t){function e(n){if(r[n])return r[n].exports;var u=r[n]={exports:{},id:n,loaded:!1};return t[n].call(u.exports,u,u.exports,e),u.loaded=!0,u.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){"use strict";function n(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e["default"]=t,e}function u(t){return t&&t.__esModule?t:{"default":t}}Object.defineProperty(e,"__esModule",{value:!0});var a=r(1),i=u(a),o=r(!function(){var t=new Error('Cannot find module "./facts"');throw t.code="MODULE_NOT_FOUND",t}()),l=n(o),s=r(4),c=u(s);e["default"]={Validator:i["default"],facts:l,rule:c["default"]},t.exports=e["default"]},function(t,e,r){"use strict";function n(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function u(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(t){return function(e,r){var n=o(r,t),u=n.isValid,a=n.message;return u?e:e.add(a)}}function i(t,e){var r=c(e,2),n=r[1];return t===!1?!1:n.has("isValid")?n.get("isValid"):n.has(p)&&n.get(p).count()?!1:n.entrySeq().filter(function(t){var e=c(t,1),r=e[0];return"isValid"!==r&&r!==p}).reduce(i,t)}function o(t,e){var r=t(e);if(!v.call(r,"isValid")||!v.call(r,"message"))throw new Error("Rules must return a result with the properties `isValid` and `message`. Use ImmutableValidation.rule()");return r}function l(t,e,r){var n=e(r);if(!h.isIterable(n))throw new TypeError("`"+t+"` is a non-iterable value. ruleForEach applies a validation rule to each item in an iterable");return n}function s(t,e,r){return t.has(e)&&(r=t.get(e).merge(r)),t.set(e,d.Map(r))}Object.defineProperty(e,"__esModule",{value:!0});var c=function(){function t(t,e){var r=[],n=!0,u=!1,a=void 0;try{for(var i,o=t[Symbol.iterator]();!(n=(i=o.next()).done)&&(r.push(i.value),!e||r.length!==e);n=!0);}catch(l){u=!0,a=l}finally{try{!n&&o["return"]&&o["return"]()}finally{if(u)throw a}}return r}return function(e,r){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),f=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),d=r(2),h=r(3),v=Object.prototype.hasOwnProperty,p="self",y=function(){function t(e){u(this,t),this.getValidator=e}return f(t,[{key:"validate",value:function(t){var e=this.getValidator(t);return b.isInstance(e)?e.validate(t):d.Map({isValid:!0})}}]),t}(),b=function(){function t(){u(this,t),this.ruleSets=[],this.validationState=d.Map({isValid:!0})}return f(t,[{key:"ruleFor",value:function(e,r){for(var n=arguments.length,u=Array(n>2?n-2:0),a=2;n>a;a++)u[a-2]=arguments[a];return t.isInstance(u[0])?this._addValidatorToRuleSets(e,r,u[0]):this._addRuleSetToRuleSets(e,r,u)}},{key:"ruleForEach",value:function(e,r){for(var n=arguments.length,u=Array(n>2?n-2:0),a=2;n>a;a++)u[a-2]=arguments[a];return t.isInstance(u[0])?this._addForEachValidatorToRuleSets(e,r,u[0]):this._addForEachRuleSetToRuleSets(e,r,u)}},{key:"validate",value:function(t){var e=this.ruleSets.reduce(function(e,r){return r(t,e)},d.Map()),r=e.entrySeq().filter(function(t){var e=c(t,1),r=e[0];return"isValid"!==r}).reduce(i,!0);return this.validationState=e.set("isValid",r),this.validationState}},{key:"_addValidatorToRuleSets",value:function(t,e,r){return this.ruleSets.push(function(n,u){var a=e(n),i=r.validate(a);return s(u,t,i)}),this}},{key:"_addRuleSetToRuleSets",value:function(t,e,r){return this.ruleSets.push(function(u,i){var o=i.getIn([t,p])||d.Set(),l=a(e(u)),s=r.reduce(l,o);return i.set(t,d.Map(n({},p,s)))}),this}},{key:"_addForEachValidatorToRuleSets",value:function(t,e,r){return this.ruleSets.push(function(n,u){for(var a=l(t,e,n),i=d.Map(),o=0;o<h.iterableLength(a);o++){var c=r.validate(h.get(a,o));i=i.set(o,c)}return s(u,t,i)}),this}},{key:"_addForEachRuleSetToRuleSets",value:function(t,e,r){return this.ruleSets.push(function(u,i){for(var o=l(t,e,u),c=d.Map(),f=0;f<h.iterableLength(o);f++){var v=a(h.get(o,f)),y=r.reduce(v,d.Set());c=c.set(f,d.Map(n({},p,y)))}return s(i,t,c)}),this}}],[{key:"isInstance",value:function(t){return t?h.isFunction(t.validate):!1}},{key:"which",value:function(t){if(!h.isFunction(t))throw new TypeError("Call Validator.which with a function returning a validator or null");return new y(t)}}]),t}();e["default"]=b,t.exports=e["default"]},function(e,r){e.exports=t},function(t,e){"use strict";function r(t){return t}function n(){return void 0}function u(t){return null===t?"null":void 0===t?"undefined":{}.toString.call(t).match(/\s([a-zA-Z]+)/)[1].toLowerCase()}function a(t){return"function"===u(t)}function i(t){return"string"===u(t)}function o(t){return"object"===u(t)}function l(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;e>n;n++)r[n-1]=arguments[n];return function(){for(var e=arguments.length,n=Array(e),u=0;e>u;u++)n[u]=arguments[u];return t.apply(this,r.concat(n))}}function s(t){return t&&"object"==typeof t?"length"in t||"count"in t&&a(t.count):!1}function c(t){return s(t)?a(t.count)?t.count():t.length:0}function f(t){return t&&a(t.toJS)?t.toJS():t}function d(t,e){return t&&"object"==typeof t?a(t.get)?t.get(e):t[e]:t}function h(t,e){return a(t)?t:a(e)?l(e,t):"identity"===e?l(r,t):n}Object.defineProperty(e,"__esModule",{value:!0}),e.identity=r,e.noop=n,e.toType=u,e.isFunction=a,e.isString=i,e.isObject=o,e.partial=l,e.isIterable=s,e.iterableLength=c,e.unwrapImmutable=f,e.get=d,e.asCallable=h},function(t,e,r){"use strict";function n(t,e){return t=u.asCallable(t,function(){return!0}),e=u.asCallable(e,function(t){return u.isString(t)?t:""}),function(r){var n=t(r),u=e(r);return{isValid:n,message:u}}}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=n;var u=r(3);t.exports=e["default"]}])}); |
{ | ||
"name": "immutable-validation", | ||
"version": "0.1.0", | ||
"version": "0.3.0", | ||
"description": "React form validation using top-down, immutable data", | ||
@@ -5,0 +5,0 @@ "main": "dist", |
@@ -0,1 +1,2 @@ | ||
/*eslint-env mocha */ | ||
import { expect } from 'chai'; | ||
@@ -2,0 +3,0 @@ import rule from '../src/rule'; |
@@ -5,3 +5,3 @@ /*eslint-env mocha */ | ||
import rule from '../src/rule'; | ||
import { required } from '../src/facts'; | ||
import { required } from '../src/predicates'; | ||
import Validator from '../src/Validator'; | ||
@@ -8,0 +8,0 @@ |
54706
-1.31%1025
-2.66%