function n(t){return n=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},n(t)}function t(n,r){return t=Object.setPrototypeOf||function(n,t){return n.__proto__=t,n},t(n,r)}function r(n,e,u){return r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(n){return!1}}()?Reflect.construct:function(n,r,e){var u=[null];u.push.apply(u,r);var i=new(Function.bind.apply(n,u));return e&&t(i,e.prototype),i},r.apply(null,arguments)}function e(u){var i="function"==typeof Map?new Map:void 0;return e=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==i){if(i.has(e))return i.get(e);i.set(e,u)}function u(){return r(e,arguments,n(this).constructor)}return u.prototype=Object.create(e.prototype,{constructor:{value:u,enumerable:!1,writable:!0,configurable:!0}}),t(u,e)},e(u)}function u(n,t){(null==t||t>n.length)&&(t=n.length);for(var r=0,e=new Array(t);r=n.length?{done:!0}:{done:!1,value:n[e++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o=Symbol.for("@ts-pattern/matcher"),c=Symbol.for("@ts-pattern/isVariadic"),f="@ts-pattern/anonymous-select-key",a=function(n){return Boolean(n&&"object"==typeof n)},l=function(n){return n&&!!n[o]},s=function n(t,r,e){if(l(t)){var u=t[o]().match(r),f=u.matched,s=u.selections;return f&&s&&Object.keys(s).forEach(function(n){return e(n,s[n])}),f}if(a(t)){if(!a(r))return!1;if(Array.isArray(t)){if(!Array.isArray(r))return!1;for(var h,v=[],p=[],g=[],y=i(t.keys());!(h=y()).done;){var m=t[h.value];l(m)&&m[c]?g.push(m):g.length?p.push(m):v.push(m)}if(g.length){if(g.length>1)throw new Error("Pattern error: Using `...P.array(...)` several times in a single pattern is not allowed.");if(r.length=n})}(r)))},length:function(r){return n(w(t,function(n){return S(function(t){return A(t)&&t.length===n})}(r)))},maxLength:function(r){return n(w(t,function(n){return S(function(t){return A(t)&&t.length<=n})}(r)))},includes:function(r){return n(w(t,(e=r,S(function(n){return A(n)&&n.includes(e)}))));var e},regex:function(r){return n(w(t,(e=r,S(function(n){return A(n)&&Boolean(n.match(e))}))));var e}})}(S(A)),T=function n(t){return Object.assign(g(t),{between:function(r,e){return n(w(t,function(n,t){return S(function(r){return x(r)&&n<=r&&t>=r})}(r,e)))},lt:function(r){return n(w(t,function(n){return S(function(t){return x(t)&&tn})}(r)))},lte:function(r){return n(w(t,function(n){return S(function(t){return x(t)&&t<=n})}(r)))},gte:function(r){return n(w(t,function(n){return S(function(t){return x(t)&&t>=n})}(r)))},int:function(){return n(w(t,S(function(n){return x(n)&&Number.isInteger(n)})))},finite:function(){return n(w(t,S(function(n){return x(n)&&Number.isFinite(n)})))},positive:function(){return n(w(t,S(function(n){return x(n)&&n>0})))},negative:function(){return n(w(t,S(function(n){return x(n)&&n<0})))}})}(S(x)),B=function n(t){return Object.assign(g(t),{between:function(r,e){return n(w(t,function(n,t){return S(function(r){return E(r)&&n<=r&&t>=r})}(r,e)))},lt:function(r){return n(w(t,function(n){return S(function(t){return E(t)&&tn})}(r)))},lte:function(r){return n(w(t,function(n){return S(function(t){return E(t)&&t<=n})}(r)))},gte:function(r){return n(w(t,function(n){return S(function(t){return E(t)&&t>=n})}(r)))},positive:function(){return n(w(t,S(function(n){return E(n)&&n>0})))},negative:function(){return n(w(t,S(function(n){return E(n)&&n<0})))}})}(S(E)),M=g(S(function(n){return"boolean"==typeof n})),R=g(S(function(n){return"symbol"==typeof n})),I=g(S(function(n){return null==n})),N=g(S(function(n){return null!=n})),k={__proto__:null,matcher:o,optional:m,array:function(){var n,t=[].slice.call(arguments);return y(((n={})[o]=function(){return{match:function(n){if(!Array.isArray(n))return{matched:!1};if(0===t.length)return{matched:!0};var r=t[0],e={};if(0===n.length)return h(r).forEach(function(n){e[n]=[]}),{matched:!0,selections:e};var u=function(n,t){e[n]=(e[n]||[]).concat([t])};return{matched:n.every(function(n){return s(r,n,u)}),selections:e}},getSelectionKeys:function(){return 0===t.length?[]:h(t[0])}}},n))},set:function(){var n,t=[].slice.call(arguments);return g(((n={})[o]=function(){return{match:function(n){if(!(n instanceof Set))return{matched:!1};var r={};if(0===n.size)return{matched:!0,selections:r};if(0===t.length)return{matched:!0};var e=function(n,t){r[n]=(r[n]||[]).concat([t])},u=t[0];return{matched:d(n,function(n){return s(u,n,e)}),selections:r}},getSelectionKeys:function(){return 0===t.length?[]:h(t[0])}}},n))},map:function(){var n,t=[].slice.call(arguments);return g(((n={})[o]=function(){return{match:function(n){if(!(n instanceof Map))return{matched:!1};var r={};if(0===n.size)return{matched:!0,selections:r};var e,u=function(n,t){r[n]=(r[n]||[]).concat([t])};if(0===t.length)return{matched:!0};if(1===t.length)throw new Error("`P.map` wasn't given enough arguments. Expected (key, value), received "+(null==(e=t[0])?void 0:e.toString()));var i=t[0],o=t[1];return{matched:b(n,function(n,t){var r=s(i,t,u),e=s(o,n,u);return r&&e}),selections:r}},getSelectionKeys:function(){return 0===t.length?[]:[].concat(h(t[0]),h(t[1]))}}},n))},intersection:w,union:O,not:function(n){var t;return g(((t={})[o]=function(){return{match:function(t){return{matched:!s(n,t,function(){})}},getSelectionKeys:function(){return[]},matcherType:"not"}},t))},when:S,select:j,any:_,_:P,string:K,number:T,bigint:B,boolean:M,symbol:R,nullish:I,nonNullable:N,instanceOf:function(n){return g(S(function(n){return function(t){return t instanceof n}}(n)))},shape:function(n){return g(S(p(n)))}},W=/*#__PURE__*/function(n){var r,e;function u(t){var r,e;try{e=JSON.stringify(t)}catch(n){e=t}return(r=n.call(this,"Pattern matching error: no pattern matches value "+e)||this).input=void 0,r.input=t,r}return e=n,(r=u).prototype=Object.create(e.prototype),r.prototype.constructor=r,t(r,e),u}(/*#__PURE__*/e(Error)),F={matched:!1,value:void 0},z=/*#__PURE__*/function(){function n(n,t){this.input=void 0,this.state=void 0,this.input=n,this.state=t}var t=n.prototype;return t.with=function(){var t=this,r=[].slice.call(arguments);if(this.state.matched)return this;var e=r[r.length-1],u=[r[0]],i=void 0;3===r.length&&"function"==typeof r[1]?i=r[1]:r.length>2&&u.push.apply(u,r.slice(1,r.length-1));var o=!1,c={},a=function(n,t){o=!0,c[n]=t},l=!u.some(function(n){return s(n,t.input,a)})||i&&!Boolean(i(this.input))?F:{matched:!0,value:e(o?f in c?c[f]:c:this.input,this.input)};return new n(this.input,l)},t.when=function(t,r){if(this.state.matched)return this;var e=Boolean(t(this.input));return new n(this.input,e?{matched:!0,value:r(this.input,this.input)}:F)},t.otherwise=function(n){return this.state.matched?this.state.value:n(this.input)},t.exhaustive=function(){if(this.state.matched)return this.state.value;throw new W(this.input)},t.run=function(){return this.exhaustive()},t.returnType=function(){return this},n}();exports.NonExhaustiveError=W,exports.P=k,exports.Pattern=k,exports.isMatching=p,exports.match=function(n){return new z(n,F)}; //# sourceMappingURL=index.cjs.map