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.0.3 to 4.0.4

2

dist/index.modern.js

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

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

@@ -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={},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}),p=h(function(n){return"number"==typeof n}),g=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:p,boolean:g,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}}},K=function(n){return new O(n,[])},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}}},K=function(n){return new O(n,[])},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};
//# 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={},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){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,[])}});
//# sourceMappingURL=index.umd.js.map

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

}
export declare type UnknownPattern = readonly [UnknownPattern, ...UnknownPattern[]] | {
export declare type UnknownPattern = readonly [] | readonly [UnknownPattern, ...UnknownPattern[]] | {
readonly [k: string]: UnknownPattern;

@@ -40,0 +40,0 @@ } | Set<UnknownPattern> | Map<unknown, UnknownPattern> | Primitives | UnknownMatcher;

{
"name": "ts-pattern",
"version": "4.0.3",
"version": "4.0.4",
"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

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