frexp
Version:
2 lines (1 loc) • 3.4 kB
JavaScript
"use strict";var e=require("./_rollupPluginBabelHelpers-aESfU7SF.js");function r(e){var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var t=r(require("yup")),n=function(){return e._createClass((function r(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;e._classCallCheck(this,r),e._defineProperty(this,"schema",void 0),e._defineProperty(this,"payload",void 0),e._defineProperty(this,"validated",void 0),e._defineProperty(this,"_error",void 0),n&&(this.schema=n(t)),a&&(this.payload=a)}),[{key:"_validate",value:(a=e._asyncToGenerator(e._regeneratorRuntime().mark((function r(){var n,a,o=arguments;return e._regeneratorRuntime().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return n=o.length>0&&void 0!==o[0]?o[0]:void 0,r.prev=1,a=e._objectSpread2({abortEarly:!1,stripUnknown:!0},n),r.next=5,this.schema.validate(this.payload,a);case 5:return this.validated=r.sent,r.abrupt("return",!1);case 9:return r.prev=9,r.t0=r.catch(1),r.t0 instanceof t.ValidationError&&(this._error=r.t0.inner.reduce((function(r,t){var n;return[].concat(e._toConsumableArray(r),[{path:t.path,type:t.type,label:null===(n=t.params)||void 0===n?void 0:n.label}])}),[])),r.abrupt("return",!0);case 13:case"end":return r.stop()}}),r,this,[[1,9]])}))),function(){return a.apply(this,arguments)})},{key:"fails",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0;return this._validate(e)}},{key:"throwError",value:(n=e._asyncToGenerator(e._regeneratorRuntime().mark((function r(){var t,n,a=arguments;return e._regeneratorRuntime().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return t=a.length>0&&void 0!==a[0]?a[0]:void 0,r.prev=1,n=e._objectSpread2({abortEarly:!1,stripUnknown:!0},t),r.next=5,this.schema.validate(this.payload,n);case 5:this.validated=r.sent,r.next=11;break;case 8:throw r.prev=8,r.t0=r.catch(1),r.t0;case 11:case"end":return r.stop()}}),r,this,[[1,8]])}))),function(){return n.apply(this,arguments)})},{key:"validation",value:(r=e._asyncToGenerator(e._regeneratorRuntime().mark((function r(n){var a,o,i=arguments;return e._regeneratorRuntime().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return a=i.length>1&&void 0!==i[1]?i[1]:void 0,r.prev=1,o=e._objectSpread2({abortEarly:!1,stripUnknown:!0},a),r.next=5,n(t).validate(this.payload,o);case 5:return r.abrupt("return",r.sent);case 8:throw r.prev=8,r.t0=r.catch(1),r.t0;case 11:case"end":return r.stop()}}),r,this,[[1,8]])}))),function(e){return r.apply(this,arguments)})},{key:"errors",value:function(){return this._error}}],[{key:"body",value:function(r){return function(){var n=e._asyncToGenerator(e._regeneratorRuntime().mark((function n(a){var o,i,u=arguments;return e._regeneratorRuntime().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return o=u.length>1&&void 0!==u[1]?u[1]:void 0,n.prev=1,i=e._objectSpread2({abortEarly:!1,stripUnknown:!0},o),n.next=5,a(t).validate(r,i);case 5:return n.abrupt("return",n.sent);case 8:throw n.prev=8,n.t0=n.catch(1),n.t0;case 11:case"end":return n.stop()}}),n,null,[[1,8]])})));return function(e){return n.apply(this,arguments)}}()}}]);var r,n,a}();module.exports=n;