Socket
Socket
Sign inDemoInstall

ts-pattern

Package Overview
Dependencies
Maintainers
1
Versions
151
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-pattern - npm Package Compare versions

Comparing version 5.0.4 to 5.0.5

2

dist/index.js

@@ -1,2 +0,2 @@

const t=Symbol.for("@ts-pattern/matcher"),e=Symbol.for("@ts-pattern/isVariadic"),n="@ts-pattern/anonymous-select-key",r=t=>Boolean(t&&"object"==typeof t),i=e=>e&&!!e[t],s=(n,o,c)=>{if(i(n)){const e=n[t](),{matched:r,selections:i}=e.match(o);return r&&i&&Object.keys(i).forEach(t=>c(t,i[t])),r}if(r(n)){if(!r(o))return!1;if(Array.isArray(n)){if(!Array.isArray(o))return!1;let t=[],r=[],a=[];for(const s of n.keys()){const o=n[s];i(o)&&o[e]?a.push(o):a.length?r.push(o):t.push(o)}if(a.length){if(a.length>1)throw new Error("Pattern error: Using `...P.array(...)` several times in a single pattern is not allowed.");if(o.length<t.length+r.length)return!1;const e=o.slice(0,t.length),n=0===r.length?[]:o.slice(-r.length),i=o.slice(t.length,0===r.length?Infinity:-r.length);return t.every((t,n)=>s(t,e[n],c))&&r.every((t,e)=>s(t,n[e],c))&&(0===a.length||s(a[0],i,c))}return n.length===o.length&&n.every((t,e)=>s(t,o[e],c))}return Object.keys(n).every(e=>{const r=n[e];return(e in o||i(a=r)&&"optional"===a[t]().matcherType)&&s(r,o[e],c);var a})}return Object.is(o,n)},o=e=>{var n,s,a;return r(e)?i(e)?null!=(n=null==(s=(a=e[t]()).getSelectionKeys)?void 0:s.call(a))?n:[]:Array.isArray(e)?c(e,o):c(Object.values(e),o):[]},c=(t,e)=>t.reduce((t,n)=>t.concat(e(n)),[]);function a(...t){if(1===t.length){const[e]=t;return t=>s(e,t,()=>{})}if(2===t.length){const[e,n]=t;return s(e,n,()=>{})}throw new Error(`isMatching wasn't given the right number of arguments: expected 1 or 2, received ${t.length}.`)}function u(t){return Object.assign(t,{optional:()=>l(t),and:e=>m(t,e),or:e=>p(t,e),select:e=>void 0===e?d(t):d(e,t)})}function h(t){return Object.assign((t=>Object.assign(t,{*[Symbol.iterator](){yield Object.assign(t,{[e]:!0})}}))(t),{optional:()=>h(l(t)),select:e=>h(void 0===e?d(t):d(e,t))})}function l(e){return u({[t]:()=>({match:t=>{let n={};const r=(t,e)=>{n[t]=e};return void 0===t?(o(e).forEach(t=>r(t,void 0)),{matched:!0,selections:n}):{matched:s(e,t,r),selections:n}},getSelectionKeys:()=>o(e),matcherType:"optional"})})}const g=(t,e)=>{for(const n of t)if(!e(n))return!1;return!0},f=(t,e)=>{for(const[n,r]of t.entries())if(!e(r,n))return!1;return!0};function m(...e){return u({[t]:()=>({match:t=>{let n={};const r=(t,e)=>{n[t]=e};return{matched:e.every(e=>s(e,t,r)),selections:n}},getSelectionKeys:()=>c(e,o),matcherType:"and"})})}function p(...e){return u({[t]:()=>({match:t=>{let n={};const r=(t,e)=>{n[t]=e};return c(e,o).forEach(t=>r(t,void 0)),{matched:e.some(e=>s(e,t,r)),selections:n}},getSelectionKeys:()=>c(e,o),matcherType:"or"})})}function y(e){return{[t]:()=>({match:t=>({matched:Boolean(e(t))})})}}function d(...e){const r="string"==typeof e[0]?e[0]:void 0,i=2===e.length?e[1]:"string"==typeof e[0]?void 0:e[0];return u({[t]:()=>({match:t=>{let e={[null!=r?r:n]:t};return{matched:void 0===i||s(i,t,(t,n)=>{e[t]=n}),selections:e}},getSelectionKeys:()=>[null!=r?r:n].concat(void 0===i?[]:o(i))})})}function v(t){return"number"==typeof t}function b(t){return"string"==typeof t}function w(t){return"bigint"==typeof t}const S=u(y(function(t){return!0})),O=S,j=t=>Object.assign(u(t),{startsWith:e=>{return j(m(t,(n=e,y(t=>b(t)&&t.startsWith(n)))));var n},endsWith:e=>{return j(m(t,(n=e,y(t=>b(t)&&t.endsWith(n)))));var n},minLength:e=>j(m(t,(t=>y(e=>b(e)&&e.length>=t))(e))),maxLength:e=>j(m(t,(t=>y(e=>b(e)&&e.length<=t))(e))),includes:e=>{return j(m(t,(n=e,y(t=>b(t)&&t.includes(n)))));var n},regex:e=>{return j(m(t,(n=e,y(t=>b(t)&&Boolean(t.match(n))))));var n}}),B=j(y(b)),E=(t,e)=>y(n=>v(n)&&t<=n&&e>=n),I=t=>y(e=>v(e)&&e<t),K=t=>y(e=>v(e)&&e>t),A=t=>y(e=>v(e)&&e<=t),x=t=>y(e=>v(e)&&e>=t),P=()=>y(t=>v(t)&&Number.isInteger(t)),T=()=>y(t=>v(t)&&Number.isFinite(t)),k=()=>y(t=>v(t)&&t>0),_=()=>y(t=>v(t)&&t<0),W=t=>Object.assign(u(t),{between:(e,n)=>W(m(t,E(e,n))),lt:e=>W(m(t,I(e))),gt:e=>W(m(t,K(e))),lte:e=>W(m(t,A(e))),gte:e=>W(m(t,x(e))),int:()=>W(m(t,P())),finite:()=>W(m(t,T())),positive:()=>W(m(t,k())),negative:()=>W(m(t,_()))}),N=W(y(v)),$=(t,e)=>y(n=>w(n)&&t<=n&&e>=n),z=t=>y(e=>w(e)&&e<t),L=t=>y(e=>w(e)&&e>t),M=t=>y(e=>w(e)&&e<=t),F=t=>y(e=>w(e)&&e>=t),J=()=>y(t=>w(t)&&t>0),U=()=>y(t=>w(t)&&t<0),V=t=>Object.assign(u(t),{between:(e,n)=>V(m(t,$(e,n))),lt:e=>V(m(t,z(e))),gt:e=>V(m(t,L(e))),lte:e=>V(m(t,M(e))),gte:e=>V(m(t,F(e))),positive:()=>V(m(t,J())),negative:()=>V(m(t,U()))}),q=V(y(w)),C=u(y(function(t){return"boolean"==typeof t})),D=u(y(function(t){return"symbol"==typeof t})),G=u(y(function(t){return null==t}));var H={__proto__:null,matcher:t,optional:l,array:function(...e){return h({[t]:()=>({match:t=>{if(!Array.isArray(t))return{matched:!1};if(0===e.length)return{matched:!0};const n=e[0];let r={};if(0===t.length)return o(n).forEach(t=>{r[t]=[]}),{matched:!0,selections:r};const i=(t,e)=>{r[t]=(r[t]||[]).concat([e])};return{matched:t.every(t=>s(n,t,i)),selections:r}},getSelectionKeys:()=>0===e.length?[]:o(e[0])})})},set:function(...e){return u({[t]:()=>({match:t=>{if(!(t instanceof Set))return{matched:!1};let n={};if(0===t.size)return{matched:!0,selections:n};if(0===e.length)return{matched:!0};const r=(t,e)=>{n[t]=(n[t]||[]).concat([e])},i=e[0];return{matched:g(t,t=>s(i,t,r)),selections:n}},getSelectionKeys:()=>0===e.length?[]:o(e[0])})})},map:function(...e){return u({[t]:()=>({match:t=>{if(!(t instanceof Map))return{matched:!1};let n={};if(0===t.size)return{matched:!0,selections:n};const r=(t,e)=>{n[t]=(n[t]||[]).concat([e])};if(0===e.length)return{matched:!0};var i;if(1===e.length)throw new Error(`\`P.map\` wasn't given enough arguments. Expected (key, value), received ${null==(i=e[0])?void 0:i.toString()}`);const[o,c]=e;return{matched:f(t,(t,e)=>{const n=s(o,e,r),i=s(c,t,r);return n&&i}),selections:n}},getSelectionKeys:()=>0===e.length?[]:[...o(e[0]),...o(e[1])]})})},intersection:m,union:p,not:function(e){return u({[t]:()=>({match:t=>({matched:!s(e,t,()=>{})}),getSelectionKeys:()=>[],matcherType:"not"})})},when:y,select:d,any:S,_:O,string:B,between:E,lt:I,gt:K,lte:A,gte:x,int:P,finite:T,positive:k,negative:_,number:N,betweenBigInt:$,ltBigInt:z,gtBigInt:L,lteBigInt:M,gteBigInt:F,positiveBigInt:J,negativeBigInt:U,bigint:q,boolean:C,symbol:D,nullish:G,instanceOf:function(t){return u(y(function(t){return e=>e instanceof t}(t)))},shape:function(t){return u(y(a(t)))}};const Q={matched:!1,value:void 0};function R(t){return new X(t,Q)}class X{constructor(t,e){this.input=void 0,this.state=void 0,this.input=t,this.state=e}with(...t){if(this.state.matched)return this;const e=t[t.length-1],r=[t[0]];let i;3===t.length&&"function"==typeof t[1]?(r.push(t[0]),i=t[1]):t.length>2&&r.push(...t.slice(1,t.length-1));let o=!1,c={};const a=(t,e)=>{o=!0,c[t]=e},u=!r.some(t=>s(t,this.input,a))||i&&!Boolean(i(this.input))?Q:{matched:!0,value:e(o?n in c?c[n]:c:this.input,this.input)};return new X(this.input,u)}when(t,e){if(this.state.matched)return this;const n=Boolean(t(this.input));return new X(this.input,n?{matched:!0,value:e(this.input,this.input)}:Q)}otherwise(t){return this.state.matched?this.state.value:t(this.input)}exhaustive(){return this.run()}run(){if(this.state.matched)return this.state.value;let t;try{t=JSON.stringify(this.input)}catch(e){t=this.input}throw new Error(`Pattern matching error: no pattern matches value ${t}`)}returnType(){return this}}export{H as P,H as Pattern,a as isMatching,R as match};
const t=Symbol.for("@ts-pattern/matcher"),e=Symbol.for("@ts-pattern/isVariadic"),n="@ts-pattern/anonymous-select-key",r=t=>Boolean(t&&"object"==typeof t),i=e=>e&&!!e[t],s=(n,o,c)=>{if(i(n)){const e=n[t](),{matched:r,selections:i}=e.match(o);return r&&i&&Object.keys(i).forEach(t=>c(t,i[t])),r}if(r(n)){if(!r(o))return!1;if(Array.isArray(n)){if(!Array.isArray(o))return!1;let t=[],r=[],a=[];for(const s of n.keys()){const o=n[s];i(o)&&o[e]?a.push(o):a.length?r.push(o):t.push(o)}if(a.length){if(a.length>1)throw new Error("Pattern error: Using `...P.array(...)` several times in a single pattern is not allowed.");if(o.length<t.length+r.length)return!1;const e=o.slice(0,t.length),n=0===r.length?[]:o.slice(-r.length),i=o.slice(t.length,0===r.length?Infinity:-r.length);return t.every((t,n)=>s(t,e[n],c))&&r.every((t,e)=>s(t,n[e],c))&&(0===a.length||s(a[0],i,c))}return n.length===o.length&&n.every((t,e)=>s(t,o[e],c))}return Object.keys(n).every(e=>{const r=n[e];return(e in o||i(a=r)&&"optional"===a[t]().matcherType)&&s(r,o[e],c);var a})}return Object.is(o,n)},o=e=>{var n,s,a;return r(e)?i(e)?null!=(n=null==(s=(a=e[t]()).getSelectionKeys)?void 0:s.call(a))?n:[]:Array.isArray(e)?c(e,o):c(Object.values(e),o):[]},c=(t,e)=>t.reduce((t,n)=>t.concat(e(n)),[]);function a(...t){if(1===t.length){const[e]=t;return t=>s(e,t,()=>{})}if(2===t.length){const[e,n]=t;return s(e,n,()=>{})}throw new Error(`isMatching wasn't given the right number of arguments: expected 1 or 2, received ${t.length}.`)}function u(t){return Object.assign(t,{optional:()=>l(t),and:e=>m(t,e),or:e=>y(t,e),select:e=>void 0===e?p(t):p(e,t)})}function h(t){return Object.assign((t=>Object.assign(t,{*[Symbol.iterator](){yield Object.assign(t,{[e]:!0})}}))(t),{optional:()=>h(l(t)),select:e=>h(void 0===e?p(t):p(e,t))})}function l(e){return u({[t]:()=>({match:t=>{let n={};const r=(t,e)=>{n[t]=e};return void 0===t?(o(e).forEach(t=>r(t,void 0)),{matched:!0,selections:n}):{matched:s(e,t,r),selections:n}},getSelectionKeys:()=>o(e),matcherType:"optional"})})}const f=(t,e)=>{for(const n of t)if(!e(n))return!1;return!0},g=(t,e)=>{for(const[n,r]of t.entries())if(!e(r,n))return!1;return!0};function m(...e){return u({[t]:()=>({match:t=>{let n={};const r=(t,e)=>{n[t]=e};return{matched:e.every(e=>s(e,t,r)),selections:n}},getSelectionKeys:()=>c(e,o),matcherType:"and"})})}function y(...e){return u({[t]:()=>({match:t=>{let n={};const r=(t,e)=>{n[t]=e};return c(e,o).forEach(t=>r(t,void 0)),{matched:e.some(e=>s(e,t,r)),selections:n}},getSelectionKeys:()=>c(e,o),matcherType:"or"})})}function d(e){return{[t]:()=>({match:t=>({matched:Boolean(e(t))})})}}function p(...e){const r="string"==typeof e[0]?e[0]:void 0,i=2===e.length?e[1]:"string"==typeof e[0]?void 0:e[0];return u({[t]:()=>({match:t=>{let e={[null!=r?r:n]:t};return{matched:void 0===i||s(i,t,(t,n)=>{e[t]=n}),selections:e}},getSelectionKeys:()=>[null!=r?r:n].concat(void 0===i?[]:o(i))})})}function v(t){return"number"==typeof t}function b(t){return"string"==typeof t}function w(t){return"bigint"==typeof t}const S=u(d(function(t){return!0})),O=S,j=t=>Object.assign(u(t),{startsWith:e=>{return j(m(t,(n=e,d(t=>b(t)&&t.startsWith(n)))));var n},endsWith:e=>{return j(m(t,(n=e,d(t=>b(t)&&t.endsWith(n)))));var n},minLength:e=>j(m(t,(t=>d(e=>b(e)&&e.length>=t))(e))),maxLength:e=>j(m(t,(t=>d(e=>b(e)&&e.length<=t))(e))),includes:e=>{return j(m(t,(n=e,d(t=>b(t)&&t.includes(n)))));var n},regex:e=>{return j(m(t,(n=e,d(t=>b(t)&&Boolean(t.match(n))))));var n}}),E=j(d(b)),K=t=>Object.assign(u(t),{between:(e,n)=>K(m(t,((t,e)=>d(n=>v(n)&&t<=n&&e>=n))(e,n))),lt:e=>K(m(t,(t=>d(e=>v(e)&&e<t))(e))),gt:e=>K(m(t,(t=>d(e=>v(e)&&e>t))(e))),lte:e=>K(m(t,(t=>d(e=>v(e)&&e<=t))(e))),gte:e=>K(m(t,(t=>d(e=>v(e)&&e>=t))(e))),int:()=>K(m(t,d(t=>v(t)&&Number.isInteger(t)))),finite:()=>K(m(t,d(t=>v(t)&&Number.isFinite(t)))),positive:()=>K(m(t,d(t=>v(t)&&t>0))),negative:()=>K(m(t,d(t=>v(t)&&t<0)))}),A=K(d(v)),x=t=>Object.assign(u(t),{between:(e,n)=>x(m(t,((t,e)=>d(n=>w(n)&&t<=n&&e>=n))(e,n))),lt:e=>x(m(t,(t=>d(e=>w(e)&&e<t))(e))),gt:e=>x(m(t,(t=>d(e=>w(e)&&e>t))(e))),lte:e=>x(m(t,(t=>d(e=>w(e)&&e<=t))(e))),gte:e=>x(m(t,(t=>d(e=>w(e)&&e>=t))(e))),positive:()=>x(m(t,d(t=>w(t)&&t>0))),negative:()=>x(m(t,d(t=>w(t)&&t<0)))}),P=x(d(w)),T=u(d(function(t){return"boolean"==typeof t})),k=u(d(function(t){return"symbol"==typeof t})),B=u(d(function(t){return null==t}));var _={__proto__:null,matcher:t,optional:l,array:function(...e){return h({[t]:()=>({match:t=>{if(!Array.isArray(t))return{matched:!1};if(0===e.length)return{matched:!0};const n=e[0];let r={};if(0===t.length)return o(n).forEach(t=>{r[t]=[]}),{matched:!0,selections:r};const i=(t,e)=>{r[t]=(r[t]||[]).concat([e])};return{matched:t.every(t=>s(n,t,i)),selections:r}},getSelectionKeys:()=>0===e.length?[]:o(e[0])})})},set:function(...e){return u({[t]:()=>({match:t=>{if(!(t instanceof Set))return{matched:!1};let n={};if(0===t.size)return{matched:!0,selections:n};if(0===e.length)return{matched:!0};const r=(t,e)=>{n[t]=(n[t]||[]).concat([e])},i=e[0];return{matched:f(t,t=>s(i,t,r)),selections:n}},getSelectionKeys:()=>0===e.length?[]:o(e[0])})})},map:function(...e){return u({[t]:()=>({match:t=>{if(!(t instanceof Map))return{matched:!1};let n={};if(0===t.size)return{matched:!0,selections:n};const r=(t,e)=>{n[t]=(n[t]||[]).concat([e])};if(0===e.length)return{matched:!0};var i;if(1===e.length)throw new Error(`\`P.map\` wasn't given enough arguments. Expected (key, value), received ${null==(i=e[0])?void 0:i.toString()}`);const[o,c]=e;return{matched:g(t,(t,e)=>{const n=s(o,e,r),i=s(c,t,r);return n&&i}),selections:n}},getSelectionKeys:()=>0===e.length?[]:[...o(e[0]),...o(e[1])]})})},intersection:m,union:y,not:function(e){return u({[t]:()=>({match:t=>({matched:!s(e,t,()=>{})}),getSelectionKeys:()=>[],matcherType:"not"})})},when:d,select:p,any:S,_:O,string:E,number:A,bigint:P,boolean:T,symbol:k,nullish:B,instanceOf:function(t){return u(d(function(t){return e=>e instanceof t}(t)))},shape:function(t){return u(d(a(t)))}};const W={matched:!1,value:void 0};function N(t){return new $(t,W)}class ${constructor(t,e){this.input=void 0,this.state=void 0,this.input=t,this.state=e}with(...t){if(this.state.matched)return this;const e=t[t.length-1],r=[t[0]];let i;3===t.length&&"function"==typeof t[1]?(r.push(t[0]),i=t[1]):t.length>2&&r.push(...t.slice(1,t.length-1));let o=!1,c={};const a=(t,e)=>{o=!0,c[t]=e},u=!r.some(t=>s(t,this.input,a))||i&&!Boolean(i(this.input))?W:{matched:!0,value:e(o?n in c?c[n]:c:this.input,this.input)};return new $(this.input,u)}when(t,e){if(this.state.matched)return this;const n=Boolean(t(this.input));return new $(this.input,n?{matched:!0,value:e(this.input,this.input)}:W)}otherwise(t){return this.state.matched?this.state.value:t(this.input)}exhaustive(){return this.run()}run(){if(this.state.matched)return this.state.value;let t;try{t=JSON.stringify(this.input)}catch(e){t=this.input}throw new Error(`Pattern matching error: no pattern matches value ${t}`)}returnType(){return this}}export{_ as P,_ as Pattern,a as isMatching,N as match};
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n||self).tsPattern={})}(this,function(n){function t(n,t){(null==t||t>n.length)&&(t=n.length);for(var e=0,r=new Array(t);e<t;e++)r[e]=n[e];return r}function e(n,e){var r="undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(r)return(r=r.call(n)).next.bind(r);if(Array.isArray(n)||(r=function(n,e){if(n){if("string"==typeof n)return t(n,e);var r=Object.prototype.toString.call(n).slice(8,-1);return"Object"===r&&n.constructor&&(r=n.constructor.name),"Map"===r||"Set"===r?Array.from(n):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?t(n,e):void 0}}(n))||e&&n&&"number"==typeof n.length){r&&(n=r);var u=0;return function(){return u>=n.length?{done:!0}:{done:!1,value:n[u++]}}}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 r=Symbol.for("@ts-pattern/matcher"),u=Symbol.for("@ts-pattern/isVariadic"),i="@ts-pattern/anonymous-select-key",o=function(n){return Boolean(n&&"object"==typeof n)},c=function(n){return n&&!!n[r]},f=function n(t,i,f){if(c(t)){var a=t[r]().match(i),s=a.matched,l=a.selections;return s&&l&&Object.keys(l).forEach(function(n){return f(n,l[n])}),s}if(o(t)){if(!o(i))return!1;if(Array.isArray(t)){if(!Array.isArray(i))return!1;for(var h,g=[],v=[],m=[],d=e(t.keys());!(h=d()).done;){var p=t[h.value];c(p)&&p[u]?m.push(p):m.length?v.push(p):g.push(p)}if(m.length){if(m.length>1)throw new Error("Pattern error: Using `...P.array(...)` several times in a single pattern is not allowed.");if(i.length<g.length+v.length)return!1;var y=i.slice(0,g.length),b=0===v.length?[]:i.slice(-v.length),w=i.slice(g.length,0===v.length?Infinity:-v.length);return g.every(function(t,e){return n(t,y[e],f)})&&v.every(function(t,e){return n(t,b[e],f)})&&(0===m.length||n(m[0],w,f))}return t.length===i.length&&t.every(function(t,e){return n(t,i[e],f)})}return Object.keys(t).every(function(e){var u,o=t[e];return(e in i||c(u=o)&&"optional"===u[r]().matcherType)&&n(o,i[e],f)})}return Object.is(i,t)},a=function n(t){var e,u,i;return o(t)?c(t)?null!=(e=null==(u=(i=t[r]()).getSelectionKeys)?void 0:u.call(i))?e:[]:Array.isArray(t)?s(t,n):s(Object.values(t),n):[]},s=function(n,t){return n.reduce(function(n,e){return n.concat(t(e))},[])};function l(){var n=[].slice.call(arguments);if(1===n.length){var t=n[0];return function(n){return f(t,n,function(){})}}if(2===n.length)return f(n[0],n[1],function(){});throw new Error("isMatching wasn't given the right number of arguments: expected 1 or 2, received "+n.length+".")}function h(n){return Object.assign(n,{optional:function(){return v(n)},and:function(t){return p(n,t)},or:function(t){return y(n,t)},select:function(t){return void 0===t?w(n):w(t,n)}})}function g(n){return Object.assign(function(n){var t;return Object.assign(n,((t={})[Symbol.iterator]=function(){/*#__PURE__*/return regeneratorRuntime.mark(function t(){var e;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,Object.assign(n,((e={})[u]=!0,e));case 2:case"end":return t.stop()}},t)})()},t))}(n),{optional:function(){return g(v(n))},select:function(t){return g(void 0===t?w(n):w(t,n))}})}function v(n){var t;return h(((t={})[r]=function(){return{match:function(t){var e={},r=function(n,t){e[n]=t};return void 0===t?(a(n).forEach(function(n){return r(n,void 0)}),{matched:!0,selections:e}):{matched:f(n,t,r),selections:e}},getSelectionKeys:function(){return a(n)},matcherType:"optional"}},t))}var m=function(n,t){for(var r,u=e(n);!(r=u()).done;)if(!t(r.value))return!1;return!0},d=function(n,t){for(var r,u=e(n.entries());!(r=u()).done;){var i=r.value;if(!t(i[1],i[0]))return!1}return!0};function p(){var n,t=[].slice.call(arguments);return h(((n={})[r]=function(){return{match:function(n){var e={},r=function(n,t){e[n]=t};return{matched:t.every(function(t){return f(t,n,r)}),selections:e}},getSelectionKeys:function(){return s(t,a)},matcherType:"and"}},n))}function y(){var n,t=[].slice.call(arguments);return h(((n={})[r]=function(){return{match:function(n){var e={},r=function(n,t){e[n]=t};return s(t,a).forEach(function(n){return r(n,void 0)}),{matched:t.some(function(t){return f(t,n,r)}),selections:e}},getSelectionKeys:function(){return s(t,a)},matcherType:"or"}},n))}function b(n){var t;return(t={})[r]=function(){return{match:function(t){return{matched:Boolean(n(t))}}}},t}function w(){var n,t=[].slice.call(arguments),e="string"==typeof t[0]?t[0]:void 0,u=2===t.length?t[1]:"string"==typeof t[0]?void 0:t[0];return h(((n={})[r]=function(){return{match:function(n){var t,r=((t={})[null!=e?e:i]=n,t);return{matched:void 0===u||f(u,n,function(n,t){r[n]=t}),selections:r}},getSelectionKeys:function(){return[null!=e?e:i].concat(void 0===u?[]:a(u))}}},n))}function S(n){return"number"==typeof n}function j(n){return"string"==typeof n}function O(n){return"bigint"==typeof n}var A=h(b(function(n){return!0})),B=A,I=function n(t){return Object.assign(h(t),{startsWith:function(e){return n(p(t,(r=e,b(function(n){return j(n)&&n.startsWith(r)}))));var r},endsWith:function(e){return n(p(t,(r=e,b(function(n){return j(n)&&n.endsWith(r)}))));var r},minLength:function(e){return n(p(t,function(n){return b(function(t){return j(t)&&t.length>=n})}(e)))},maxLength:function(e){return n(p(t,function(n){return b(function(t){return j(t)&&t.length<=n})}(e)))},includes:function(e){return n(p(t,(r=e,b(function(n){return j(n)&&n.includes(r)}))));var r},regex:function(e){return n(p(t,(r=e,b(function(n){return j(n)&&Boolean(n.match(r))}))));var r}})}(b(j)),x=function(n,t){return b(function(e){return S(e)&&n<=e&&t>=e})},E=function(n){return b(function(t){return S(t)&&t<n})},K=function(n){return b(function(t){return S(t)&&t>n})},T=function(n){return b(function(t){return S(t)&&t<=n})},P=function(n){return b(function(t){return S(t)&&t>=n})},k=function(){return b(function(n){return S(n)&&Number.isInteger(n)})},_=function(){return b(function(n){return S(n)&&Number.isFinite(n)})},M=function(){return b(function(n){return S(n)&&n>0})},W=function(){return b(function(n){return S(n)&&n<0})},N=function n(t){return Object.assign(h(t),{between:function(e,r){return n(p(t,x(e,r)))},lt:function(e){return n(p(t,E(e)))},gt:function(e){return n(p(t,K(e)))},lte:function(e){return n(p(t,T(e)))},gte:function(e){return n(p(t,P(e)))},int:function(){return n(p(t,k()))},finite:function(){return n(p(t,_()))},positive:function(){return n(p(t,M()))},negative:function(){return n(p(t,W()))}})}(b(S)),z=function(n,t){return b(function(e){return O(e)&&n<=e&&t>=e})},L=function(n){return b(function(t){return O(t)&&t<n})},R=function(n){return b(function(t){return O(t)&&t>n})},U=function(n){return b(function(t){return O(t)&&t<=n})},C=function(n){return b(function(t){return O(t)&&t>=n})},F=function(){return b(function(n){return O(n)&&n>0})},J=function(){return b(function(n){return O(n)&&n<0})},V=function n(t){return Object.assign(h(t),{between:function(e,r){return n(p(t,z(e,r)))},lt:function(e){return n(p(t,L(e)))},gt:function(e){return n(p(t,R(e)))},lte:function(e){return n(p(t,U(e)))},gte:function(e){return n(p(t,C(e)))},positive:function(){return n(p(t,F()))},negative:function(){return n(p(t,J()))}})}(b(O)),$=h(b(function(n){return"boolean"==typeof n})),q=h(b(function(n){return"symbol"==typeof n})),D=h(b(function(n){return null==n})),G={__proto__:null,matcher:r,optional:v,array:function(){var n,t=[].slice.call(arguments);return g(((n={})[r]=function(){return{match:function(n){if(!Array.isArray(n))return{matched:!1};if(0===t.length)return{matched:!0};var e=t[0],r={};if(0===n.length)return a(e).forEach(function(n){r[n]=[]}),{matched:!0,selections:r};var u=function(n,t){r[n]=(r[n]||[]).concat([t])};return{matched:n.every(function(n){return f(e,n,u)}),selections:r}},getSelectionKeys:function(){return 0===t.length?[]:a(t[0])}}},n))},set:function(){var n,t=[].slice.call(arguments);return h(((n={})[r]=function(){return{match:function(n){if(!(n instanceof Set))return{matched:!1};var e={};if(0===n.size)return{matched:!0,selections:e};if(0===t.length)return{matched:!0};var r=function(n,t){e[n]=(e[n]||[]).concat([t])},u=t[0];return{matched:m(n,function(n){return f(u,n,r)}),selections:e}},getSelectionKeys:function(){return 0===t.length?[]:a(t[0])}}},n))},map:function(){var n,t=[].slice.call(arguments);return h(((n={})[r]=function(){return{match:function(n){if(!(n instanceof Map))return{matched:!1};var e={};if(0===n.size)return{matched:!0,selections:e};var r,u=function(n,t){e[n]=(e[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==(r=t[0])?void 0:r.toString()));var i=t[0],o=t[1];return{matched:d(n,function(n,t){var e=f(i,t,u),r=f(o,n,u);return e&&r}),selections:e}},getSelectionKeys:function(){return 0===t.length?[]:[].concat(a(t[0]),a(t[1]))}}},n))},intersection:p,union:y,not:function(n){var t;return h(((t={})[r]=function(){return{match:function(t){return{matched:!f(n,t,function(){})}},getSelectionKeys:function(){return[]},matcherType:"not"}},t))},when:b,select:w,any:A,_:B,string:I,between:x,lt:E,gt:K,lte:T,gte:P,int:k,finite:_,positive:M,negative:W,number:N,betweenBigInt:z,ltBigInt:L,gtBigInt:R,lteBigInt:U,gteBigInt:C,positiveBigInt:F,negativeBigInt:J,bigint:V,boolean:$,symbol:q,nullish:D,instanceOf:function(n){return h(b(function(n){return function(t){return t instanceof n}}(n)))},shape:function(n){return h(b(l(n)))}},H={matched:!1,value:void 0},Q=/*#__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,e=[].slice.call(arguments);if(this.state.matched)return this;var r=e[e.length-1],u=[e[0]],o=void 0;3===e.length&&"function"==typeof e[1]?(u.push(e[0]),o=e[1]):e.length>2&&u.push.apply(u,e.slice(1,e.length-1));var c=!1,a={},s=function(n,t){c=!0,a[n]=t},l=!u.some(function(n){return f(n,t.input,s)})||o&&!Boolean(o(this.input))?H:{matched:!0,value:r(c?i in a?a[i]:a:this.input,this.input)};return new n(this.input,l)},t.when=function(t,e){if(this.state.matched)return this;var r=Boolean(t(this.input));return new n(this.input,r?{matched:!0,value:e(this.input,this.input)}:H)},t.otherwise=function(n){return this.state.matched?this.state.value:n(this.input)},t.exhaustive=function(){return this.run()},t.run=function(){if(this.state.matched)return this.state.value;var n;try{n=JSON.stringify(this.input)}catch(t){n=this.input}throw new Error("Pattern matching error: no pattern matches value "+n)},t.returnType=function(){return this},n}();n.P=G,n.Pattern=G,n.isMatching=l,n.match=function(n){return new Q(n,H)}});
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n||self).tsPattern={})}(this,function(n){function t(n,t){(null==t||t>n.length)&&(t=n.length);for(var e=0,r=new Array(t);e<t;e++)r[e]=n[e];return r}function e(n,e){var r="undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(r)return(r=r.call(n)).next.bind(r);if(Array.isArray(n)||(r=function(n,e){if(n){if("string"==typeof n)return t(n,e);var r=Object.prototype.toString.call(n).slice(8,-1);return"Object"===r&&n.constructor&&(r=n.constructor.name),"Map"===r||"Set"===r?Array.from(n):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?t(n,e):void 0}}(n))||e&&n&&"number"==typeof n.length){r&&(n=r);var u=0;return function(){return u>=n.length?{done:!0}:{done:!1,value:n[u++]}}}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 r=Symbol.for("@ts-pattern/matcher"),u=Symbol.for("@ts-pattern/isVariadic"),i="@ts-pattern/anonymous-select-key",o=function(n){return Boolean(n&&"object"==typeof n)},c=function(n){return n&&!!n[r]},a=function n(t,i,a){if(c(t)){var f=t[r]().match(i),s=f.matched,l=f.selections;return s&&l&&Object.keys(l).forEach(function(n){return a(n,l[n])}),s}if(o(t)){if(!o(i))return!1;if(Array.isArray(t)){if(!Array.isArray(i))return!1;for(var h,v=[],g=[],m=[],d=e(t.keys());!(h=d()).done;){var p=t[h.value];c(p)&&p[u]?m.push(p):m.length?g.push(p):v.push(p)}if(m.length){if(m.length>1)throw new Error("Pattern error: Using `...P.array(...)` several times in a single pattern is not allowed.");if(i.length<v.length+g.length)return!1;var y=i.slice(0,v.length),b=0===g.length?[]:i.slice(-g.length),w=i.slice(v.length,0===g.length?Infinity:-g.length);return v.every(function(t,e){return n(t,y[e],a)})&&g.every(function(t,e){return n(t,b[e],a)})&&(0===m.length||n(m[0],w,a))}return t.length===i.length&&t.every(function(t,e){return n(t,i[e],a)})}return Object.keys(t).every(function(e){var u,o=t[e];return(e in i||c(u=o)&&"optional"===u[r]().matcherType)&&n(o,i[e],a)})}return Object.is(i,t)},f=function n(t){var e,u,i;return o(t)?c(t)?null!=(e=null==(u=(i=t[r]()).getSelectionKeys)?void 0:u.call(i))?e:[]:Array.isArray(t)?s(t,n):s(Object.values(t),n):[]},s=function(n,t){return n.reduce(function(n,e){return n.concat(t(e))},[])};function l(){var n=[].slice.call(arguments);if(1===n.length){var t=n[0];return function(n){return a(t,n,function(){})}}if(2===n.length)return a(n[0],n[1],function(){});throw new Error("isMatching wasn't given the right number of arguments: expected 1 or 2, received "+n.length+".")}function h(n){return Object.assign(n,{optional:function(){return g(n)},and:function(t){return p(n,t)},or:function(t){return y(n,t)},select:function(t){return void 0===t?w(n):w(t,n)}})}function v(n){return Object.assign(function(n){var t;return Object.assign(n,((t={})[Symbol.iterator]=function(){/*#__PURE__*/return regeneratorRuntime.mark(function t(){var e;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,Object.assign(n,((e={})[u]=!0,e));case 2:case"end":return t.stop()}},t)})()},t))}(n),{optional:function(){return v(g(n))},select:function(t){return v(void 0===t?w(n):w(t,n))}})}function g(n){var t;return h(((t={})[r]=function(){return{match:function(t){var e={},r=function(n,t){e[n]=t};return void 0===t?(f(n).forEach(function(n){return r(n,void 0)}),{matched:!0,selections:e}):{matched:a(n,t,r),selections:e}},getSelectionKeys:function(){return f(n)},matcherType:"optional"}},t))}var m=function(n,t){for(var r,u=e(n);!(r=u()).done;)if(!t(r.value))return!1;return!0},d=function(n,t){for(var r,u=e(n.entries());!(r=u()).done;){var i=r.value;if(!t(i[1],i[0]))return!1}return!0};function p(){var n,t=[].slice.call(arguments);return h(((n={})[r]=function(){return{match:function(n){var e={},r=function(n,t){e[n]=t};return{matched:t.every(function(t){return a(t,n,r)}),selections:e}},getSelectionKeys:function(){return s(t,f)},matcherType:"and"}},n))}function y(){var n,t=[].slice.call(arguments);return h(((n={})[r]=function(){return{match:function(n){var e={},r=function(n,t){e[n]=t};return s(t,f).forEach(function(n){return r(n,void 0)}),{matched:t.some(function(t){return a(t,n,r)}),selections:e}},getSelectionKeys:function(){return s(t,f)},matcherType:"or"}},n))}function b(n){var t;return(t={})[r]=function(){return{match:function(t){return{matched:Boolean(n(t))}}}},t}function w(){var n,t=[].slice.call(arguments),e="string"==typeof t[0]?t[0]:void 0,u=2===t.length?t[1]:"string"==typeof t[0]?void 0:t[0];return h(((n={})[r]=function(){return{match:function(n){var t,r=((t={})[null!=e?e:i]=n,t);return{matched:void 0===u||a(u,n,function(n,t){r[n]=t}),selections:r}},getSelectionKeys:function(){return[null!=e?e:i].concat(void 0===u?[]:f(u))}}},n))}function S(n){return"number"==typeof n}function j(n){return"string"==typeof n}function O(n){return"bigint"==typeof n}var A=h(b(function(n){return!0})),x=A,E=function n(t){return Object.assign(h(t),{startsWith:function(e){return n(p(t,(r=e,b(function(n){return j(n)&&n.startsWith(r)}))));var r},endsWith:function(e){return n(p(t,(r=e,b(function(n){return j(n)&&n.endsWith(r)}))));var r},minLength:function(e){return n(p(t,function(n){return b(function(t){return j(t)&&t.length>=n})}(e)))},maxLength:function(e){return n(p(t,function(n){return b(function(t){return j(t)&&t.length<=n})}(e)))},includes:function(e){return n(p(t,(r=e,b(function(n){return j(n)&&n.includes(r)}))));var r},regex:function(e){return n(p(t,(r=e,b(function(n){return j(n)&&Boolean(n.match(r))}))));var r}})}(b(j)),K=function n(t){return Object.assign(h(t),{between:function(e,r){return n(p(t,function(n,t){return b(function(e){return S(e)&&n<=e&&t>=e})}(e,r)))},lt:function(e){return n(p(t,function(n){return b(function(t){return S(t)&&t<n})}(e)))},gt:function(e){return n(p(t,function(n){return b(function(t){return S(t)&&t>n})}(e)))},lte:function(e){return n(p(t,function(n){return b(function(t){return S(t)&&t<=n})}(e)))},gte:function(e){return n(p(t,function(n){return b(function(t){return S(t)&&t>=n})}(e)))},int:function(){return n(p(t,b(function(n){return S(n)&&Number.isInteger(n)})))},finite:function(){return n(p(t,b(function(n){return S(n)&&Number.isFinite(n)})))},positive:function(){return n(p(t,b(function(n){return S(n)&&n>0})))},negative:function(){return n(p(t,b(function(n){return S(n)&&n<0})))}})}(b(S)),T=function n(t){return Object.assign(h(t),{between:function(e,r){return n(p(t,function(n,t){return b(function(e){return O(e)&&n<=e&&t>=e})}(e,r)))},lt:function(e){return n(p(t,function(n){return b(function(t){return O(t)&&t<n})}(e)))},gt:function(e){return n(p(t,function(n){return b(function(t){return O(t)&&t>n})}(e)))},lte:function(e){return n(p(t,function(n){return b(function(t){return O(t)&&t<=n})}(e)))},gte:function(e){return n(p(t,function(n){return b(function(t){return O(t)&&t>=n})}(e)))},positive:function(){return n(p(t,b(function(n){return O(n)&&n>0})))},negative:function(){return n(p(t,b(function(n){return O(n)&&n<0})))}})}(b(O)),P=h(b(function(n){return"boolean"==typeof n})),k=h(b(function(n){return"symbol"==typeof n})),B=h(b(function(n){return null==n})),I={__proto__:null,matcher:r,optional:g,array:function(){var n,t=[].slice.call(arguments);return v(((n={})[r]=function(){return{match:function(n){if(!Array.isArray(n))return{matched:!1};if(0===t.length)return{matched:!0};var e=t[0],r={};if(0===n.length)return f(e).forEach(function(n){r[n]=[]}),{matched:!0,selections:r};var u=function(n,t){r[n]=(r[n]||[]).concat([t])};return{matched:n.every(function(n){return a(e,n,u)}),selections:r}},getSelectionKeys:function(){return 0===t.length?[]:f(t[0])}}},n))},set:function(){var n,t=[].slice.call(arguments);return h(((n={})[r]=function(){return{match:function(n){if(!(n instanceof Set))return{matched:!1};var e={};if(0===n.size)return{matched:!0,selections:e};if(0===t.length)return{matched:!0};var r=function(n,t){e[n]=(e[n]||[]).concat([t])},u=t[0];return{matched:m(n,function(n){return a(u,n,r)}),selections:e}},getSelectionKeys:function(){return 0===t.length?[]:f(t[0])}}},n))},map:function(){var n,t=[].slice.call(arguments);return h(((n={})[r]=function(){return{match:function(n){if(!(n instanceof Map))return{matched:!1};var e={};if(0===n.size)return{matched:!0,selections:e};var r,u=function(n,t){e[n]=(e[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==(r=t[0])?void 0:r.toString()));var i=t[0],o=t[1];return{matched:d(n,function(n,t){var e=a(i,t,u),r=a(o,n,u);return e&&r}),selections:e}},getSelectionKeys:function(){return 0===t.length?[]:[].concat(f(t[0]),f(t[1]))}}},n))},intersection:p,union:y,not:function(n){var t;return h(((t={})[r]=function(){return{match:function(t){return{matched:!a(n,t,function(){})}},getSelectionKeys:function(){return[]},matcherType:"not"}},t))},when:b,select:w,any:A,_:x,string:E,number:K,bigint:T,boolean:P,symbol:k,nullish:B,instanceOf:function(n){return h(b(function(n){return function(t){return t instanceof n}}(n)))},shape:function(n){return h(b(l(n)))}},_={matched:!1,value:void 0},M=/*#__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,e=[].slice.call(arguments);if(this.state.matched)return this;var r=e[e.length-1],u=[e[0]],o=void 0;3===e.length&&"function"==typeof e[1]?(u.push(e[0]),o=e[1]):e.length>2&&u.push.apply(u,e.slice(1,e.length-1));var c=!1,f={},s=function(n,t){c=!0,f[n]=t},l=!u.some(function(n){return a(n,t.input,s)})||o&&!Boolean(o(this.input))?_:{matched:!0,value:r(c?i in f?f[i]:f:this.input,this.input)};return new n(this.input,l)},t.when=function(t,e){if(this.state.matched)return this;var r=Boolean(t(this.input));return new n(this.input,r?{matched:!0,value:e(this.input,this.input)}:_)},t.otherwise=function(n){return this.state.matched?this.state.value:n(this.input)},t.exhaustive=function(){return this.run()},t.run=function(){if(this.state.matched)return this.state.value;var n;try{n=JSON.stringify(this.input)}catch(t){n=this.input}throw new Error("Pattern matching error: no pattern matches value "+n)},t.returnType=function(){return this},n}();n.P=I,n.Pattern=I,n.isMatching=l,n.match=function(n){return new M(n,_)}});
//# sourceMappingURL=index.umd.js.map

@@ -32,2 +32,2 @@ import { Pattern } from './types/Pattern.js';

*/
export declare function isMatching<p extends Pattern<unknown>>(pattern: p, value: unknown): value is P.infer<p>;
export declare function isMatching<const p extends Pattern<unknown>>(pattern: p, value: unknown): value is P.infer<p>;

@@ -44,3 +44,3 @@ import * as symbols from './internals/symbols.js';

*
* [Read the documentation for `P.infer` on GitHub](https://github.com/gvergnaud/ts-pattern#Pinfer)
* [Read the documentation for `P.infer` on GitHub](https://github.com/gvergnaud/ts-pattern#pinfer)
*

@@ -56,3 +56,3 @@ * @example

*
* [Read the documentation for `P.narrow` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnarrow)
* [Read the documentation for `P.narrow` on GitHub](https://github.com/gvergnaud/ts-pattern#pnarrow)
*

@@ -71,3 +71,3 @@ * @example

*
* [Read the documentation for `P.optional` on GitHub](https://github.com/gvergnaud/ts-pattern#Poptional-patterns)
* [Read the documentation for `P.optional` on GitHub](https://github.com/gvergnaud/ts-pattern#poptional-patterns)
*

@@ -88,3 +88,3 @@ * @example

*
* [Read the documentation for `P.array` on GitHub](https://github.com/gvergnaud/ts-pattern#Parray-patterns)
* [Read the documentation for `P.array` on GitHub](https://github.com/gvergnaud/ts-pattern#parray-patterns)
*

@@ -101,3 +101,3 @@ * @example

*
* [Read `P.set` documentation on GitHub](https://github.com/gvergnaud/ts-pattern#Pset-patterns)
* [Read `P.set` documentation on GitHub](https://github.com/gvergnaud/ts-pattern#pset-patterns)
*

@@ -114,3 +114,3 @@ * @example

*
* [Read `P.set` documentation on GitHub](https://github.com/gvergnaud/ts-pattern#Pset-patterns)
* [Read `P.set` documentation on GitHub](https://github.com/gvergnaud/ts-pattern#pset-patterns)
*

@@ -127,3 +127,3 @@ * @example

*
* [Read the documentation for `P.intersection` on GitHub](https://github.com/gvergnaud/ts-pattern#Pintersection-patterns)
* [Read the documentation for `P.intersection` on GitHub](https://github.com/gvergnaud/ts-pattern#pintersection-patterns)
*

@@ -148,3 +148,3 @@ * @example

*
* [Read the documentation for `P.union` on GitHub](https://github.com/gvergnaud/ts-pattern#Punion-patterns)
* [Read the documentation for `P.union` on GitHub](https://github.com/gvergnaud/ts-pattern#punion-patterns)
*

@@ -163,3 +163,3 @@ * @example

*
* [Read the documentation for `P.not` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnot-patterns)
* [Read the documentation for `P.not` on GitHub](https://github.com/gvergnaud/ts-pattern#pnot-patterns)
*

@@ -176,3 +176,3 @@ * @example

*
* [Read the documentation for `P.when` on GitHub](https://github.com/gvergnaud/ts-pattern#Pwhen-patterns)
* [Read the documentation for `P.when` on GitHub](https://github.com/gvergnaud/ts-pattern#pwhen-patterns)
*

@@ -190,3 +190,3 @@ * @example

*
* [Read the documentation for `P.select` on GitHub](https://github.com/gvergnaud/ts-pattern#Pselect-patterns)
* [Read the documentation for `P.select` on GitHub](https://github.com/gvergnaud/ts-pattern#pselect-patterns)
*

@@ -205,3 +205,3 @@ * @example

*
* [Read the documentation for `P.any` on GitHub](https://github.com/gvergnaud/ts-pattern#P_-wildcard)
* [Read the documentation for `P.any` on GitHub](https://github.com/gvergnaud/ts-pattern#p_-wildcard)
*

@@ -217,3 +217,3 @@ * @example

*
* [Read the documentation for `P._` on GitHub](https://github.com/gvergnaud/ts-pattern#P_-wildcard)
* [Read the documentation for `P._` on GitHub](https://github.com/gvergnaud/ts-pattern#p_-wildcard)
*

@@ -228,3 +228,3 @@ * @example

*
* [Read the documentation for `P.string` on GitHub](https://github.com/gvergnaud/ts-pattern#Pstring-wildcard)
* [Read the documentation for `P.string` on GitHub](https://github.com/gvergnaud/ts-pattern#pstring-wildcard)
*

@@ -237,96 +237,5 @@ * @example

/**
* `P.number.between(min, max)` matches **number** between `min` and `max`,
* equal to min or equal to max.
*
* [Read the documentation for `P.number.between` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnumberbetween)
*
* @example
* match(value)
* .with(P.number.between(0, 10), () => '0 <= numbers <= 10')
*/
export declare const between: <input, const min extends number, const max extends number>(min: min, max: max) => GuardExcludeP<input, number, never>;
/**
* `P.number.lt(max)` matches **number** smaller than `max`.
*
* [Read the documentation for `P.number.lt` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnumberlt)
*
* @example
* match(value)
* .with(P.number.lt(10), () => 'numbers < 10')
*/
export declare const lt: <input, const max extends number>(max: max) => GuardExcludeP<input, number, never>;
/**
* `P.number.gt(min)` matches **number** greater than `min`.
*
* [Read the documentation for `P.number.gt` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnumbergt)
*
* @example
* match(value)
* .with(P.number.gt(10), () => 'numbers > 10')
*/
export declare const gt: <input, const min extends number>(min: min) => GuardExcludeP<input, number, never>;
/**
* `P.number.lte(max)` matches **number** smaller than or equal to `max`.
*
* [Read the documentation for `P.number.lte` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnumberlte)
*
* @example
* match(value)
* .with(P.number.lte(10), () => 'numbers <= 10')
*/
export declare const lte: <input, const max extends number>(max: max) => GuardExcludeP<input, number, never>;
/**
* `P.number.gte(min)` matches **number** greater than or equal to `min`.
*
* [Read the documentation for `P.number.gte` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnumbergte)
*
* @example
* match(value)
* .with(P.number.gte(10), () => 'numbers >= 10')
*/
export declare const gte: <input, const min extends number>(min: min) => GuardExcludeP<input, number, never>;
/**
* `P.number.int` matches **integer** numbers.
*
* [Read the documentation for `P.number.int` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnumberint)
*
* @example
* match(value)
* .with(P.number.int, () => 'an integer')
*/
export declare const int: <input>() => GuardExcludeP<input, number, never>;
/**
* `P.number.finite` matches **finite numbers**.
*
* [Read the documentation for `P.number.finite` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnumberfinite)
*
* @example
* match(value)
* .with(P.number.finite, () => 'not Infinity')
*/
export declare const finite: <input>() => GuardExcludeP<input, number, never>;
/**
* `P.number.positive` matches **positive** numbers.
*
* [Read the documentation for `P.number.positive` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnumberpositive)
*
* @example
* match(value)
* .with(P.number.positive, () => 'number > 0')
*/
export declare const positive: <input>() => GuardExcludeP<input, number, never>;
/**
* `P.number.negative` matches **negative** numbers.
*
* [Read the documentation for `P.number.negative` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnumbernegative)
*
* @example
* match(value)
* .with(P.number.negative, () => 'number < 0')
*/
export declare const negative: <input>() => GuardExcludeP<input, number, never>;
/**
* `P.number` is a wildcard pattern, matching any **number**.
*
* [Read the documentation for `P.number` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnumber-wildcard)
* [Read the documentation for `P.number` on GitHub](https://github.com/gvergnaud/ts-pattern#pnumber-wildcard)
*

@@ -339,76 +248,5 @@ * @example

/**
* `P.bigint.between(min, max)` matches **bigint** between `min` and `max`,
* equal to min or equal to max.
*
* [Read the documentation for `P.bigint.between` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnumberbetween)
*
* @example
* match(value)
* .with(P.bigint.between(0, 10), () => '0 <= numbers <= 10')
*/
export declare const betweenBigInt: <input, const min extends bigint, const max extends bigint>(min: min, max: max) => GuardExcludeP<input, bigint, never>;
/**
* `P.bigint.lt(max)` matches **bigint** smaller than `max`.
*
* [Read the documentation for `P.bigint.lt` on GitHub](https://github.com/gvergnaud/ts-pattern#bigintlt)
*
* @example
* match(value)
* .with(P.bigint.lt(10), () => 'numbers < 10')
*/
export declare const ltBigInt: <input, const max extends bigint>(max: max) => GuardExcludeP<input, bigint, never>;
/**
* `P.bigint.gt(min)` matches **bigint** greater than `min`.
*
* [Read the documentation for `P.bigint.gt` on GitHub](https://github.com/gvergnaud/ts-pattern#bigintgt)
*
* @example
* match(value)
* .with(P.bigint.gt(10), () => 'numbers > 10')
*/
export declare const gtBigInt: <input, const min extends bigint>(min: min) => GuardExcludeP<input, bigint, never>;
/**
* `P.bigint.lte(max)` matches **bigint** smaller than or equal to `max`.
*
* [Read the documentation for `P.bigint.lte` on GitHub](https://github.com/gvergnaud/ts-pattern#bigintlte)
*
* @example
* match(value)
* .with(P.bigint.lte(10), () => 'bigints <= 10')
*/
export declare const lteBigInt: <input, const max extends bigint>(max: max) => GuardExcludeP<input, bigint, never>;
/**
* `P.bigint.gte(min)` matches **bigint** greater than or equal to `min`.
*
* [Read the documentation for `P.bigint.gte` on GitHub](https://github.com/gvergnaud/ts-pattern#Pbigintgte)
*
* @example
* match(value)
* .with(P.bigint.gte(10), () => 'bigints >= 10')
*/
export declare const gteBigInt: <input, const min extends bigint>(min: min) => GuardExcludeP<input, bigint, never>;
/**
* `P.bigint.positive` matches **positive** bigints.
*
* [Read the documentation for `P.bigint.positive` on GitHub](https://github.com/gvergnaud/ts-pattern#Pbigintpositive)
*
* @example
* match(value)
* .with(P.bigint.positive, () => 'bigint > 0')
*/
export declare const positiveBigInt: <input>() => GuardExcludeP<input, bigint, never>;
/**
* `P.bigint.negative` matches **negative** bigints.
*
* [Read the documentation for `P.bigint.negative` on GitHub](https://github.com/gvergnaud/ts-pattern#Pbigintnegative)
*
* @example
* match(value)
* .with(P.bigint.negative, () => 'bigint < 0')
*/
export declare const negativeBigInt: <input>() => GuardExcludeP<input, bigint, never>;
/**
* `P.bigint` is a wildcard pattern, matching any **bigint**.
*
* [Read the documentation for `P.bigint` on GitHub](https://github.com/gvergnaud/ts-pattern#bigint-wildcard)
* [Read the documentation for `P.bigint` on GitHub](https://github.com/gvergnaud/ts-pattern#number-wildcard)
*

@@ -449,3 +287,3 @@ * @example

*
* [Read the documentation for `P.instanceOf` on GitHub](https://github.com/gvergnaud/ts-pattern#Pinstanceof-patterns)
* [Read the documentation for `P.instanceOf` on GitHub](https://github.com/gvergnaud/ts-pattern#pinstanceof-patterns)
*

@@ -460,3 +298,3 @@ * @example

*
* [Read the documentation for `P.shape` on GitHub](https://github.com/gvergnaud/ts-pattern#Pshape-patterns)
* [Read the documentation for `P.shape` on GitHub](https://github.com/gvergnaud/ts-pattern#pshape-patterns)
*

@@ -463,0 +301,0 @@ * @example

@@ -85,3 +85,3 @@ import type * as symbols from '../internals/symbols.js';

*
* [Read the documentation for `P.optional` on GitHub](https://github.com/gvergnaud/ts-pattern#Poptional-patterns)
* [Read the documentation for `P.optional` on GitHub](https://github.com/gvergnaud/ts-pattern#poptional-patterns)
*

@@ -97,3 +97,3 @@ * @example

*
* [Read the documentation for `P.intersection` on GitHub](https://github.com/gvergnaud/ts-pattern#Pintersection-patterns)
* [Read the documentation for `P.intersection` on GitHub](https://github.com/gvergnaud/ts-pattern#pintersection-patterns)
*

@@ -112,3 +112,3 @@ * @example

*
* [Read the documentation for `P.union` on GitHub](https://github.com/gvergnaud/ts-pattern#Punion-patterns)
* [Read the documentation for `P.union` on GitHub](https://github.com/gvergnaud/ts-pattern#punion-patterns)
*

@@ -126,3 +126,3 @@ * @example

*
* [Read the documentation for `P.select` on GitHub](https://github.com/gvergnaud/ts-pattern#Pselect-patterns)
* [Read the documentation for `P.select` on GitHub](https://github.com/gvergnaud/ts-pattern#pselect-patterns)
*

@@ -140,3 +140,3 @@ * @example

*
* [Read the documentation for `P.string.startsWith` on GitHub](https://github.com/gvergnaud/ts-pattern#PstringstartsWith)
* [Read the documentation for `P.string.startsWith` on GitHub](https://github.com/gvergnaud/ts-pattern#pstringstartsWith)
*

@@ -151,3 +151,3 @@ * @example

*
* [Read the documentation for `P.string.endsWith` on GitHub](https://github.com/gvergnaud/ts-pattern#PstringendsWith)
* [Read the documentation for `P.string.endsWith` on GitHub](https://github.com/gvergnaud/ts-pattern#pstringendsWith)
*

@@ -162,3 +162,3 @@ * @example

*
* [Read the documentation for `P.string.minLength` on GitHub](https://github.com/gvergnaud/ts-pattern#PstringminLength)
* [Read the documentation for `P.string.minLength` on GitHub](https://github.com/gvergnaud/ts-pattern#pstringminLength)
*

@@ -173,3 +173,3 @@ * @example

*
* [Read the documentation for `P.string.maxLength` on GitHub](https://github.com/gvergnaud/ts-pattern#PstringmaxLength)
* [Read the documentation for `P.string.maxLength` on GitHub](https://github.com/gvergnaud/ts-pattern#pstringmaxLength)
*

@@ -184,3 +184,3 @@ * @example

*
* [Read the documentation for `P.string.includes` on GitHub](https://github.com/gvergnaud/ts-pattern#Pstringincludes)
* [Read the documentation for `P.string.includes` on GitHub](https://github.com/gvergnaud/ts-pattern#pstringincludes)
*

@@ -195,3 +195,3 @@ * @example

*
* [Read the documentation for `P.string.regex` on GitHub](https://github.com/gvergnaud/ts-pattern#Pstringregex)
* [Read the documentation for `P.string.regex` on GitHub](https://github.com/gvergnaud/ts-pattern#pstringregex)
*

@@ -209,3 +209,3 @@ * @example

*
* [Read the documentation for `P.number.between` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnumberbetween)
* [Read the documentation for `P.number.between` on GitHub](https://github.com/gvergnaud/ts-pattern#pnumberbetween)
*

@@ -220,3 +220,3 @@ * @example

*
* [Read the documentation for `P.number.lt` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnumberlt)
* [Read the documentation for `P.number.lt` on GitHub](https://github.com/gvergnaud/ts-pattern#pnumberlt)
*

@@ -231,3 +231,3 @@ * @example

*
* [Read the documentation for `P.number.gt` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnumbergt)
* [Read the documentation for `P.number.gt` on GitHub](https://github.com/gvergnaud/ts-pattern#pnumbergt)
*

@@ -242,3 +242,3 @@ * @example

*
* [Read the documentation for `P.number.lte` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnumberlte)
* [Read the documentation for `P.number.lte` on GitHub](https://github.com/gvergnaud/ts-pattern#pnumberlte)
*

@@ -253,3 +253,3 @@ * @example

*
* [Read the documentation for `P.number.gte` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnumbergte)
* [Read the documentation for `P.number.gte` on GitHub](https://github.com/gvergnaud/ts-pattern#pnumbergte)
*

@@ -264,3 +264,3 @@ * @example

*
* [Read the documentation for `P.number.int` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnumberint)
* [Read the documentation for `P.number.int` on GitHub](https://github.com/gvergnaud/ts-pattern#pnumberint)
*

@@ -275,3 +275,3 @@ * @example

*
* [Read the documentation for `P.number.finite` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnumberfinite)
* [Read the documentation for `P.number.finite` on GitHub](https://github.com/gvergnaud/ts-pattern#pnumberfinite)
*

@@ -286,3 +286,3 @@ * @example

*
* [Read the documentation for `P.number.positive` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnumberpositive)
* [Read the documentation for `P.number.positive` on GitHub](https://github.com/gvergnaud/ts-pattern#pnumberpositive)
*

@@ -297,3 +297,3 @@ * @example

*
* [Read the documentation for `P.number.negative` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnumbernegative)
* [Read the documentation for `P.number.negative` on GitHub](https://github.com/gvergnaud/ts-pattern#pnumbernegative)
*

@@ -311,3 +311,3 @@ * @example

*
* [Read the documentation for `P.bigint.between` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnumberbetween)
* [Read the documentation for `P.bigint.between` on GitHub](https://github.com/gvergnaud/ts-pattern#pnumberbetween)
*

@@ -322,3 +322,3 @@ * @example

*
* [Read the documentation for `P.bigint.lt` on GitHub](https://github.com/gvergnaud/ts-pattern#bigintlt)
* [Read the documentation for `P.bigint.lt` on GitHub](https://github.com/gvergnaud/ts-pattern#pnumberlt)
*

@@ -333,3 +333,3 @@ * @example

*
* [Read the documentation for `P.bigint.gt` on GitHub](https://github.com/gvergnaud/ts-pattern#bigintgt)
* [Read the documentation for `P.bigint.gt` on GitHub](https://github.com/gvergnaud/ts-pattern#pnumbergt)
*

@@ -344,3 +344,3 @@ * @example

*
* [Read the documentation for `P.bigint.lte` on GitHub](https://github.com/gvergnaud/ts-pattern#bigintlte)
* [Read the documentation for `P.bigint.lte` on GitHub](https://github.com/gvergnaud/ts-pattern#pnumberlte)
*

@@ -355,3 +355,3 @@ * @example

*
* [Read the documentation for `P.bigint.gte` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnumbergte)
* [Read the documentation for `P.bigint.gte` on GitHub](https://github.com/gvergnaud/ts-pattern#pnumbergte)
*

@@ -366,3 +366,3 @@ * @example

*
* [Read the documentation for `P.bigint.positive` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnumberpositive)
* [Read the documentation for `P.bigint.positive` on GitHub](https://github.com/gvergnaud/ts-pattern#pnumberpositive)
*

@@ -377,3 +377,3 @@ * @example

*
* [Read the documentation for `P.bigint.negative` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnumbernegative)
* [Read the documentation for `P.bigint.negative` on GitHub](https://github.com/gvergnaud/ts-pattern#pnumbernegative)
*

@@ -392,3 +392,3 @@ * @example

*
* [Read the documentation for `P.optional` on GitHub](https://github.com/gvergnaud/ts-pattern#Poptional-patterns)
* [Read the documentation for `P.optional` on GitHub](https://github.com/gvergnaud/ts-pattern#poptional-patterns)
*

@@ -403,3 +403,3 @@ * @example

*
* [Read the documentation for `P.select` on GitHub](https://github.com/gvergnaud/ts-pattern#Pselect-patterns)
* [Read the documentation for `P.select` on GitHub](https://github.com/gvergnaud/ts-pattern#pselect-patterns)
*

@@ -406,0 +406,0 @@ * @example

{
"name": "ts-pattern",
"version": "5.0.4",
"version": "5.0.5",
"description": " The exhaustive Pattern Matching library for TypeScript.",

@@ -5,0 +5,0 @@ "type": "module",

@@ -54,5 +54,5 @@ <h1 align="center">TS-Pattern</h1>

- Use [patterns](#patterns) to **validate** the shape of your data with [`isMatching`](#ismatching).
- **Expressive API**, with catch-all and type specific **wildcards**: [`P._`](#P_-wildcard), [`P.string`](#Pstring-wildcard), [`P.number`](#Pnumber-wildcard), etc.
- Supports [**predicates**](#Pwhen-patterns), [**unions**](#Punion-patterns), [**intersections**](#Pintersection-patterns) and [**exclusion**](#Pnot-patterns) patterns for non-trivial cases.
- Supports properties selection, via the [`P.select(name?)`](#Pselect-patterns) function.
- **Expressive API**, with catch-all and type specific **wildcards**: [`P._`](#p_-wildcard), [`P.string`](#pstring-wildcard), [`P.number`](#pnumber-wildcard), etc.
- Supports [**predicates**](#pwhen-patterns), [**unions**](#punion-patterns), [**intersections**](#pintersection-patterns) and [**exclusion**](#pnot-patterns) patterns for non-trivial cases.
- Supports properties selection, via the [`P.select(name?)`](#pselect-patterns) function.
- Tiny bundle footprint ([**only ~2kB**](https://bundlephobia.com/package/ts-pattern)).

@@ -84,3 +84,3 @@

Note: TS-Pattern assumes [Strict Mode](https://www.typescriptlang.org/tsconfig#strict) is enabled in your `tsconfig.json` file.
TS-Pattern assumes that [Strict Mode](https://www.typescriptlang.org/tsconfig#strict) is enabled in your `tsconfig.json` file.

@@ -116,15 +116,15 @@ | ts-pattern | TypeScript v5+ | TypeScript v4.5+ | TypeScript v4.2+ |

- [Maps](#pmap-patterns)
- [`P.array` patterns](#Parray-patterns)
- [`P.when` patterns](#Pwhen-patterns)
- [`P.not` patterns](#Pnot-patterns)
- [`P.select` patterns](#Pselect-patterns)
- [`P.optional` patterns](#Poptional-patterns)
- [`P.instanceOf` patterns](#Pinstanceof-patterns)
- [`P.union` patterns](#Punion-patterns)
- [`P.intersection` patterns](#Pintersection-patterns)
- [`P.array` patterns](#parray-patterns)
- [`P.when` patterns](#pwhen-patterns)
- [`P.not` patterns](#pnot-patterns)
- [`P.select` patterns](#pselect-patterns)
- [`P.optional` patterns](#poptional-patterns)
- [`P.instanceOf` patterns](#pinstanceof-patterns)
- [`P.union` patterns](#punion-patterns)
- [`P.intersection` patterns](#pintersection-patterns)
- [`P.string` predicates](#pstring-predicates)
- [`P.number` and `P.bigint` predicates](#pnumber-and-pbigint-predicates)
- [Types](#types)
- [`P.infer`](#Pinfer)
- [`P.Pattern`](#PPattern)
- [`P.infer`](#pinfer)
- [`P.Pattern`](#pPattern)
- [Type inference](#type-inference)

@@ -690,3 +690,3 @@ - [Inspirations](#inspirations)

Patterns can be regular JavaScript values (`"some string"`, `10`, `true`, ...), data structures ([objects](#objects), [arrays](#tuples-arrays), ...), wildcards ([`P._`](#P_-wildcard), [`P.string`](#pstring-wildcard), [`P.number`](#pnumber-wildcard), ...), or special matcher functions ([`P.not`](#pnot-patterns),
Patterns can be regular JavaScript values (`"some string"`, `10`, `true`, ...), data structures ([objects](#objects), [arrays](#tuples-arrays), ...), wildcards ([`P._`](#p_-wildcard), [`P.string`](#pstring-wildcard), [`P.number`](#pnumber-wildcard), ...), or special matcher functions ([`P.not`](#pnot-patterns),
[`P.when`](#pwhen-patterns), [`P.select`](#pselect-patterns), ...).

@@ -774,5 +774,5 @@

In TypeScript, [Tuples](https://en.wikipedia.org/wiki/Tuple) are arrays with a fixed
number of elements which can be of different types. You can pattern-match on tuples
number of elements that can be of different types. You can pattern-match on tuples
using a tuple pattern. A tuple pattern will match if the input value **is an array of the same length**,
and each item match the corresponding sub-pattern.
and each item matches the corresponding sub-pattern.

@@ -779,0 +779,0 @@ ```ts

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc