import{ArgumentError as t}from"../ArgumentError.js";import{ArgumentMissingError as e}from"../ArgumentMissingError.js";import{ArgumentOutOfRangeError as r}from"../ArgumentOutOfRangeError.js";export function checkArg(t,e){const r=s.instance;return r.parameter=t,r.value=e,r}class s{static instance=new s;parameter;value;isInRange(t,e,s){const a="string"==typeof this.value?parseInt(this.value):"number"==typeof this.value?this.value:NaN;if(isNaN(a)||a<t||a>e)throw new r(this.parameter,s);return this}isDefined(t){if(void 0===this.value)throw new e(this.parameter,t);return this}isNotEmpty(e){if(""===this.value||Array.isArray(this.value)&&!this.value.length)throw new t(this.parameter,this._formatMessage(e??"Parameter '{0}' cannot be empty."));return this}isNotMissing(t){if(null===this.value||void 0===this.value)throw new e(this.parameter,t);return this}isNotNull(t){if(null===this.value)throw new e(this.parameter,t);return this}matches(e,r){if("string"!=typeof this.value||!this.value.match(e))throw new t(this.parameter,this._formatMessage(r??"Parameter '{0}' was not in the expected format."));return this}satisfies(e,r){let s,a=!1;try{a=e(this.value)}catch(t){s=t?.message}if(!a)throw new t(this.parameter,this._formatMessage(r??s));return this}_formatMessage(t){return t?t.replace("{0}",this.parameter):t}}export function assertNever(t,e){if(e)throw e}