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 4.2.2 to 4.2.3-test.0

dist/index.js

0

dist/index.d.ts

@@ -0,0 +0,0 @@ import * as Pattern from './patterns';

2

dist/index.module.js

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

var n=Symbol("@ts-pattern/matcher"),t="@ts-pattern/anonymous-select-key",e=function(n){return Boolean(n&&"object"==typeof n)},r=function(t){return t&&!!t[n]},u=function t(u,i,c){if(e(u)){if(r(u)){var o=u[n]().match(i),a=o.matched,f=o.selections;return a&&f&&Object.keys(f).forEach(function(n){return c(n,f[n])}),a}if(!e(i))return!1;if(Array.isArray(u))return!!Array.isArray(i)&&u.length===i.length&&u.every(function(n,e){return t(n,i[e],c)});if(u instanceof Map)return i instanceof Map&&Array.from(u.keys()).every(function(n){return t(u.get(n),i.get(n),c)});if(u instanceof Set){if(!(i instanceof Set))return!1;if(0===u.size)return 0===i.size;if(1===u.size){var s=Array.from(u.values())[0];return r(s)?Array.from(i.values()).every(function(n){return t(s,n,c)}):i.has(s)}return Array.from(u.values()).every(function(n){return i.has(n)})}return Object.keys(u).every(function(e){var o,a=u[e];return(e in i||r(o=a)&&"optional"===o[n]().matcherType)&&t(a,i[e],c)})}return Object.is(i,u)},i=function t(u){var i,o,a;return e(u)?r(u)?null!=(i=null==(o=(a=u[n]()).getSelectionKeys)?void 0:o.call(a))?i:[]:Array.isArray(u)?c(u,t):c(Object.values(u),t):[]},c=function(n,t){return n.reduce(function(n,e){return n.concat(t(e))},[])};function o(t){var e;return(e={})[n]=function(){return{match:function(n){var e={},r=function(n,t){e[n]=t};return void 0===n?(i(t).forEach(function(n){return r(n,void 0)}),{matched:!0,selections:e}):{matched:u(t,n,r),selections:e}},getSelectionKeys:function(){return i(t)},matcherType:"optional"}},e}function a(t){var e;return(e={})[n]=function(){return{match:function(n){if(!Array.isArray(n))return{matched:!1};var e={};if(0===n.length)return i(t).forEach(function(n){e[n]=[]}),{matched:!0,selections:e};var r=function(n,t){e[n]=(e[n]||[]).concat([t])};return{matched:n.every(function(n){return u(t,n,r)}),selections:e}},getSelectionKeys:function(){return i(t)}}},e}function f(){var t,e=[].slice.call(arguments);return(t={})[n]=function(){return{match:function(n){var t={},r=function(n,e){t[n]=e};return{matched:e.every(function(t){return u(t,n,r)}),selections:t}},getSelectionKeys:function(){return c(e,i)},matcherType:"and"}},t}function s(){var t,e=[].slice.call(arguments);return(t={})[n]=function(){return{match:function(n){var t={},r=function(n,e){t[n]=e};return c(e,i).forEach(function(n){return r(n,void 0)}),{matched:e.some(function(t){return u(t,n,r)}),selections:t}},getSelectionKeys:function(){return c(e,i)},matcherType:"or"}},t}function l(t){var e;return(e={})[n]=function(){return{match:function(n){return{matched:!u(t,n,function(){})}},getSelectionKeys:function(){return[]},matcherType:"not"}},e}function h(t){var e;return(e={})[n]=function(){return{match:function(n){return{matched:Boolean(t(n))}}}},e}function v(){var e,r=[].slice.call(arguments),c="string"==typeof r[0]?r[0]:void 0,o=2===r.length?r[1]:"string"==typeof r[0]?void 0:r[0];return(e={})[n]=function(){return{match:function(n){var e,r=((e={})[null!=c?c:t]=n,e);return{matched:void 0===o||u(o,n,function(n,t){r[n]=t}),selections:r}},getSelectionKeys:function(){return[null!=c?c:t].concat(void 0===o?[]:i(o))}}},e}var y=h(function(n){return!0}),m=y,d=h(function(n){return"string"==typeof n}),g=h(function(n){return"number"==typeof n}),p=h(function(n){return"boolean"==typeof n}),b=h(function(n){return"bigint"==typeof n}),w=h(function(n){return"symbol"==typeof n}),A=h(function(n){return null==n}),S={__proto__:null,optional:o,array:a,intersection:f,union:s,not:l,when:h,select:v,any:y,_:m,string:d,number:g,boolean:p,bigint:b,symbol:w,nullish:A,instanceOf:function(n){return h(function(n){return function(t){return t instanceof n}}(n))},typed:function(){return{array:a,optional:o,intersection:f,union:s,not:l,select:v,when:h}}};function K(n){return new O(n,[])}var O=/*#__PURE__*/function(){function n(n,t){this.value=void 0,this.cases=void 0,this.value=n,this.cases=t}var e=n.prototype;return e.with=function(){var e=[].slice.call(arguments),r=e[e.length-1],i=[e[0]],c=[];return 3===e.length&&"function"==typeof e[1]?(i.push(e[0]),c.push(e[1])):e.length>2&&i.push.apply(i,e.slice(1,e.length-1)),new n(this.value,this.cases.concat([{match:function(n){var e={},r=Boolean(i.some(function(t){return u(t,n,function(n,t){e[n]=t})})&&c.every(function(t){return t(n)}));return{matched:r,value:r&&Object.keys(e).length?t in e?e[t]:e:n}},handler:r}]))},e.when=function(t,e){return new n(this.value,this.cases.concat([{match:function(n){return{matched:Boolean(t(n)),value:n}},handler:e}]))},e.otherwise=function(t){return new n(this.value,this.cases.concat([{match:function(n){return{matched:!0,value:n}},handler:t}])).run()},e.exhaustive=function(){return this.run()},e.run=function(){for(var n=this.value,t=void 0,e=0;e<this.cases.length;e++){var r=this.cases[e],u=r.match(this.value);if(u.matched){n=u.value,t=r.handler;break}}if(!t){var i;try{i=JSON.stringify(this.value)}catch(n){i=this.value}throw new Error("Pattern matching error: no pattern matches value "+i)}return t(n,this.value)},n}();function j(){var n=[].slice.call(arguments);if(1===n.length){var t=n[0];return function(n){return u(t,n,function(){})}}if(2===n.length){var e=n,r=e[0],i=e[1];return u(r,i,function(){})}throw new Error("isMatching wasn't given the right number of arguments: expected 1 or 2, received "+n.length+".")}export{S as P,S as Pattern,j as isMatching,K as match};
var n=Symbol("@ts-pattern/matcher"),t="@ts-pattern/anonymous-select-key",e=function(n){return Boolean(n&&"object"==typeof n)},r=function(t){return t&&!!t[n]},u=function t(u,i,c){if(e(u)){if(r(u)){var o=u[n]().match(i),a=o.matched,f=o.selections;return a&&f&&Object.keys(f).forEach(function(n){return c(n,f[n])}),a}if(!e(i))return!1;if(Array.isArray(u))return!!Array.isArray(i)&&u.length===i.length&&u.every(function(n,e){return t(n,i[e],c)});if(u instanceof Map)return i instanceof Map&&Array.from(u.keys()).every(function(n){return t(u.get(n),i.get(n),c)});if(u instanceof Set){if(!(i instanceof Set))return!1;if(0===u.size)return 0===i.size;if(1===u.size){var s=Array.from(u.values())[0];return r(s)?Array.from(i.values()).every(function(n){return t(s,n,c)}):i.has(s)}return Array.from(u.values()).every(function(n){return i.has(n)})}return Object.keys(u).every(function(e){var o,a=u[e];return(e in i||r(o=a)&&"optional"===o[n]().matcherType)&&t(a,i[e],c)})}return Object.is(i,u)},i=function t(u){var i,o,a;return e(u)?r(u)?null!=(i=null==(o=(a=u[n]()).getSelectionKeys)?void 0:o.call(a))?i:[]:Array.isArray(u)?c(u,t):c(Object.values(u),t):[]},c=function(n,t){return n.reduce(function(n,e){return n.concat(t(e))},[])};function o(t){var e;return(e={})[n]=function(){return{match:function(n){var e={},r=function(n,t){e[n]=t};return void 0===n?(i(t).forEach(function(n){return r(n,void 0)}),{matched:!0,selections:e}):{matched:u(t,n,r),selections:e}},getSelectionKeys:function(){return i(t)},matcherType:"optional"}},e}function a(t){var e;return(e={})[n]=function(){return{match:function(n){if(!Array.isArray(n))return{matched:!1};var e={};if(0===n.length)return i(t).forEach(function(n){e[n]=[]}),{matched:!0,selections:e};var r=function(n,t){e[n]=(e[n]||[]).concat([t])};return{matched:n.every(function(n){return u(t,n,r)}),selections:e}},getSelectionKeys:function(){return i(t)}}},e}function f(){var t,e=[].slice.call(arguments);return(t={})[n]=function(){return{match:function(n){var t={},r=function(n,e){t[n]=e};return{matched:e.every(function(t){return u(t,n,r)}),selections:t}},getSelectionKeys:function(){return c(e,i)},matcherType:"and"}},t}function s(){var t,e=[].slice.call(arguments);return(t={})[n]=function(){return{match:function(n){var t={},r=function(n,e){t[n]=e};return c(e,i).forEach(function(n){return r(n,void 0)}),{matched:e.some(function(t){return u(t,n,r)}),selections:t}},getSelectionKeys:function(){return c(e,i)},matcherType:"or"}},t}function l(t){var e;return(e={})[n]=function(){return{match:function(n){return{matched:!u(t,n,function(){})}},getSelectionKeys:function(){return[]},matcherType:"not"}},e}function h(t){var e;return(e={})[n]=function(){return{match:function(n){return{matched:Boolean(t(n))}}}},e}function v(){var e,r=[].slice.call(arguments),c="string"==typeof r[0]?r[0]:void 0,o=2===r.length?r[1]:"string"==typeof r[0]?void 0:r[0];return(e={})[n]=function(){return{match:function(n){var e,r=((e={})[null!=c?c:t]=n,e);return{matched:void 0===o||u(o,n,function(n,t){r[n]=t}),selections:r}},getSelectionKeys:function(){return[null!=c?c:t].concat(void 0===o?[]:i(o))}}},e}var y=h(function(n){return!0}),m=y,d=h(function(n){return"string"==typeof n}),g=h(function(n){return"number"==typeof n}),p=h(function(n){return"boolean"==typeof n}),b=h(function(n){return"bigint"==typeof n}),w=h(function(n){return"symbol"==typeof n}),A=h(function(n){return null==n}),S={__proto__:null,optional:o,array:a,intersection:f,union:s,not:l,when:h,select:v,any:y,_:m,string:d,number:g,boolean:p,bigint:b,symbol:w,nullish:A,instanceOf:function(n){return h(function(n){return function(t){return t instanceof n}}(n))},typed:function(){return{array:a,optional:o,intersection:f,union:s,not:l,select:v,when:h}}};function K(n){return new O(n,[])}var O=/*#__PURE__*/function(){function n(n,t){this.value=void 0,this.cases=void 0,this.value=n,this.cases=t}var e=n.prototype;return e.with=function(){var e=[].slice.call(arguments),r=e[e.length-1],i=[e[0]],c=[];return 3===e.length&&"function"==typeof e[1]?(i.push(e[0]),c.push(e[1])):e.length>2&&i.push.apply(i,e.slice(1,e.length-1)),new n(this.value,this.cases.concat([{match:function(n){var e={},r=Boolean(i.some(function(t){return u(t,n,function(n,t){e[n]=t})})&&c.every(function(t){return t(n)}));return{matched:r,value:r&&Object.keys(e).length?t in e?e[t]:e:n}},handler:r}]))},e.when=function(t,e){return new n(this.value,this.cases.concat([{match:function(n){return{matched:Boolean(t(n)),value:n}},handler:e}]))},e.otherwise=function(t){return new n(this.value,this.cases.concat([{match:function(n){return{matched:!0,value:n}},handler:t}])).run()},e.exhaustive=function(){return this.run()},e.run=function(){for(var n=this.value,t=void 0,e=0;e<this.cases.length;e++){var r=this.cases[e],u=r.match(this.value);if(u.matched){n=u.value,t=r.handler;break}}if(!t){var i;try{i=JSON.stringify(this.value)}catch(n){i=this.value}throw new Error("Pattern matching error: no pattern matches value "+i)}return t(n,this.value)},n}();function j(){var n=[].slice.call(arguments);if(1===n.length){var t=n[0];return function(n){return u(t,n,function(){})}}if(2===n.length)return u(n[0],n[1],function(){});throw new Error("isMatching wasn't given the right number of arguments: expected 1 or 2, received "+n.length+".")}export{S as P,S as Pattern,j as isMatching,K as match};
//# sourceMappingURL=index.module.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){var t=Symbol("@ts-pattern/matcher"),e="@ts-pattern/anonymous-select-key",r=function(n){return Boolean(n&&"object"==typeof n)},u=function(n){return n&&!!n[t]},i=function n(e,i,o){if(r(e)){if(u(e)){var c=e[t]().match(i),a=c.matched,f=c.selections;return a&&f&&Object.keys(f).forEach(function(n){return o(n,f[n])}),a}if(!r(i))return!1;if(Array.isArray(e))return!!Array.isArray(i)&&e.length===i.length&&e.every(function(t,e){return n(t,i[e],o)});if(e instanceof Map)return i instanceof Map&&Array.from(e.keys()).every(function(t){return n(e.get(t),i.get(t),o)});if(e instanceof Set){if(!(i instanceof Set))return!1;if(0===e.size)return 0===i.size;if(1===e.size){var s=Array.from(e.values())[0];return u(s)?Array.from(i.values()).every(function(t){return n(s,t,o)}):i.has(s)}return Array.from(e.values()).every(function(n){return i.has(n)})}return Object.keys(e).every(function(r){var c,a=e[r];return(r in i||u(c=a)&&"optional"===c[t]().matcherType)&&n(a,i[r],o)})}return Object.is(i,e)},o=function n(e){var i,o,a;return r(e)?u(e)?null!=(i=null==(o=(a=e[t]()).getSelectionKeys)?void 0:o.call(a))?i:[]:Array.isArray(e)?c(e,n):c(Object.values(e),n):[]},c=function(n,t){return n.reduce(function(n,e){return n.concat(t(e))},[])};function a(n){var e;return(e={})[t]=function(){return{match:function(t){var e={},r=function(n,t){e[n]=t};return void 0===t?(o(n).forEach(function(n){return r(n,void 0)}),{matched:!0,selections:e}):{matched:i(n,t,r),selections:e}},getSelectionKeys:function(){return o(n)},matcherType:"optional"}},e}function f(n){var e;return(e={})[t]=function(){return{match:function(t){if(!Array.isArray(t))return{matched:!1};var e={};if(0===t.length)return o(n).forEach(function(n){e[n]=[]}),{matched:!0,selections:e};var r=function(n,t){e[n]=(e[n]||[]).concat([t])};return{matched:t.every(function(t){return i(n,t,r)}),selections:e}},getSelectionKeys:function(){return o(n)}}},e}function s(){var n,e=[].slice.call(arguments);return(n={})[t]=function(){return{match:function(n){var t={},r=function(n,e){t[n]=e};return{matched:e.every(function(t){return i(t,n,r)}),selections:t}},getSelectionKeys:function(){return c(e,o)},matcherType:"and"}},n}function l(){var n,e=[].slice.call(arguments);return(n={})[t]=function(){return{match:function(n){var t={},r=function(n,e){t[n]=e};return c(e,o).forEach(function(n){return r(n,void 0)}),{matched:e.some(function(t){return i(t,n,r)}),selections:t}},getSelectionKeys:function(){return c(e,o)},matcherType:"or"}},n}function h(n){var e;return(e={})[t]=function(){return{match:function(t){return{matched:!i(n,t,function(){})}},getSelectionKeys:function(){return[]},matcherType:"not"}},e}function v(n){var e;return(e={})[t]=function(){return{match:function(t){return{matched:Boolean(n(t))}}}},e}function y(){var n,r=[].slice.call(arguments),u="string"==typeof r[0]?r[0]:void 0,c=2===r.length?r[1]:"string"==typeof r[0]?void 0:r[0];return(n={})[t]=function(){return{match:function(n){var t,r=((t={})[null!=u?u:e]=n,t);return{matched:void 0===c||i(c,n,function(n,t){r[n]=t}),selections:r}},getSelectionKeys:function(){return[null!=u?u:e].concat(void 0===c?[]:o(c))}}},n}var m=v(function(n){return!0}),d=m,p=v(function(n){return"string"==typeof n}),g=v(function(n){return"number"==typeof n}),b=v(function(n){return"boolean"==typeof n}),w=v(function(n){return"bigint"==typeof n}),A=v(function(n){return"symbol"==typeof n}),S=v(function(n){return null==n}),j={__proto__:null,optional:a,array:f,intersection:s,union:l,not:h,when:v,select:y,any:m,_:d,string:p,number:g,boolean:b,bigint:w,symbol:A,nullish:S,instanceOf:function(n){return v(function(n){return function(t){return t instanceof n}}(n))},typed:function(){return{array:f,optional:a,intersection:s,union:l,not:h,select:y,when:v}}},K=/*#__PURE__*/function(){function n(n,t){this.value=void 0,this.cases=void 0,this.value=n,this.cases=t}var t=n.prototype;return t.with=function(){var t=[].slice.call(arguments),r=t[t.length-1],u=[t[0]],o=[];return 3===t.length&&"function"==typeof t[1]?(u.push(t[0]),o.push(t[1])):t.length>2&&u.push.apply(u,t.slice(1,t.length-1)),new n(this.value,this.cases.concat([{match:function(n){var t={},r=Boolean(u.some(function(e){return i(e,n,function(n,e){t[n]=e})})&&o.every(function(t){return t(n)}));return{matched:r,value:r&&Object.keys(t).length?e in t?t[e]:t:n}},handler:r}]))},t.when=function(t,e){return new n(this.value,this.cases.concat([{match:function(n){return{matched:Boolean(t(n)),value:n}},handler:e}]))},t.otherwise=function(t){return new n(this.value,this.cases.concat([{match:function(n){return{matched:!0,value:n}},handler:t}])).run()},t.exhaustive=function(){return this.run()},t.run=function(){for(var n=this.value,t=void 0,e=0;e<this.cases.length;e++){var r=this.cases[e],u=r.match(this.value);if(u.matched){n=u.value,t=r.handler;break}}if(!t){var i;try{i=JSON.stringify(this.value)}catch(n){i=this.value}throw new Error("Pattern matching error: no pattern matches value "+i)}return t(n,this.value)},n}();n.P=j,n.Pattern=j,n.isMatching=function(){var n=[].slice.call(arguments);if(1===n.length){var t=n[0];return function(n){return i(t,n,function(){})}}if(2===n.length){var e=n,r=e[0],u=e[1];return i(r,u,function(){})}throw new Error("isMatching wasn't given the right number of arguments: expected 1 or 2, received "+n.length+".")},n.match=function(n){return new K(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){var t=Symbol("@ts-pattern/matcher"),e="@ts-pattern/anonymous-select-key",r=function(n){return Boolean(n&&"object"==typeof n)},u=function(n){return n&&!!n[t]},i=function n(e,i,o){if(r(e)){if(u(e)){var c=e[t]().match(i),a=c.matched,f=c.selections;return a&&f&&Object.keys(f).forEach(function(n){return o(n,f[n])}),a}if(!r(i))return!1;if(Array.isArray(e))return!!Array.isArray(i)&&e.length===i.length&&e.every(function(t,e){return n(t,i[e],o)});if(e instanceof Map)return i instanceof Map&&Array.from(e.keys()).every(function(t){return n(e.get(t),i.get(t),o)});if(e instanceof Set){if(!(i instanceof Set))return!1;if(0===e.size)return 0===i.size;if(1===e.size){var s=Array.from(e.values())[0];return u(s)?Array.from(i.values()).every(function(t){return n(s,t,o)}):i.has(s)}return Array.from(e.values()).every(function(n){return i.has(n)})}return Object.keys(e).every(function(r){var c,a=e[r];return(r in i||u(c=a)&&"optional"===c[t]().matcherType)&&n(a,i[r],o)})}return Object.is(i,e)},o=function n(e){var i,o,a;return r(e)?u(e)?null!=(i=null==(o=(a=e[t]()).getSelectionKeys)?void 0:o.call(a))?i:[]:Array.isArray(e)?c(e,n):c(Object.values(e),n):[]},c=function(n,t){return n.reduce(function(n,e){return n.concat(t(e))},[])};function a(n){var e;return(e={})[t]=function(){return{match:function(t){var e={},r=function(n,t){e[n]=t};return void 0===t?(o(n).forEach(function(n){return r(n,void 0)}),{matched:!0,selections:e}):{matched:i(n,t,r),selections:e}},getSelectionKeys:function(){return o(n)},matcherType:"optional"}},e}function f(n){var e;return(e={})[t]=function(){return{match:function(t){if(!Array.isArray(t))return{matched:!1};var e={};if(0===t.length)return o(n).forEach(function(n){e[n]=[]}),{matched:!0,selections:e};var r=function(n,t){e[n]=(e[n]||[]).concat([t])};return{matched:t.every(function(t){return i(n,t,r)}),selections:e}},getSelectionKeys:function(){return o(n)}}},e}function s(){var n,e=[].slice.call(arguments);return(n={})[t]=function(){return{match:function(n){var t={},r=function(n,e){t[n]=e};return{matched:e.every(function(t){return i(t,n,r)}),selections:t}},getSelectionKeys:function(){return c(e,o)},matcherType:"and"}},n}function l(){var n,e=[].slice.call(arguments);return(n={})[t]=function(){return{match:function(n){var t={},r=function(n,e){t[n]=e};return c(e,o).forEach(function(n){return r(n,void 0)}),{matched:e.some(function(t){return i(t,n,r)}),selections:t}},getSelectionKeys:function(){return c(e,o)},matcherType:"or"}},n}function h(n){var e;return(e={})[t]=function(){return{match:function(t){return{matched:!i(n,t,function(){})}},getSelectionKeys:function(){return[]},matcherType:"not"}},e}function v(n){var e;return(e={})[t]=function(){return{match:function(t){return{matched:Boolean(n(t))}}}},e}function y(){var n,r=[].slice.call(arguments),u="string"==typeof r[0]?r[0]:void 0,c=2===r.length?r[1]:"string"==typeof r[0]?void 0:r[0];return(n={})[t]=function(){return{match:function(n){var t,r=((t={})[null!=u?u:e]=n,t);return{matched:void 0===c||i(c,n,function(n,t){r[n]=t}),selections:r}},getSelectionKeys:function(){return[null!=u?u:e].concat(void 0===c?[]:o(c))}}},n}var m=v(function(n){return!0}),d=m,p=v(function(n){return"string"==typeof n}),g=v(function(n){return"number"==typeof n}),b=v(function(n){return"boolean"==typeof n}),w=v(function(n){return"bigint"==typeof n}),A=v(function(n){return"symbol"==typeof n}),S=v(function(n){return null==n}),j={__proto__:null,optional:a,array:f,intersection:s,union:l,not:h,when:v,select:y,any:m,_:d,string:p,number:g,boolean:b,bigint:w,symbol:A,nullish:S,instanceOf:function(n){return v(function(n){return function(t){return t instanceof n}}(n))},typed:function(){return{array:f,optional:a,intersection:s,union:l,not:h,select:y,when:v}}},K=/*#__PURE__*/function(){function n(n,t){this.value=void 0,this.cases=void 0,this.value=n,this.cases=t}var t=n.prototype;return t.with=function(){var t=[].slice.call(arguments),r=t[t.length-1],u=[t[0]],o=[];return 3===t.length&&"function"==typeof t[1]?(u.push(t[0]),o.push(t[1])):t.length>2&&u.push.apply(u,t.slice(1,t.length-1)),new n(this.value,this.cases.concat([{match:function(n){var t={},r=Boolean(u.some(function(e){return i(e,n,function(n,e){t[n]=e})})&&o.every(function(t){return t(n)}));return{matched:r,value:r&&Object.keys(t).length?e in t?t[e]:t:n}},handler:r}]))},t.when=function(t,e){return new n(this.value,this.cases.concat([{match:function(n){return{matched:Boolean(t(n)),value:n}},handler:e}]))},t.otherwise=function(t){return new n(this.value,this.cases.concat([{match:function(n){return{matched:!0,value:n}},handler:t}])).run()},t.exhaustive=function(){return this.run()},t.run=function(){for(var n=this.value,t=void 0,e=0;e<this.cases.length;e++){var r=this.cases[e],u=r.match(this.value);if(u.matched){n=u.value,t=r.handler;break}}if(!t){var i;try{i=JSON.stringify(this.value)}catch(n){i=this.value}throw new Error("Pattern matching error: no pattern matches value "+i)}return t(n,this.value)},n}();n.P=j,n.Pattern=j,n.isMatching=function(){var n=[].slice.call(arguments);if(1===n.length){var t=n[0];return function(n){return i(t,n,function(){})}}if(2===n.length)return i(n[0],n[1],function(){});throw new Error("isMatching wasn't given the right number of arguments: expected 1 or 2, received "+n.length+".")},n.match=function(n){return new K(n,[])}});
//# sourceMappingURL=index.umd.js.map

@@ -0,0 +0,0 @@ /**

@@ -16,8 +16,8 @@ /**

export declare const toExclude: unique symbol;
export type toExclude = typeof toExclude;
export declare type toExclude = typeof toExclude;
export declare const matcher: unique symbol;
export type matcher = typeof matcher;
export declare type matcher = typeof matcher;
export declare const unset: unique symbol;
export type unset = typeof unset;
export declare type unset = typeof unset;
export declare const anonymousSelectKey = "@ts-pattern/anonymous-select-key";
export type anonymousSelectKey = typeof anonymousSelectKey;
export declare type anonymousSelectKey = typeof anonymousSelectKey;

@@ -0,0 +0,0 @@ import { Pattern } from './types/Pattern';

@@ -0,0 +0,0 @@ import { Match } from './types/Match';

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

*/
export type infer<p extends Pattern<any>> = InvertPattern<p>;
export declare type infer<p extends Pattern<any>> = InvertPattern<p>;
/**

@@ -29,3 +29,3 @@ * `P.optional(subpattern)` takes a sub pattern and returns a pattern which matches if the

export declare function optional<input, p extends unknown extends input ? UnknownPattern : Pattern<input>>(pattern: p): OptionalP<input, p>;
type Elem<xs> = xs extends readonly (infer x)[] ? x : never;
declare type Elem<xs> = xs extends readonly (infer x)[] ? x : never;
/**

@@ -115,3 +115,3 @@ * `P.array(subpattern)` takes a sub pattern and returns a pattern, which matches

export declare function select<input, p extends unknown extends input ? UnknownPattern : Pattern<input>, k extends string>(key: k, pattern: p): SelectP<k, input, p>;
type AnyConstructor = abstract new (...args: any[]) => any;
declare type AnyConstructor = abstract new (...args: any[]) => any;
/**

@@ -118,0 +118,0 @@ * `P.any` is a wildcard pattern, matching **any value**.

import { Cast, Compute, Iterator, UpdateAt } from './helpers';
export type BuildMany<data, xs extends any[]> = xs extends any ? BuildOne<data, xs> : never;
type BuildOne<data, xs extends any[]> = xs extends [
export declare type BuildMany<data, xs extends any[]> = xs extends any ? BuildOne<data, xs> : never;
declare type BuildOne<data, xs extends any[]> = xs extends [
[

@@ -10,4 +10,4 @@ infer value,

] ? BuildOne<Update<data, value, Cast<path, PropertyKey[]>>, tail> : data;
type SafeGet<data, k extends PropertyKey, def> = k extends keyof data ? data[k] : def;
type Update<data, value, path extends PropertyKey[]> = path extends [
declare type SafeGet<data, k extends PropertyKey, def> = k extends keyof data ? data[k] : def;
declare type Update<data, value, path extends PropertyKey[]> = path extends [
infer head,

@@ -14,0 +14,0 @@ ...infer tail

import { DistributeMatchingUnions } from './DistributeUnions';
export type DeepExclude<a, b> = Exclude<DistributeMatchingUnions<a, b>, b>;
export declare type DeepExclude<a, b> = Exclude<DistributeMatchingUnions<a, b>, b>;

@@ -28,4 +28,4 @@ import { BuildMany } from './BuildMany';

*/
export type DistributeMatchingUnions<a, p> = IsAny<a> extends true ? any : BuildMany<a, Distribute<FindUnionsMany<a, p>>>;
export type FindUnionsMany<a, p, path extends PropertyKey[] = []> = UnionToTuple<(p extends any ? IsMatching<a, p> extends true ? FindUnions<a, p, path> : [] : never) extends (infer T)[] ? T : never>;
export declare type DistributeMatchingUnions<a, p> = IsAny<a> extends true ? any : BuildMany<a, Distribute<FindUnionsMany<a, p>>>;
export declare type FindUnionsMany<a, p, path extends PropertyKey[] = []> = UnionToTuple<(p extends any ? IsMatching<a, p> extends true ? FindUnions<a, p, path> : [] : never) extends (infer T)[] ? T : never>;
/**

@@ -49,3 +49,3 @@ * The reason we don't look further down the tree with lists,

*/
export type FindUnions<a, p, path extends PropertyKey[] = []> = unknown extends p ? [] : IsAny<p> extends true ? [] : Length<path> extends 5 ? [] : IsUnion<a> extends true ? [
export declare type FindUnions<a, p, path extends PropertyKey[] = []> = unknown extends p ? [] : IsAny<p> extends true ? [] : Length<path> extends 5 ? [] : IsUnion<a> extends true ? [
{

@@ -88,3 +88,3 @@ cases: a extends any ? {

}>> : [];
export type Distribute<unions extends any[]> = unions extends [
export declare type Distribute<unions extends any[]> = unions extends [
{

@@ -91,0 +91,0 @@ cases: infer cases;

import type { ToExclude } from './Pattern';
import type { BuiltInObjects, Compute, ExcludeObjectIfContainsNever, IsAny, IsPlainObject, LeastUpperBound } from './helpers';
import { DeepExclude } from './DeepExclude';
export type ExtractPreciseValue<a, b> = unknown extends b ? a : IsAny<a> extends true ? b : b extends readonly [] ? [] : b extends ToExclude<infer b1> ? DeepExclude<a, b1> : b extends readonly (infer bItem)[] ? a extends readonly (infer aItem)[] ? b extends readonly [infer b1, infer b2, infer b3, infer b4, infer b5] ? a extends readonly [infer a1, infer a2, infer a3, infer a4, infer a5] ? ExcludeObjectIfContainsNever<[
export declare type ExtractPreciseValue<a, b> = unknown extends b ? a : IsAny<a> extends true ? b : b extends readonly [] ? [] : b extends ToExclude<infer b1> ? DeepExclude<a, b1> : b extends readonly (infer bItem)[] ? a extends readonly (infer aItem)[] ? b extends readonly [infer b1, infer b2, infer b3, infer b4, infer b5] ? a extends readonly [infer a1, infer a2, infer a3, infer a4, infer a5] ? ExcludeObjectIfContainsNever<[
ExtractPreciseValue<a1, b1>,

@@ -6,0 +6,0 @@ ExtractPreciseValue<a2, b2>,

import type * as symbols from '../internals/symbols';
import type { Cast, Equal, IsAny, TupleKeys, UnionToTuple } from './helpers';
import type { Matcher, Pattern } from './Pattern';
type SelectionsRecord = Record<string, [unknown, unknown[]]>;
export type None = {
declare type SelectionsRecord = Record<string, [unknown, unknown[]]>;
export declare type None = {
type: 'none';
};
export type Some<key extends string> = {
export declare type Some<key extends string> = {
type: 'some';
key: key;
};
export type SelectionType = None | Some<string>;
type MapOptional<selections> = {
export declare type SelectionType = None | Some<string>;
declare type MapOptional<selections> = {
[k in keyof selections]: selections[k] extends [infer v, infer subpath] ? [v | undefined, subpath] : never;
};
type MapList<selections> = {
declare type MapList<selections> = {
[k in keyof selections]: selections[k] extends [infer v, infer subpath] ? [v[], subpath] : never;
};
type ReduceFindSelectionUnion<i, ps extends any[], output = never> = ps extends [infer head, ...infer tail] ? ReduceFindSelectionUnion<i, tail, output | FindSelectionUnion<i, head>> : output;
export type FindSelectionUnion<i, p, path extends any[] = []> = IsAny<i> extends true ? never : p extends Matcher<any, infer pattern, infer matcherType, infer sel> ? {
declare type ReduceFindSelectionUnion<i, ps extends any[], output = never> = ps extends [infer head, ...infer tail] ? ReduceFindSelectionUnion<i, tail, output | FindSelectionUnion<i, head>> : output;
export declare type FindSelectionUnion<i, p, path extends any[] = []> = IsAny<i> extends true ? never : p extends Matcher<any, infer pattern, infer matcherType, infer sel> ? {
select: sel extends Some<infer k> ? {

@@ -40,9 +40,9 @@ [kk in k]: [i, path];

}[keyof p] : never : never;
export type SeveralAnonymousSelectError<a = 'You can only use a single anonymous selection (with `select()`) in your pattern. If you need to select multiple values, give them names with `select(<name>)` instead'> = {
export declare type SeveralAnonymousSelectError<a = 'You can only use a single anonymous selection (with `select()`) in your pattern. If you need to select multiple values, give them names with `select(<name>)` instead'> = {
__error: never;
} & a;
export type MixedNamedAndAnonymousSelectError<a = 'Mixing named selections (`select("name")`) and anonymous selections (`select()`) is forbiden. Please, only use named selections.'> = {
export declare type MixedNamedAndAnonymousSelectError<a = 'Mixing named selections (`select("name")`) and anonymous selections (`select()`) is forbiden. Please, only use named selections.'> = {
__error: never;
} & a;
export type SelectionToArgs<selections extends SelectionsRecord> = symbols.anonymousSelectKey extends keyof selections ? [
export declare type SelectionToArgs<selections extends SelectionsRecord> = symbols.anonymousSelectKey extends keyof selections ? [
selections[symbols.anonymousSelectKey][1]

@@ -52,3 +52,3 @@ ] extends [never] ? SeveralAnonymousSelectError : keyof selections extends symbols.anonymousSelectKey ? selections[symbols.anonymousSelectKey][0] : MixedNamedAndAnonymousSelectError : {

};
type ConcatSelections<a extends SelectionsRecord, b extends SelectionsRecord> = {
declare type ConcatSelections<a extends SelectionsRecord, b extends SelectionsRecord> = {
[k in keyof a & keyof b]: [a[k][0] | b[k][0], a[k][1] & b[k][1]];

@@ -60,5 +60,5 @@ } & {

};
type ReduceToRecord<selections extends any[], output extends SelectionsRecord = {}> = selections extends [infer sel, ...infer rest] ? ReduceToRecord<rest, ConcatSelections<Cast<sel, SelectionsRecord>, output>> : output;
export type Selections<i, p> = FindSelectionUnion<i, p> extends infer u ? [u] extends [never] ? i : SelectionToArgs<ReduceToRecord<UnionToTuple<u>>> : i;
export type FindSelected<i, p> = Equal<p, Pattern<i>> extends true ? i : Selections<i, p>;
declare type ReduceToRecord<selections extends any[], output extends SelectionsRecord = {}> = selections extends [infer sel, ...infer rest] ? ReduceToRecord<rest, ConcatSelections<Cast<sel, SelectionsRecord>, output>> : output;
export declare type Selections<i, p> = FindSelectionUnion<i, p> extends infer u ? [u] extends [never] ? i : SelectionToArgs<ReduceToRecord<UnionToTuple<u>>> : i;
export declare type FindSelected<i, p> = Equal<p, Pattern<i>> extends true ? i : Selections<i, p>;
export {};

@@ -1,3 +0,3 @@

export type ValueOf<a> = a extends any[] ? a[number] : a[keyof a];
export type Values<a extends object> = UnionToTuple<ValueOf<a>>;
export declare type ValueOf<a> = a extends any[] ? a[number] : a[keyof a];
export declare type Values<a extends object> = UnionToTuple<ValueOf<a>>;
/**

@@ -11,3 +11,3 @@ * ### LeastUpperBound

*/
export type LeastUpperBound<a, b> = b extends a ? b : a extends b ? a : never;
export declare type LeastUpperBound<a, b> = b extends a ? b : a extends b ? a : never;
/**

@@ -17,46 +17,46 @@ * if a key of an object has the never type,

**/
export type ExcludeIfContainsNever<a, b> = b extends Map<any, any> | Set<any> ? a : b extends readonly [any, ...any] ? ExcludeObjectIfContainsNever<a, keyof b & ('0' | '1' | '2' | '3' | '4')> : b extends any[] ? ExcludeObjectIfContainsNever<a, keyof b & number> : ExcludeObjectIfContainsNever<a, keyof b & string>;
export type ExcludeObjectIfContainsNever<a, keyConstraint = unknown> = a extends any ? 'exclude' extends {
export declare type ExcludeIfContainsNever<a, b> = b extends Map<any, any> | Set<any> ? a : b extends readonly [any, ...any] ? ExcludeObjectIfContainsNever<a, keyof b & ('0' | '1' | '2' | '3' | '4')> : b extends any[] ? ExcludeObjectIfContainsNever<a, keyof b & number> : ExcludeObjectIfContainsNever<a, keyof b & string>;
export declare type ExcludeObjectIfContainsNever<a, keyConstraint = unknown> = a extends any ? 'exclude' extends {
[k in keyConstraint & keyof a]-?: [a[k]] extends [never] ? 'exclude' : 'include';
}[keyConstraint & keyof a] ? never : a : never;
export type UnionToIntersection<union> = (union extends any ? (k: union) => void : never) extends (k: infer intersection) => void ? intersection : never;
export type IsUnion<a> = [a] extends [UnionToIntersection<a>] ? false : true;
export type UnionToTuple<union, output extends any[] = []> = UnionToIntersection<union extends any ? (t: union) => union : never> extends (_: any) => infer elem ? UnionToTuple<Exclude<union, elem>, [elem, ...output]> : output;
export type Cast<a, b> = a extends b ? a : never;
export type Flatten<xs extends any[], output extends any[] = []> = xs extends readonly [infer head, ...infer tail] ? Flatten<tail, [...output, ...Cast<head, any[]>]> : output;
export type Equal<a, b> = (<T>() => T extends a ? 1 : 2) extends <T>() => T extends b ? 1 : 2 ? true : false;
export type Expect<a extends true> = a;
export type IsAny<a> = 0 extends 1 & a ? true : false;
export type IsNever<T> = [T] extends [never] ? true : false;
export type Length<it extends readonly any[]> = it['length'];
export type Iterator<n extends number, it extends any[] = []> = it['length'] extends n ? it : Iterator<n, [any, ...it]>;
export type Next<it extends any[]> = [any, ...it];
export type Prev<it extends any[]> = it extends readonly [any, ...infer tail] ? tail : [];
export type Take<xs extends readonly any[], it extends any[], output extends any[] = []> = Length<it> extends 0 ? output : xs extends readonly [infer head, ...infer tail] ? Take<tail, Prev<it>, [...output, head]> : output;
export type Drop<xs extends readonly any[], n extends any[]> = Length<n> extends 0 ? xs : xs extends readonly [any, ...infer tail] ? Drop<tail, Prev<n>> : [];
export type UpdateAt<tail extends readonly any[], n extends any[], value, inits extends readonly any[] = []> = Length<n> extends 0 ? tail extends readonly [any, ...infer tail] ? [...inits, value, ...tail] : inits : tail extends readonly [infer head, ...infer tail] ? UpdateAt<tail, Prev<n>, value, [...inits, head]> : inits;
export type BuiltInObjects = Function | Date | RegExp | Generator | {
export declare type UnionToIntersection<union> = (union extends any ? (k: union) => void : never) extends (k: infer intersection) => void ? intersection : never;
export declare type IsUnion<a> = [a] extends [UnionToIntersection<a>] ? false : true;
export declare type UnionToTuple<union, output extends any[] = []> = UnionToIntersection<union extends any ? (t: union) => union : never> extends (_: any) => infer elem ? UnionToTuple<Exclude<union, elem>, [elem, ...output]> : output;
export declare type Cast<a, b> = a extends b ? a : never;
export declare type Flatten<xs extends any[], output extends any[] = []> = xs extends readonly [infer head, ...infer tail] ? Flatten<tail, [...output, ...Cast<head, any[]>]> : output;
export declare type Equal<a, b> = (<T>() => T extends a ? 1 : 2) extends <T>() => T extends b ? 1 : 2 ? true : false;
export declare type Expect<a extends true> = a;
export declare type IsAny<a> = 0 extends 1 & a ? true : false;
export declare type IsNever<T> = [T] extends [never] ? true : false;
export declare type Length<it extends readonly any[]> = it['length'];
export declare type Iterator<n extends number, it extends any[] = []> = it['length'] extends n ? it : Iterator<n, [any, ...it]>;
export declare type Next<it extends any[]> = [any, ...it];
export declare type Prev<it extends any[]> = it extends readonly [any, ...infer tail] ? tail : [];
export declare type Take<xs extends readonly any[], it extends any[], output extends any[] = []> = Length<it> extends 0 ? output : xs extends readonly [infer head, ...infer tail] ? Take<tail, Prev<it>, [...output, head]> : output;
export declare type Drop<xs extends readonly any[], n extends any[]> = Length<n> extends 0 ? xs : xs extends readonly [any, ...infer tail] ? Drop<tail, Prev<n>> : [];
export declare type UpdateAt<tail extends readonly any[], n extends any[], value, inits extends readonly any[] = []> = Length<n> extends 0 ? tail extends readonly [any, ...infer tail] ? [...inits, value, ...tail] : inits : tail extends readonly [infer head, ...infer tail] ? UpdateAt<tail, Prev<n>, value, [...inits, head]> : inits;
export declare type BuiltInObjects = Function | Date | RegExp | Generator | {
readonly [Symbol.toStringTag]: string;
} | any[];
export type IsPlainObject<o, excludeUnion = BuiltInObjects> = o extends object ? o extends string | excludeUnion ? false : true : false;
export type Compute<a extends any> = a extends BuiltInObjects ? a : {
export declare type IsPlainObject<o, excludeUnion = BuiltInObjects> = o extends object ? o extends string | excludeUnion ? false : true : false;
export declare type Compute<a extends any> = a extends BuiltInObjects ? a : {
[k in keyof a]: a[k];
};
export type IntersectObjects<a> = (a extends any ? keyof a : never) extends infer allKeys ? {
export declare type IntersectObjects<a> = (a extends any ? keyof a : never) extends infer allKeys ? {
[k in Cast<allKeys, PropertyKey>]: a extends any ? k extends keyof a ? a[k] : never : never;
} : never;
export type WithDefault<a, def> = [a] extends [never] ? def : a;
export type IsLiteral<a> = [a] extends [null | undefined] ? true : [a] extends [string] ? string extends a ? false : true : [a] extends [number] ? number extends a ? false : true : [a] extends [boolean] ? boolean extends a ? false : true : [a] extends [symbol] ? symbol extends a ? false : true : [a] extends [bigint] ? bigint extends a ? false : true : false;
export type Primitives = number | boolean | string | undefined | null | symbol | bigint;
export type NonLiteralPrimitive = Exclude<Primitives, undefined | null>;
export type TupleKeys = 0 | 1 | 2 | 3 | 4;
export type Union<a, b> = [b] extends [a] ? a : [a] extends [b] ? b : a | b;
export declare type WithDefault<a, def> = [a] extends [never] ? def : a;
export declare type IsLiteral<a> = [a] extends [null | undefined] ? true : [a] extends [string] ? string extends a ? false : true : [a] extends [number] ? number extends a ? false : true : [a] extends [boolean] ? boolean extends a ? false : true : [a] extends [symbol] ? symbol extends a ? false : true : [a] extends [bigint] ? bigint extends a ? false : true : false;
export declare type Primitives = number | boolean | string | undefined | null | symbol | bigint;
export declare type NonLiteralPrimitive = Exclude<Primitives, undefined | null>;
export declare type TupleKeys = 0 | 1 | 2 | 3 | 4;
export declare type Union<a, b> = [b] extends [a] ? a : [a] extends [b] ? b : a | b;
/**
* GuardValue returns the value guarded by a type guard function.
*/
export type GuardValue<fn> = fn extends (value: any) => value is infer b ? b : fn extends (value: infer a) => unknown ? a : never;
export type GuardFunction<input, narrowed> = ((value: input) => value is Cast<narrowed, input>) | ((value: input) => boolean);
export type Some<bools extends boolean[]> = true extends bools[number] ? true : false;
export type All<bools extends boolean[]> = bools[number] extends true ? true : false;
export type Extends<a, b> = [a] extends [b] ? true : false;
export type Not<a extends boolean> = a extends true ? false : true;
export declare type GuardValue<fn> = fn extends (value: any) => value is infer b ? b : fn extends (value: infer a) => unknown ? a : never;
export declare type GuardFunction<input, narrowed> = ((value: input) => value is Cast<narrowed, input>) | ((value: input) => boolean);
export declare type Some<bools extends boolean[]> = true extends bools[number] ? true : false;
export declare type All<bools extends boolean[]> = bools[number] extends true ? true : false;
export declare type Extends<a, b> = [a] extends [b] ? true : false;
export declare type Not<a extends boolean> = a extends true ? false : true;
import { DeepExclude } from './DeepExclude';
import { IsPlainObject, Primitives, IsLiteral, ValueOf, Compute, Cast, Equal, Extends, Not, All, NonLiteralPrimitive } from './helpers';
import type { Matcher, Pattern, ToExclude } from './Pattern';
type OptionalKeys<p> = ValueOf<{
declare type OptionalKeys<p> = ValueOf<{
[k in keyof p]: p[k] extends Matcher<any, any, infer matcherType> ? matcherType extends 'optional' ? k : never : never;
}>;
type ReduceUnion<tuple extends any[], output = never> = tuple extends readonly [
declare type ReduceUnion<tuple extends any[], output = never> = tuple extends readonly [
infer p,
...infer tail
] ? ReduceUnion<tail, output | InvertPattern<p>> : output;
type ReduceIntersection<tuple extends any[], output = unknown> = tuple extends readonly [infer p, ...infer tail] ? ReduceIntersection<tail, output & InvertPattern<p>> : output;
declare type ReduceIntersection<tuple extends any[], output = unknown> = tuple extends readonly [infer p, ...infer tail] ? ReduceIntersection<tail, output & InvertPattern<p>> : output;
/**

@@ -17,3 +17,3 @@ * ### InvertPattern

*/
export type InvertPattern<p> = p extends Matcher<infer input, infer narrowed, infer matcherType, any> ? {
export declare type InvertPattern<p> = p extends Matcher<infer input, infer narrowed, infer matcherType, any> ? {
not: ToExclude<InvertPattern<narrowed>>;

@@ -44,5 +44,5 @@ select: InvertPattern<narrowed>;

}> : never : p;
export type ReduceIntersectionForExclude<tuple extends any[], i, output = unknown> = tuple extends readonly [infer p, ...infer tail] ? ReduceIntersectionForExclude<tail, i, output & InvertPatternForExcludeInternal<p, i, unknown>> : output;
export type ReduceUnionForExclude<tuple extends any[], i, output = never> = tuple extends readonly [infer p, ...infer tail] ? ReduceUnionForExclude<tail, i, output | InvertPatternForExcludeInternal<p, i, never>> : output;
type ExcludeIfExists<a, b> = [
export declare type ReduceIntersectionForExclude<tuple extends any[], i, output = unknown> = tuple extends readonly [infer p, ...infer tail] ? ReduceIntersectionForExclude<tail, i, output & InvertPatternForExcludeInternal<p, i, unknown>> : output;
export declare type ReduceUnionForExclude<tuple extends any[], i, output = never> = tuple extends readonly [infer p, ...infer tail] ? ReduceUnionForExclude<tail, i, output | InvertPatternForExcludeInternal<p, i, never>> : output;
declare type ExcludeIfExists<a, b> = [
b

@@ -57,4 +57,4 @@ ] extends [never] ? never : unknown extends a ? never : All<[

*/
export type InvertPatternForExclude<p, i> = Equal<p, Pattern<i>> extends true ? never : InvertPatternForExcludeInternal<p, i>;
type InvertPatternForExcludeInternal<p, i, empty = never> = [
export declare type InvertPatternForExclude<p, i> = Equal<p, Pattern<i>> extends true ? never : InvertPatternForExcludeInternal<p, i>;
declare type InvertPatternForExcludeInternal<p, i, empty = never> = [
p

@@ -61,0 +61,0 @@ ] extends [Primitives] ? IsLiteral<p> extends true ? p : IsLiteral<i> extends true ? p : empty : p extends Matcher<infer matchableInput, infer subpattern, infer matcherType, any, infer excluded> ? {

import { Primitives, IsPlainObject, IsUnion } from './helpers';
export type IsMatching<a, p> = true extends IsUnion<a> | IsUnion<p> ? true extends (p extends any ? (a extends any ? IsMatching<a, p> : never) : never) ? true : false : unknown extends p ? true : p extends Primitives ? p extends a ? true : false : [p, a] extends [readonly any[], readonly any[]] ? [p, a] extends [
export declare type IsMatching<a, p> = true extends IsUnion<a> | IsUnion<p> ? true extends (p extends any ? (a extends any ? IsMatching<a, p> : never) : never) ? true : false : unknown extends p ? true : p extends Primitives ? p extends a ? true : false : [p, a] extends [readonly any[], readonly any[]] ? [p, a] extends [
readonly [infer p1, infer p2, infer p3, infer p4, infer p5],

@@ -4,0 +4,0 @@ readonly [infer a1, infer a2, infer a3, infer a4, infer a5]

@@ -8,5 +8,5 @@ import type * as symbols from '../internals/symbols';

import type { FindSelected } from './FindSelected';
export type MatchedValue<a, invpattern> = WithDefault<ExtractPreciseValue<a, invpattern>, a>;
export type PickReturnValue<a, b> = a extends symbols.unset ? b : a;
type NonExhaustiveError<i> = {
export declare type MatchedValue<a, invpattern> = WithDefault<ExtractPreciseValue<a, invpattern>, a>;
export declare type PickReturnValue<a, b> = a extends symbols.unset ? b : a;
declare type NonExhaustiveError<i> = {
__nonExhaustive: never;

@@ -18,3 +18,3 @@ } & i;

*/
export type Match<i, o, patternValueTuples extends any[] = [], inferredOutput = never> = {
export declare type Match<i, o, patternValueTuples extends any[] = [], inferredOutput = never> = {
/**

@@ -127,6 +127,6 @@ * `.with(pattern, handler)` Registers a pattern and an handler function which

*/
type DeepExcludeAll<a, tupleList extends any[]> = [a] extends [never] ? never : tupleList extends [infer excluded, ...infer tail] ? DeepExcludeAll<DeepExclude<a, excluded>, tail> : a;
type MakeTuples<ps extends any[], value> = {
declare type DeepExcludeAll<a, tupleList extends any[]> = [a] extends [never] ? never : tupleList extends [infer excluded, ...infer tail] ? DeepExcludeAll<DeepExclude<a, excluded>, tail> : a;
declare type MakeTuples<ps extends any[], value> = {
-readonly [index in keyof ps]: InvertPatternForExclude<ps[index], value>;
};
export {};
import type * as symbols from '../internals/symbols';
import { Primitives } from './helpers';
import { None, Some, SelectionType } from './FindSelected';
export type MatcherType = 'not' | 'optional' | 'or' | 'and' | 'array' | 'select' | 'default';
export type MatcherProtocol<input, narrowed, matcherType extends MatcherType, selections extends SelectionType, excluded> = {
export declare type MatcherType = 'not' | 'optional' | 'or' | 'and' | 'array' | 'select' | 'default';
export declare type MatcherProtocol<input, narrowed, matcherType extends MatcherType, selections extends SelectionType, excluded> = {
match: <I>(value: I | input) => MatchResult;

@@ -10,3 +10,3 @@ getSelectionKeys?: () => string[];

};
export type MatchResult = {
export declare type MatchResult = {
matched: boolean;

@@ -25,16 +25,16 @@ selections?: Record<string, any>;

}
type UnknownMatcher = Matcher<unknown, unknown, any, any>;
export type OptionalP<input, p> = Matcher<input, p, 'optional'>;
export type ArrayP<input, p> = Matcher<input, p, 'array'>;
export type AndP<input, ps> = Matcher<input, ps, 'and'>;
export type OrP<input, ps> = Matcher<input, ps, 'or'>;
export type NotP<input, p> = Matcher<input, p, 'not'>;
export type GuardP<input, narrowed> = Matcher<input, narrowed>;
export type GuardExcludeP<input, narrowed, excluded> = Matcher<input, narrowed, 'default', None, excluded>;
export type SelectP<key extends string, input = unknown, p = Matcher<unknown, unknown>> = Matcher<input, p, 'select', Some<key>>;
export type AnonymousSelectP = SelectP<symbols.anonymousSelectKey>;
declare type UnknownMatcher = Matcher<unknown, unknown, any, any>;
export declare type OptionalP<input, p> = Matcher<input, p, 'optional'>;
export declare type ArrayP<input, p> = Matcher<input, p, 'array'>;
export declare type AndP<input, ps> = Matcher<input, ps, 'and'>;
export declare type OrP<input, ps> = Matcher<input, ps, 'or'>;
export declare type NotP<input, p> = Matcher<input, p, 'not'>;
export declare type GuardP<input, narrowed> = Matcher<input, narrowed>;
export declare type GuardExcludeP<input, narrowed, excluded> = Matcher<input, narrowed, 'default', None, excluded>;
export declare type SelectP<key extends string, input = unknown, p = Matcher<unknown, unknown>> = Matcher<input, p, 'select', Some<key>>;
export declare type AnonymousSelectP = SelectP<symbols.anonymousSelectKey>;
export interface ToExclude<a> {
[symbols.toExclude]: a;
}
export type UnknownPattern = readonly [] | readonly [UnknownPattern, ...UnknownPattern[]] | {
export declare type UnknownPattern = readonly [] | readonly [UnknownPattern, ...UnknownPattern[]] | {
readonly [k: string]: UnknownPattern;

@@ -53,3 +53,3 @@ } | Set<UnknownPattern> | Map<unknown, UnknownPattern> | Primitives | UnknownMatcher;

*/
export type Pattern<a> = Matcher<a, unknown, any, any> | (a extends Primitives ? a : unknown extends a ? UnknownPattern : a extends readonly (infer i)[] ? a extends readonly [any, ...any] ? {
export declare type Pattern<a> = Matcher<a, unknown, any, any> | (a extends Primitives ? a : unknown extends a ? UnknownPattern : a extends readonly (infer i)[] ? a extends readonly [any, ...any] ? {
readonly [index in keyof a]: Pattern<a[index]>;

@@ -56,0 +56,0 @@ } : readonly [] | readonly [Pattern<i>, ...Pattern<i>[]] : a extends Map<infer k, infer v> ? Map<k, Pattern<v>> : a extends Set<infer v> ? Set<Pattern<v>> : a extends object ? {

{
"name": "ts-pattern",
"version": "4.2.2",
"version": "4.2.3-test.0",
"description": " The exhaustive Pattern Matching library for TypeScript.",
"type": "module",
"source": "src/index.ts",
"exports": {
".": {
"require": "./dist/index.cjs",
"import": "./dist/index.module.js",
"types": "./dist/index.d.ts",
"default": "./dist/index.modern.js"
},
"./package.json": "./package.json"
},
"main": "./dist/index.cjs",
"types": "dist/index.d.ts",
"main": "./dist/index.js",
"module": "./dist/index.module.js",
"exports": "./dist/foo.modern.mjs",
"unpkg": "./dist/index.umd.js",
"types": "dist/index.d.ts",
"scripts": {

@@ -56,3 +46,3 @@ "build": "microbundle",

"jest": "^27.4.5",
"microbundle": "^0.15.0",
"microbundle": "^0.15.1",
"prettier": "^2.5.1",

@@ -59,0 +49,0 @@ "ts-jest": "^27.1.2",

@@ -20,2 +20,4 @@ <h1 align="center">TS-Pattern</h1>

```ts

@@ -45,2 +47,5 @@ import { match, P } from 'ts-pattern';

![ts-pattern](https://user-images.githubusercontent.com/9265418/231688650-7cd957a9-8edc-4db8-a5fe-61e1c2179d91.gif)
<p align="center"><i>Animation by <a target="_blank" href="https://twitter.com/nicoespeon/status/1644342570389061634?s=20">@nicoespeon</a></i></p>
## Features

@@ -63,3 +68,3 @@

Read the introduction blog post: [Bringing Pattern Matching to TypeScript 🎨 Introducing TS-Pattern v3.0](https://dev.to/gvergnaud/bringing-pattern-matching-to-typescript-introducing-ts-pattern-v3-0-o1k)
Read the introduction blog post: [Bringing Pattern Matching to TypeScript 🎨 Introducing TS-Pattern](https://dev.to/gvergnaud/bringing-pattern-matching-to-typescript-introducing-ts-pattern-v3-0-o1k)

@@ -66,0 +71,0 @@ ## Installation

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