ts-pattern
Advanced tools
Comparing version 5.0.0-rc.5 to 5.0.0-rc.6
@@ -1,2 +0,2 @@ | ||
const t=Symbol("@ts-pattern/matcher"),e=Symbol("@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 time 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}.`)}const h=t=>Object.assign(t,{optional:()=>u(t),and:e=>m(t,e),or:e=>y(t,e),select:e=>void 0===e?v(t):v(e,t)});function u(e){return h({[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"})})}function l(...n){return h({[t]:()=>({match:t=>{if(!Array.isArray(t))return{matched:!1};if(0===n.length)return{matched:!0};const e=n[0];let r={};if(0===t.length)return o(e).forEach(t=>{r[t]=[]}),{matched:!0,selections:r};const i=(t,e)=>{r[t]=(r[t]||[]).concat([e])};return{matched:t.every(t=>s(e,t,i)),selections:r}},getSelectionKeys:()=>0===n.length?[]:o(n[0])}),*[Symbol.iterator](){yield Object.assign(0===n.length?l():l(n[0]),{[e]:!0})}})}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 h({[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 h({[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 p(e){return h({[t]:()=>({match:t=>({matched:!s(e,t,()=>{})}),getSelectionKeys:()=>[],matcherType:"not"})})}function d(e){return h({[t]:()=>({match:t=>({matched:Boolean(e(t))})})})}function v(...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 h({[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 b(t){return"number"==typeof t}function w(t){return"string"==typeof t}function S(t){return"bigint"==typeof t}const B=h(d(function(t){return!0})),O=B,j=t=>Object.assign(t,{startsWith:e=>{return j(m(t,(n=e,d(t=>w(t)&&t.startsWith(n)))));var n},endsWith:e=>{return j(m(t,(n=e,d(t=>w(t)&&t.endsWith(n)))));var n},minLength:e=>j(m(t,(t=>d(e=>w(e)&&e.length>=t))(e))),maxLength:e=>j(m(t,(t=>d(e=>w(e)&&e.length<=t))(e))),includes:e=>{return j(m(t,(n=e,d(t=>w(t)&&t.includes(n)))));var n},regex:e=>{return j(m(t,(n=e,d(t=>w(t)&&Boolean(t.match(n))))));var n}}),E=j(d(w)),I=(t,e)=>d(n=>b(n)&&t<=n&&e>=n),K=t=>d(e=>b(e)&&e<t),A=t=>d(e=>b(e)&&e>t),k=t=>d(e=>b(e)&&e<=t),x=t=>d(e=>b(e)&&e>=t),P=()=>d(t=>b(t)&&Number.isInteger(t)),T=()=>d(t=>b(t)&&Number.isFinite(t)),_=()=>d(t=>b(t)&&t>0),W=()=>d(t=>b(t)&&t<0),N=t=>Object.assign(t,{between:(e,n)=>N(m(t,I(e,n))),lt:e=>N(m(t,K(e))),gt:e=>N(m(t,A(e))),lte:e=>N(m(t,k(e))),gte:e=>N(m(t,x(e))),int:()=>N(m(t,P())),finite:()=>N(m(t,T())),positive:()=>N(m(t,_())),negative:()=>N(m(t,W()))}),$=N(d(b)),z=(t,e)=>d(n=>S(n)&&t<=n&&e>=n),L=t=>d(e=>S(e)&&e<t),M=t=>d(e=>S(e)&&e>t),F=t=>d(e=>S(e)&&e<=t),J=t=>d(e=>S(e)&&e>=t),U=()=>d(t=>S(t)&&t>0),V=()=>d(t=>S(t)&&t<0),q=t=>Object.assign(t,{between:(e,n)=>q(m(t,z(e,n))),lt:e=>q(m(t,L(e))),gt:e=>q(m(t,M(e))),lte:e=>q(m(t,F(e))),gte:e=>q(m(t,J(e))),positive:()=>q(m(t,U())),negative:()=>q(m(t,V()))}),C=q(d(S)),D=h(d(function(t){return"boolean"==typeof t})),G=h(d(function(t){return"symbol"==typeof t})),H=h(d(function(t){return null==t}));var Q={__proto__:null,matcher:t,optional:u,array:l,set:function(...e){return h({[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 h({[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:y,not:p,when:d,select:v,any:B,_:O,string:E,between:I,lt:K,gt:A,lte:k,gte:x,int:P,finite:T,positive:_,negative:W,number:$,betweenBigInt:z,ltBigInt:L,gtBigInt:M,lteBigInt:F,gteBigInt:J,positiveBigInt:U,negativeBigInt:V,bigint:C,boolean:D,symbol:G,nullish:H,instanceOf:function(t){return h(d(function(t){return e=>e instanceof t}(t)))},shape:function(t){return h(d(a(t)))},typed:function(){return{array:l,optional:u,intersection:m,union:y,not:p,select:v,when:d}}};function R(t){return new Y(t)}const X={matched:!1};class Y{constructor(t,e=X){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]],i=[];3===t.length&&"function"==typeof t[1]?(r.push(t[0]),i.push(t[1])):t.length>2&&r.push(...t.slice(1,t.length-1));let o={};const c=Boolean(r.some(t=>s(t,this.input,(t,e)=>{o[t]=e}))&&i.every(t=>t(this.input)))?{matched:!0,value:e(Object.keys(o).length?n in o?o[n]:o:this.input,this.input)}:{matched:!1};return new Y(this.input,c)}when(t,e){if(this.state.matched)return this;const n=Boolean(t(this.input));return new Y(this.input,n?{matched:!0,value:e(this.input,this.input)}:{matched:!1})}otherwise(t){return this.state.matched?this.state.value:t(this.input,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{Q as P,Q as Pattern,a as isMatching,R as match}; | ||
const t=Symbol("@ts-pattern/matcher"),e=Symbol("@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 time 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}.`)}const h=t=>Object.assign(t,{optional:()=>u(t),and:e=>f(t,e),or:e=>m(t,e),select:e=>void 0===e?p(t):p(e,t)});function u(e){return h({[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 l=(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 f(...e){return h({[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 m(...e){return h({[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 h({[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 h({[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 d(t){return"number"==typeof t}function v(t){return"string"==typeof t}function b(t){return"bigint"==typeof t}const w=h(y(function(t){return!0})),S=w,B=t=>Object.assign(t,{startsWith:e=>{return B(f(t,(n=e,y(t=>v(t)&&t.startsWith(n)))));var n},endsWith:e=>{return B(f(t,(n=e,y(t=>v(t)&&t.endsWith(n)))));var n},minLength:e=>B(f(t,(t=>y(e=>v(e)&&e.length>=t))(e))),maxLength:e=>B(f(t,(t=>y(e=>v(e)&&e.length<=t))(e))),includes:e=>{return B(f(t,(n=e,y(t=>v(t)&&t.includes(n)))));var n},regex:e=>{return B(f(t,(n=e,y(t=>v(t)&&Boolean(t.match(n))))));var n}}),O=B(y(v)),j=(t,e)=>y(n=>d(n)&&t<=n&&e>=n),E=t=>y(e=>d(e)&&e<t),I=t=>y(e=>d(e)&&e>t),K=t=>y(e=>d(e)&&e<=t),A=t=>y(e=>d(e)&&e>=t),k=()=>y(t=>d(t)&&Number.isInteger(t)),x=()=>y(t=>d(t)&&Number.isFinite(t)),P=()=>y(t=>d(t)&&t>0),T=()=>y(t=>d(t)&&t<0),_=t=>Object.assign(t,{between:(e,n)=>_(f(t,j(e,n))),lt:e=>_(f(t,E(e))),gt:e=>_(f(t,I(e))),lte:e=>_(f(t,K(e))),gte:e=>_(f(t,A(e))),int:()=>_(f(t,k())),finite:()=>_(f(t,x())),positive:()=>_(f(t,P())),negative:()=>_(f(t,T()))}),W=_(y(d)),N=(t,e)=>y(n=>b(n)&&t<=n&&e>=n),$=t=>y(e=>b(e)&&e<t),z=t=>y(e=>b(e)&&e>t),L=t=>y(e=>b(e)&&e<=t),M=t=>y(e=>b(e)&&e>=t),F=()=>y(t=>b(t)&&t>0),J=()=>y(t=>b(t)&&t<0),U=t=>Object.assign(t,{between:(e,n)=>U(f(t,N(e,n))),lt:e=>U(f(t,$(e))),gt:e=>U(f(t,z(e))),lte:e=>U(f(t,L(e))),gte:e=>U(f(t,M(e))),positive:()=>U(f(t,F())),negative:()=>U(f(t,J()))}),V=U(y(b)),q=h(y(function(t){return"boolean"==typeof t})),C=h(y(function(t){return"symbol"==typeof t})),D=h(y(function(t){return null==t}));var G={__proto__:null,matcher:t,optional:u,array:function n(...r){return h({[t]:()=>({match:t=>{if(!Array.isArray(t))return{matched:!1};if(0===r.length)return{matched:!0};const e=r[0];let n={};if(0===t.length)return o(e).forEach(t=>{n[t]=[]}),{matched:!0,selections:n};const i=(t,e)=>{n[t]=(n[t]||[]).concat([e])};return{matched:t.every(t=>s(e,t,i)),selections:n}},getSelectionKeys:()=>0===r.length?[]:o(r[0])}),*[Symbol.iterator](){yield Object.assign(0===r.length?n():n(r[0]),{[e]:!0})}})},set:function(...e){return h({[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:l(t,t=>s(i,t,r)),selections:n}},getSelectionKeys:()=>0===e.length?[]:o(e[0])})})},map:function(...e){return h({[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:f,union:m,not:function(e){return h({[t]:()=>({match:t=>({matched:!s(e,t,()=>{})}),getSelectionKeys:()=>[],matcherType:"not"})})},when:y,select:p,any:w,_:S,string:O,between:j,lt:E,gt:I,lte:K,gte:A,int:k,finite:x,positive:P,negative:T,number:W,betweenBigInt:N,ltBigInt:$,gtBigInt:z,lteBigInt:L,gteBigInt:M,positiveBigInt:F,negativeBigInt:J,bigint:V,boolean:q,symbol:C,nullish:D,instanceOf:function(t){return h(y(function(t){return e=>e instanceof t}(t)))},shape:function(t){return h(y(a(t)))}};function H(t){return new R(t)}const Q={matched:!1};class R{constructor(t,e=Q){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]],i=[];3===t.length&&"function"==typeof t[1]?(r.push(t[0]),i.push(t[1])):t.length>2&&r.push(...t.slice(1,t.length-1));let o={};const c=Boolean(r.some(t=>s(t,this.input,(t,e)=>{o[t]=e}))&&i.every(t=>t(this.input)))?{matched:!0,value:e(Object.keys(o).length?n in o?o[n]:o:this.input,this.input)}:{matched:!1};return new R(this.input,c)}when(t,e){if(this.state.matched)return this;const n=Boolean(t(this.input));return new R(this.input,n?{matched:!0,value:e(this.input,this.input)}:{matched:!1})}otherwise(t){return this.state.matched?this.state.value:t(this.input,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{G as P,G as Pattern,a as isMatching,H 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("@ts-pattern/matcher"),u=Symbol("@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,g=[],v=[],m=[],p=e(t.keys());!(h=p()).done;){var d=t[h.value];c(d)&&d[u]?m.push(d):m.length?v.push(d):g.push(d)}if(m.length){if(m.length>1)throw new Error("Pattern error: Using `...P.array(...)` several time 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],a)})&&v.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+".")}var h=function(n){return Object.assign(n,{optional:function(){return g(n)},and:function(t){return d(n,t)},or:function(t){return y(n,t)},select:function(t){return void 0===t?S(n):S(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))}function v(){var n,t=[].slice.call(arguments);return h(((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[Symbol.iterator]=function(){/*#__PURE__*/return regeneratorRuntime.mark(function n(){var e;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,Object.assign(0===t.length?v():v(t[0]),((e={})[u]=!0,e));case 2:case"end":return n.stop()}},n)})()},n))}var m=function(n,t){for(var r,u=e(n);!(r=u()).done;)if(!t(r.value))return!1;return!0},p=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 d(){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 h(((t={})[r]=function(){return{match:function(t){return{matched:!a(n,t,function(){})}},getSelectionKeys:function(){return[]},matcherType:"not"}},t))}function w(n){var t;return h(((t={})[r]=function(){return{match:function(t){return{matched:Boolean(n(t))}}}},t))}function S(){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 j(n){return"number"==typeof n}function A(n){return"string"==typeof n}function O(n){return"bigint"==typeof n}var B=h(w(function(n){return!0})),I=B,x=function n(t){return Object.assign(t,{startsWith:function(e){return n(d(t,(r=e,w(function(n){return A(n)&&n.startsWith(r)}))));var r},endsWith:function(e){return n(d(t,(r=e,w(function(n){return A(n)&&n.endsWith(r)}))));var r},minLength:function(e){return n(d(t,function(n){return w(function(t){return A(t)&&t.length>=n})}(e)))},maxLength:function(e){return n(d(t,function(n){return w(function(t){return A(t)&&t.length<=n})}(e)))},includes:function(e){return n(d(t,(r=e,w(function(n){return A(n)&&n.includes(r)}))));var r},regex:function(e){return n(d(t,(r=e,w(function(n){return A(n)&&Boolean(n.match(r))}))));var r}})}(w(A)),E=function(n,t){return w(function(e){return j(e)&&n<=e&&t>=e})},K=function(n){return w(function(t){return j(t)&&t<n})},T=function(n){return w(function(t){return j(t)&&t>n})},k=function(n){return w(function(t){return j(t)&&t<=n})},P=function(n){return w(function(t){return j(t)&&t>=n})},_=function(){return w(function(n){return j(n)&&Number.isInteger(n)})},M=function(){return w(function(n){return j(n)&&Number.isFinite(n)})},W=function(){return w(function(n){return j(n)&&n>0})},N=function(){return w(function(n){return j(n)&&n<0})},z=function n(t){return Object.assign(t,{between:function(e,r){return n(d(t,E(e,r)))},lt:function(e){return n(d(t,K(e)))},gt:function(e){return n(d(t,T(e)))},lte:function(e){return n(d(t,k(e)))},gte:function(e){return n(d(t,P(e)))},int:function(){return n(d(t,_()))},finite:function(){return n(d(t,M()))},positive:function(){return n(d(t,W()))},negative:function(){return n(d(t,N()))}})}(w(j)),L=function(n,t){return w(function(e){return O(e)&&n<=e&&t>=e})},R=function(n){return w(function(t){return O(t)&&t<n})},U=function(n){return w(function(t){return O(t)&&t>n})},C=function(n){return w(function(t){return O(t)&&t<=n})},F=function(n){return w(function(t){return O(t)&&t>=n})},J=function(){return w(function(n){return O(n)&&n>0})},V=function(){return w(function(n){return O(n)&&n<0})},$=function n(t){return Object.assign(t,{between:function(e,r){return n(d(t,L(e,r)))},lt:function(e){return n(d(t,R(e)))},gt:function(e){return n(d(t,U(e)))},lte:function(e){return n(d(t,C(e)))},gte:function(e){return n(d(t,F(e)))},positive:function(){return n(d(t,J()))},negative:function(){return n(d(t,V()))}})}(w(O)),q=h(w(function(n){return"boolean"==typeof n})),D=h(w(function(n){return"symbol"==typeof n})),G=h(w(function(n){return null==n})),H={__proto__:null,matcher:r,optional:g,array:v,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:p(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:d,union:y,not:b,when:w,select:S,any:B,_:I,string:x,between:E,lt:K,gt:T,lte:k,gte:P,int:_,finite:M,positive:W,negative:N,number:z,betweenBigInt:L,ltBigInt:R,gtBigInt:U,lteBigInt:C,gteBigInt:F,positiveBigInt:J,negativeBigInt:V,bigint:$,boolean:q,symbol:D,nullish:G,instanceOf:function(n){return h(w(function(n){return function(t){return t instanceof n}}(n)))},shape:function(n){return h(w(l(n)))},typed:function(){return{array:v,optional:g,intersection:d,union:y,not:b,select:S,when:w}}},Q={matched:!1},X=/*#__PURE__*/function(){function n(n,t){void 0===t&&(t=Q),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=[];3===e.length&&"function"==typeof e[1]?(u.push(e[0]),o.push(e[1])):e.length>2&&u.push.apply(u,e.slice(1,e.length-1));var c={},f=Boolean(u.some(function(n){return a(n,t.input,function(n,t){c[n]=t})})&&o.every(function(n){return n(t.input)}))?{matched:!0,value:r(Object.keys(c).length?i in c?c[i]:c:this.input,this.input)}:{matched:!1};return new n(this.input,f)},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)}:{matched:!1})},t.otherwise=function(n){return this.state.matched?this.state.value:n(this.input,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=H,n.Pattern=H,n.isMatching=l,n.match=function(n){return new X(n)}}); | ||
!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("@ts-pattern/matcher"),u=Symbol("@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,g=[],v=[],m=[],p=e(t.keys());!(h=p()).done;){var d=t[h.value];c(d)&&d[u]?m.push(d):m.length?v.push(d):g.push(d)}if(m.length){if(m.length>1)throw new Error("Pattern error: Using `...P.array(...)` several time 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],a)})&&v.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+".")}var h=function(n){return Object.assign(n,{optional:function(){return g(n)},and:function(t){return p(n,t)},or:function(t){return d(n,t)},select:function(t){return void 0===t?b(n):b(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 v=function(n,t){for(var r,u=e(n);!(r=u()).done;)if(!t(r.value))return!1;return!0},m=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 d(){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 y(n){var t;return h(((t={})[r]=function(){return{match:function(t){return{matched:Boolean(n(t))}}}},t))}function b(){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 w(n){return"number"==typeof n}function S(n){return"string"==typeof n}function j(n){return"bigint"==typeof n}var A=h(y(function(n){return!0})),O=A,B=function n(t){return Object.assign(t,{startsWith:function(e){return n(p(t,(r=e,y(function(n){return S(n)&&n.startsWith(r)}))));var r},endsWith:function(e){return n(p(t,(r=e,y(function(n){return S(n)&&n.endsWith(r)}))));var r},minLength:function(e){return n(p(t,function(n){return y(function(t){return S(t)&&t.length>=n})}(e)))},maxLength:function(e){return n(p(t,function(n){return y(function(t){return S(t)&&t.length<=n})}(e)))},includes:function(e){return n(p(t,(r=e,y(function(n){return S(n)&&n.includes(r)}))));var r},regex:function(e){return n(p(t,(r=e,y(function(n){return S(n)&&Boolean(n.match(r))}))));var r}})}(y(S)),I=function(n,t){return y(function(e){return w(e)&&n<=e&&t>=e})},x=function(n){return y(function(t){return w(t)&&t<n})},E=function(n){return y(function(t){return w(t)&&t>n})},K=function(n){return y(function(t){return w(t)&&t<=n})},T=function(n){return y(function(t){return w(t)&&t>=n})},k=function(){return y(function(n){return w(n)&&Number.isInteger(n)})},P=function(){return y(function(n){return w(n)&&Number.isFinite(n)})},_=function(){return y(function(n){return w(n)&&n>0})},M=function(){return y(function(n){return w(n)&&n<0})},W=function n(t){return Object.assign(t,{between:function(e,r){return n(p(t,I(e,r)))},lt:function(e){return n(p(t,x(e)))},gt:function(e){return n(p(t,E(e)))},lte:function(e){return n(p(t,K(e)))},gte:function(e){return n(p(t,T(e)))},int:function(){return n(p(t,k()))},finite:function(){return n(p(t,P()))},positive:function(){return n(p(t,_()))},negative:function(){return n(p(t,M()))}})}(y(w)),N=function(n,t){return y(function(e){return j(e)&&n<=e&&t>=e})},z=function(n){return y(function(t){return j(t)&&t<n})},L=function(n){return y(function(t){return j(t)&&t>n})},R=function(n){return y(function(t){return j(t)&&t<=n})},U=function(n){return y(function(t){return j(t)&&t>=n})},C=function(){return y(function(n){return j(n)&&n>0})},F=function(){return y(function(n){return j(n)&&n<0})},J=function n(t){return Object.assign(t,{between:function(e,r){return n(p(t,N(e,r)))},lt:function(e){return n(p(t,z(e)))},gt:function(e){return n(p(t,L(e)))},lte:function(e){return n(p(t,R(e)))},gte:function(e){return n(p(t,U(e)))},positive:function(){return n(p(t,C()))},negative:function(){return n(p(t,F()))}})}(y(j)),V=h(y(function(n){return"boolean"==typeof n})),$=h(y(function(n){return"symbol"==typeof n})),q=h(y(function(n){return null==n})),D={__proto__:null,matcher:r,optional:g,array:function n(){var t,e=[].slice.call(arguments);return h(((t={})[r]=function(){return{match:function(n){if(!Array.isArray(n))return{matched:!1};if(0===e.length)return{matched:!0};var t=e[0],r={};if(0===n.length)return f(t).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(t,n,u)}),selections:r}},getSelectionKeys:function(){return 0===e.length?[]:f(e[0])}}},t[Symbol.iterator]=function(){/*#__PURE__*/return regeneratorRuntime.mark(function t(){var r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,Object.assign(0===e.length?n():n(e[0]),((r={})[u]=!0,r));case 2:case"end":return t.stop()}},t)})()},t))},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:v(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:m(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:d,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:y,select:b,any:A,_:O,string:B,between:I,lt:x,gt:E,lte:K,gte:T,int:k,finite:P,positive:_,negative:M,number:W,betweenBigInt:N,ltBigInt:z,gtBigInt:L,lteBigInt:R,gteBigInt:U,positiveBigInt:C,negativeBigInt:F,bigint:J,boolean:V,symbol:$,nullish:q,instanceOf:function(n){return h(y(function(n){return function(t){return t instanceof n}}(n)))},shape:function(n){return h(y(l(n)))}},G={matched:!1},H=/*#__PURE__*/function(){function n(n,t){void 0===t&&(t=G),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=[];3===e.length&&"function"==typeof e[1]?(u.push(e[0]),o.push(e[1])):e.length>2&&u.push.apply(u,e.slice(1,e.length-1));var c={},f=Boolean(u.some(function(n){return a(n,t.input,function(n,t){c[n]=t})})&&o.every(function(n){return n(t.input)}))?{matched:!0,value:r(Object.keys(c).length?i in c?c[i]:c:this.input,this.input)}:{matched:!1};return new n(this.input,f)},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)}:{matched:!1})},t.otherwise=function(n){return this.state.matched?this.state.value:n(this.input,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=D,n.Pattern=D,n.isMatching=l,n.match=function(n){return new H(n)}}); | ||
//# sourceMappingURL=index.umd.js.map |
@@ -10,3 +10,3 @@ import { Match } from './types/Match.js'; | ||
* | ||
* [Read documentation for `match` on GitHub](https://github.com/gvergnaud/ts-pattern#match) | ||
* [Read the documentation for `match` on GitHub](https://github.com/gvergnaud/ts-pattern#match) | ||
* | ||
@@ -13,0 +13,0 @@ * @example |
import * as symbols from './internals/symbols.js'; | ||
import { matcher } from './internals/symbols.js'; | ||
import { ExtractPreciseValue } from './types/ExtractPreciseValue.js'; | ||
import { Fn, GuardFunction } from './types/helpers.js'; | ||
import { Fn } from './types/helpers.js'; | ||
import { InvertPattern } from './types/InvertPattern.js'; | ||
@@ -44,3 +44,3 @@ import { Pattern, UnknownPattern, OptionalP, ArrayP, MapP, SetP, AndP, OrP, NotP, GuardP, SelectP, AnonymousSelectP, GuardExcludeP, CustomP, Matcher } from './types/Pattern.js'; | ||
* | ||
* [Read 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) | ||
* | ||
@@ -58,3 +58,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -70,3 +70,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -91,3 +91,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -106,3 +106,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -121,3 +121,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -138,3 +138,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -175,3 +175,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -196,3 +196,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -211,3 +211,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -224,3 +224,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -238,3 +238,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -260,3 +260,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -272,3 +272,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -285,3 +285,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -296,3 +296,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -307,3 +307,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -318,3 +318,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -329,3 +329,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -340,3 +340,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -352,3 +352,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -364,3 +364,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -375,3 +375,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -386,3 +386,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -397,3 +397,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -408,3 +408,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -419,3 +419,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -430,3 +430,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -441,3 +441,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -452,3 +452,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -465,3 +465,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -476,3 +476,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -487,3 +487,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -498,3 +498,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -509,3 +509,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -520,3 +520,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -531,3 +531,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -542,3 +542,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -553,3 +553,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -565,3 +565,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -577,3 +577,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -588,3 +588,3 @@ * @example | ||
* | ||
* [Read 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#bigintlt) | ||
* | ||
@@ -599,3 +599,3 @@ * @example | ||
* | ||
* [Read 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#bigintgt) | ||
* | ||
@@ -610,3 +610,3 @@ * @example | ||
* | ||
* [Read 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#bigintlte) | ||
* | ||
@@ -621,3 +621,3 @@ * @example | ||
* | ||
* [Read documentation for `P.bigint.gte` on GitHub](https://github.com/gvergnaud/ts-pattern#Pbigintgte) | ||
* [Read the documentation for `P.bigint.gte` on GitHub](https://github.com/gvergnaud/ts-pattern#Pbigintgte) | ||
* | ||
@@ -632,3 +632,3 @@ * @example | ||
* | ||
* [Read documentation for `P.bigint.positive` on GitHub](https://github.com/gvergnaud/ts-pattern#Pbigintpositive) | ||
* [Read the documentation for `P.bigint.positive` on GitHub](https://github.com/gvergnaud/ts-pattern#Pbigintpositive) | ||
* | ||
@@ -643,3 +643,3 @@ * @example | ||
* | ||
* [Read documentation for `P.bigint.negative` on GitHub](https://github.com/gvergnaud/ts-pattern#Pbigintnegative) | ||
* [Read the documentation for `P.bigint.negative` on GitHub](https://github.com/gvergnaud/ts-pattern#Pbigintnegative) | ||
* | ||
@@ -656,3 +656,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -667,3 +667,3 @@ * @example | ||
* | ||
* [Read 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#bigintlt) | ||
* | ||
@@ -678,3 +678,3 @@ * @example | ||
* | ||
* [Read 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#bigintgt) | ||
* | ||
@@ -689,3 +689,3 @@ * @example | ||
* | ||
* [Read 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#bigintlte) | ||
* | ||
@@ -700,3 +700,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -711,3 +711,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -722,3 +722,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -734,3 +734,3 @@ * @example | ||
* | ||
* [Read 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#bigint-wildcard) | ||
* | ||
@@ -744,3 +744,3 @@ * @example | ||
* | ||
* [Read documentation for `P.boolean` on GitHub](https://github.com/gvergnaud/ts-pattern#boolean-wildcard) | ||
* [Read the documentation for `P.boolean` on GitHub](https://github.com/gvergnaud/ts-pattern#boolean-wildcard) | ||
* | ||
@@ -754,3 +754,3 @@ * @example | ||
* | ||
* [Read documentation for `P.symbol` on GitHub](https://github.com/gvergnaud/ts-pattern#symbol-wildcard) | ||
* [Read the documentation for `P.symbol` on GitHub](https://github.com/gvergnaud/ts-pattern#symbol-wildcard) | ||
* | ||
@@ -764,3 +764,3 @@ * @example | ||
* | ||
* [Read documentation for `P.nullish` on GitHub](https://github.com/gvergnaud/ts-pattern#nullish-wildcard) | ||
* [Read the documentation for `P.nullish` on GitHub](https://github.com/gvergnaud/ts-pattern#nullish-wildcard) | ||
* | ||
@@ -774,3 +774,3 @@ * @example | ||
* | ||
* [Read 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) | ||
* | ||
@@ -782,6 +782,6 @@ * @example | ||
/** | ||
* `P.shape(somePattern)` allows for calling methods like `.optional()` or `.select()` | ||
* `P.shape(somePattern)` lets you call methods like `.optional()`, `.and`, `.or` and `.select()` | ||
* On structural patterns, like objects and arrays. | ||
* | ||
* [Read 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) | ||
* | ||
@@ -797,26 +797,1 @@ * @example | ||
export declare function shape<input, p extends Pattern<input>>(pattern: p): Chainable<GuardP<input, InvertPattern<p, input>>>; | ||
/** | ||
* `P.typed<SomeType>()` is a way to set the input type this | ||
* pattern should match on. | ||
* | ||
* It returns all utility functions to create patterns, | ||
* Like `array`, `union`, `intersection`, etc. | ||
* | ||
* [Read documentation for `P.typed` on GitHub](https://github.com/gvergnaud/ts-pattern#Ptyped) | ||
* | ||
* @example | ||
* .with( | ||
* P.typed<string | number[]>().array(P.string), | ||
* (arrayOfString) => arrayOfString.join(', ') | ||
* ) | ||
*/ | ||
export declare function typed<input>(): { | ||
array<const p extends Pattern<UnwrapArray<input>>>(pattern: p): Chainable<ArrayP<input, p>>; | ||
optional<const p extends Pattern<input>>(pattern: p): Chainable<OptionalP<input, p>>; | ||
intersection<const ps extends readonly [Pattern<input>, ...Pattern<input>[]]>(...patterns: ps): Chainable<AndP<input, ps>>; | ||
union<const ps extends readonly [Pattern<input>, ...Pattern<input>[]]>(...patterns: ps): Chainable<OrP<input, ps>>; | ||
not<const p extends Pattern<input>>(pattern: p): Chainable<NotP<input, p>>; | ||
when<const narrowed extends input = never>(predicate: GuardFunction<input, narrowed>): GuardP<input, narrowed>; | ||
select<const pattern extends Pattern<input>>(pattern: pattern): Chainable<SelectP<symbols.anonymousSelectKey, input, pattern>>; | ||
select<const p extends Pattern<input>, const k extends string>(key: k, pattern: p): Chainable<SelectP<k, input, p>>; | ||
}; |
@@ -64,3 +64,3 @@ export type ValueOf<a> = a extends readonly any[] ? a[number] : a[keyof a]; | ||
readonly [k in AllKeys<a>]: a extends any ? k extends keyof a ? a[k] : never : never; | ||
}; | ||
} | never; | ||
export type IsFixedSizeTuple<a extends readonly any[]> = IsLiteral<Length<a>>; | ||
@@ -67,0 +67,0 @@ export type IsTuple<a> = a extends readonly [] | readonly [any, ...any] | readonly [...any, any] ? true : false; |
@@ -8,8 +8,8 @@ import type * as symbols from '../internals/symbols.js'; | ||
export type PickReturnValue<a, b> = a extends symbols.unset ? b : a; | ||
type NonExhaustiveError<i> = { | ||
interface NonExhaustiveError<i> { | ||
__nonExhaustive: never; | ||
} & i; | ||
type TSPatternError<i> = { | ||
} | ||
interface TSPatternError<i> { | ||
__nonExhaustive: never; | ||
} & i; | ||
} | ||
/** | ||
@@ -24,3 +24,3 @@ * #### Match | ||
* | ||
* [Read documentation for `.with()` on GitHub](https://github.com/gvergnaud/ts-pattern#with) | ||
* [Read the documentation for `.with()` on GitHub](https://github.com/gvergnaud/ts-pattern#with) | ||
**/ | ||
@@ -79,3 +79,3 @@ with<const p extends Pattern<i>, c, value extends MatchedValue<i, InvertPattern<p, i>>, excluded = InvertPatternForExclude<p, value>>( | ||
* | ||
* [Read documentation for `.when()` on GitHub](https://github.com/gvergnaud/ts-pattern#when) | ||
* [Read the documentation for `.when()` on GitHub](https://github.com/gvergnaud/ts-pattern#when) | ||
**/ | ||
@@ -92,3 +92,3 @@ when<pred extends (value: i) => unknown, c, value extends GuardValue<pred>>(predicate: pred, handler: (value: value) => PickReturnValue<o, c>): pred extends (value: any) => value is infer narrowed ? Match<Exclude<i, narrowed>, o, [ | ||
* | ||
* [Read documentation for `.otherwise()` on GitHub](https://github.com/gvergnaud/ts-pattern#otherwise) | ||
* [Read the documentation for `.otherwise()` on GitHub](https://github.com/gvergnaud/ts-pattern#otherwise) | ||
* | ||
@@ -104,3 +104,3 @@ **/ | ||
* | ||
* [Read documentation for `.exhaustive()` on GitHub](https://github.com/gvergnaud/ts-pattern#exhaustive) | ||
* [Read the documentation for `.exhaustive()` on GitHub](https://github.com/gvergnaud/ts-pattern#exhaustive) | ||
* | ||
@@ -116,3 +116,3 @@ * */ | ||
* | ||
* [Read documentation for `.returnType()` on GitHub](https://github.com/gvergnaud/ts-pattern#returnType) | ||
* [Read the documentation for `.returnType()` on GitHub](https://github.com/gvergnaud/ts-pattern#returnType) | ||
* */ | ||
@@ -119,0 +119,0 @@ returnType: [inferredOutput] extends [never] ? <output>() => Match<i, output, handledCases> : TSPatternError<'calling `.returnType<T>()` is only allowed directly after `match(...)`.'>; |
@@ -27,5 +27,6 @@ import type * as symbols from '../internals/symbols.js'; | ||
} | ||
type PatternMatcher<input> = Matcher<input, unknown, any, any>; | ||
export type MatchedValue<a, invpattern> = WithDefault<ExtractPreciseValue<a, invpattern>, a>; | ||
export type AnyMatcher = Matcher<any, any, any, any, any>; | ||
type UnknownMatcher = Matcher<unknown, unknown, any, any>; | ||
type UnknownMatcher = PatternMatcher<unknown>; | ||
export type CustomP<input, pattern, narrowedOrFn> = Matcher<input, pattern, 'custom', None, narrowedOrFn>; | ||
@@ -55,3 +56,3 @@ export type ArrayP<input, p> = Matcher<input, p, 'array'>; | ||
* | ||
* [Read documentation for `P.Pattern` on GitHub](https://github.com/gvergnaud/ts-pattern#patterns) | ||
* [Read the documentation for `P.Pattern` on GitHub](https://github.com/gvergnaud/ts-pattern#patterns) | ||
* | ||
@@ -61,7 +62,8 @@ * @example | ||
*/ | ||
export type Pattern<a> = unknown extends a ? UnknownPattern : PatternInternal<a>; | ||
export type PatternInternal<a, objs = Exclude<a, Primitives | Map<any, any> | Set<any> | readonly any[]>, arrays = Extract<a, readonly any[]>, primitives = Extract<a, Primitives>> = Matcher<a, unknown, any, any> | ([objs] extends [never] ? never : ObjectPattern<MergeUnion<objs>>) | ([arrays] extends [never] ? never : ArrayPattern<arrays>) | primitives; | ||
export type Pattern<a> = unknown extends a ? UnknownPattern : KnownPattern<a>; | ||
type KnownPattern<a> = KnownPatternInternal<a>; | ||
type KnownPatternInternal<a, objs = Exclude<a, Primitives | Map<any, any> | Set<any> | readonly any[]>, arrays = Extract<a, readonly any[]>, primitives = Exclude<a, object>> = primitives | PatternMatcher<a> | ([objs] extends [never] ? never : ObjectPattern<MergeUnion<objs>>) | ([arrays] extends [never] ? never : ArrayPattern<arrays>); | ||
type ObjectPattern<a> = { | ||
readonly [k in keyof a]?: Pattern<Exclude<a[k], undefined>>; | ||
}; | ||
readonly [k in keyof a]?: Pattern<a[k]>; | ||
} | never; | ||
type ArrayPattern<a> = a extends readonly (infer i)[] ? a extends readonly [any, ...any] ? { | ||
@@ -68,0 +70,0 @@ readonly [index in keyof a]: Pattern<a[index]>; |
{ | ||
"name": "ts-pattern", | ||
"version": "5.0.0-rc.5", | ||
"version": "5.0.0-rc.6", | ||
"description": " The exhaustive Pattern Matching library for TypeScript.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
458612
1594