/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/sound@3.1.0/sound.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
import _ from"lodash";import isemail from"isemail";const valid={boolean:{true:!0,false:!1,t:!0,f:!1,yes:!0,no:!1,on:!0,off:!1,1:!0,0:!1}},T_IS_STRING="isString",T_IS_INTEGER="isInteger",T_IS_FLOAT="isFloat",T_IS_BOOLEAN="isBoolean",T_IS_DATE="isDate",T_IS_OBJECT="isObject",T_IS_ARRAY="isArray",T_IS_URL="isUrl",T_IS_DOMAIN="isDomain",T_IS_EMAIL_ADDRESS="isEmailAddress",T_IS_TOKEN="isToken",T_IS_MATCH="isMatch",T_IS_ENUM="isEnum",T_TO_TRIM="toTrim",T_TO_LOWER_CASE="toLowerCase",T_TO_UPPER_CASE="toUpperCase",T_TO_REPLACE="toReplace",T_IS_EQUAL="isEqual",T_IS_NOT_EMPTY="isNotEmpty",T_IS_MIN_LEN="isMinLen",T_IS_MAX_LEN="isMaxLen",T_IS_MIN_VAL="isMinVal",T_IS_MAX_VAL="isMaxVal",T_IS_GREATER_THAN="isGreaterThan",T_IS_LESS_THAN="isLessThan",T_TO_STRING="toString",T_TO_INTEGER="toInteger",T_TO_FLOAT="toFloat",T_TO_BOOLEAN="toBoolean",Constraint=function(t){return this._name=t,this._required=!1,this._requiredMsg=void 0,this._default=void 0,this.rules=[],this};Constraint.prototype.setName=function(t){return this._name=t,this},Constraint.prototype.isRequired=function(t){return this._required=!0,this._requiredMsg=t,this},Constraint.prototype.hasDefault=function(t){return this._default=t,this},Constraint.prototype.isString=function(t){return this.rules.push({type:"isString",msg:t}),this},Constraint.prototype.isInteger=function(t){return this.rules.push({type:"isInteger",msg:t}),this},Constraint.prototype.isFloat=function(t){return this.rules.push({type:"isFloat",msg:t}),this},Constraint.prototype.isBoolean=function(t){return this.rules.push({type:"isBoolean",msg:t}),this},Constraint.prototype.isDate=function(t){return this.rules.push({type:"isDate",msg:t}),this},Constraint.prototype.isObject=function(t){return this.rules.push({type:"isObject",msg:t}),this},Constraint.prototype.isArray=function(t){return this.rules.push({type:"isArray",msg:t}),this},Constraint.prototype.isEqual=function(t,e){return this.rules.push({type:"isEqual",value:t,msg:e}),this},Constraint.prototype.isLessThan=function(t,e){return this.rules.push({type:"isLessThan",value:t,msg:e}),this},Constraint.prototype.isGreaterThan=function(t,e){return this.rules.push({type:"isGreaterThan",value:t,msg:e}),this},Constraint.prototype.isMinVal=function(t,e){return this.rules.push({type:"isMinVal",value:t,msg:e}),this},Constraint.prototype.isMaxVal=function(t,e){return this.rules.push({type:"isMaxVal",value:t,msg:e}),this},Constraint.prototype.isNotEmpty=function(t){return this.rules.push({type:"isNotEmpty",msg:t}),this},Constraint.prototype.isMinLen=function(t,e){return this.rules.push({type:"isMinLen",len:t,msg:e}),this},Constraint.prototype.isMaxLen=function(t,e){return this.rules.push({type:"isMaxLen",len:t,msg:e}),this},Constraint.prototype.isMatch=function(t,e){return this.rules.push({type:"isMatch",regex:t,msg:e}),this},Constraint.prototype.isEnum=function(t,e){const s={};return t.forEach((t=>s[t]=!0)),this.rules.push({type:"isEnum",values:t,value:s,msg:e}),this},Constraint.prototype.isUrl=function(t){return this.rules.push({type:"isUrl",msg:t}),this},Constraint.prototype.isDomain=function(t){return this.rules.push({type:"isDomain",msg:t}),this},Constraint.prototype.isEmailAddress=function(t){return this.rules.push({type:"isEmailAddress",msg:t}),this},Constraint.prototype.isToken=function(t){return this.rules.push({type:"isToken",msg:t}),this},Constraint.prototype._inject=function(t){return this.rules.push(t),this},Constraint.prototype.toTrim=function(){return this.rules.push({type:"toTrim"}),this},Constraint.prototype.toLowerCase=function(){return this.rules.push({type:"toLowerCase"}),this},Constraint.prototype.toUpperCase=function(){return this.rules.push({type:"toUpperCase"}),this},Constraint.prototype.toReplace=function(t,e){return this.rules.push({type:"toReplace",a:t,b:e}),this},Constraint.prototype.toString=function(t){return this.rules.push({type:"toString",msg:t}),this},Constraint.prototype.toInteger=function(t){return this.rules.push({type:"toInteger",msg:t}),this},Constraint.prototype.toFloat=function(t){return this.rules.push({type:"toFloat",msg:t}),this},Constraint.prototype.toBoolean=function(t){return this.rules.push({type:"toBoolean",msg:t}),this};const sound=function(t){return new Constraint(t)};sound.validate=function(t,e){const s={},r={};let i=!0;return Object.keys(e).forEach((function(n){const o=validateParam(e[n]._name||n,t[n],e[n]);o.ok?void 0!==o.val&&(s[n]=o.val):(i=!1,r[n]=o.err)})),{ok:i,arg:t,val:s,err:r}};const validateParam=function(t,e,s){if(_.isUndefined(e)||_.isNull(e)||""===e){if(_.isUndefined(s._default))return s._required?{ok:!1,err:s._requiredMsg||t+" is required"}:{ok:!0};e=s._default}for(let r=0;r<s.rules.length;r++){const i=s.rules[r];if("isString"===i.type){if(!_.isString(e))return{ok:!1,err:i.msg||t+" should be a string"}}else if("isInteger"===i.type){if(parseInt(e,10)!==e)return{ok:!1,err:i.msg||t+" should be an integer"}}else if("isFloat"===i.type){if("number"!=typeof e)return{ok:!1,err:i.msg||t+" should be a float"}}else if("isBoolean"===i.type){if(!_.isBoolean(e))return{ok:!1,err:i.msg||t+" should be a boolean"}}else if("isDate"===i.type){if(!_.isDate(e))return{ok:!1,err:i.msg||t+" should be a date"}}else if("isObject"===i.type){if(!_.isPlainObject(e))return{ok:!1,err:i.msg||t+" should be an object"}}else if("isArray"===i.type){if(!_.isArray(e))return{ok:!1,err:i.msg||t+" should be an array"}}else if("isEqual"===i.type){if(e!==i.value)return{ok:!1,err:i.msg||t+" should be "+i.value}}else if("isGreaterThan"===i.type){if(e<=i.value)return{ok:!1,err:i.msg||t+" should be greater than "+i.value}}else if("isLessThan"===i.type){if(e>=i.value)return{ok:!1,err:i.msg||t+" should be less than "+i.value}}else if("isMinVal"===i.type){if(e<i.value)return{ok:!1,err:i.msg||t+" should be at least "+i.value}}else if("isMaxVal"===i.type){if(e>i.value)return{ok:!1,err:i.msg||t+" should be at most "+i.value}}else if("isNotEmpty"===i.type){if(""===e.trim())return{ok:!1,err:i.msg||t+" should be provided"}}else if("isMinLen"===i.type){if(e.length<i.len)return{ok:!1,err:i.msg||t+" should be at least "+i.len+" characters"}}else if("isMaxLen"===i.type){if(e.length>i.len)return{ok:!1,err:i.msg||t+" should be at most "+i.len+" characters"}}else if("isMatch"===i.type){if(!e.match(i.regex))return{ok:!1,err:i.msg||t+" is not valid"}}else if("isEnum"===i.type){if(!(e in i.value))return{ok:!1,err:i.msg||t+" is not a valid value"}}else if("isUrl"===i.type){if(!e.match(/^https?:\/\/[A-Za-z0-9][A-Za-z0-9-]*(\.[A-Za-z]+)+(:\d+)?(\/\S*)?$/))return{ok:!1,err:i.msg||t+" should be a URL and start with http:// or https://"}}else if("isDomain"===i.type){if(!e.match(/^([A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?\.)+[A-Za-z]{2,}$/))return{ok:!1,err:i.msg||t+" should be a FQDN such as example.com or my.example.org"}}else if("isEmailAddress"===i.type){if(0!==isemail.validate(e,{errorLevel:10}))return{ok:!1,err:i.msg||t+" should be an Email Address"}}else if("isToken"===i.type){if(!e.match(/^[a-z0-9][a-z0-9-]*[a-z0-9]$/))return{ok:!1,err:i.msg||t+" should start and end with letters/numbers and contain only lowercase letters, numbers and dashes"}}else if("toTrim"===i.type)e=e.replace(/^\s+|\s+$/g,"");else if("toLowerCase"===i.type)e=e.toLowerCase();else if("toUpperCase"===i.type)e=e.toUpperCase();else if("toReplace"===i.type)e=e.replace(i.a,i.b);else if("toString"===i.type)e=String(e);else if("toInteger"===i.type){if(e=parseInt(e,10),Number.isNaN(e))return{ok:!1,err:i.msg||t+" could not be converted to an integer"}}else if("toFloat"===i.type){if(e=parseFloat(e),Number.isNaN(e))return{ok:!1,err:i.msg||t+" could not be converted to a float"}}else{if("toBoolean"!==i.type)throw new Error("Program Error: unknown type "+i.type);if(_.isString(e)){if(!(e.toLowerCase()in valid.boolean))return{ok:!1,err:i.msg||t+" is not a recognised value when converting to boolean"};e=valid.boolean[e.toLowerCase()]}else{if(!_.isNumber(e))return{ok:!1,err:i.msg||t+" value should be a string or integer when converting to boolean"};e=!(0==e)}}}return{ok:!0,val:e}};export default sound;
//# sourceMappingURL=/sm/870c624ae153c8447a9f092bf7d7e7d6b16bb13f418feb3a2223f95becc743d5.map