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.2 to 4.0.3-rc.0

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(const n of this.cases){const r=n.match(this.value);if(r.matched){t=r.value,e=n.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={};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,o,i){if(e(u)){if(r(u)){var c=u[n]().match(o),a=c.matched,f=c.selections;return a&&f&&Object.keys(f).forEach(function(n){return i(n,f[n])}),a}if(!e(o))return!1;if(Array.isArray(u))return!!Array.isArray(o)&&u.length===o.length&&u.every(function(n,e){return t(n,o[e],i)});if(u instanceof Map)return o instanceof Map&&Array.from(u.keys()).every(function(n){return t(u.get(n),o.get(n),i)});if(u instanceof Set){if(!(o instanceof Set))return!1;if(0===u.size)return 0===o.size;if(1===u.size){var s=Array.from(u.values())[0];return r(s)?Array.from(o.values()).every(function(n){return t(s,n,i)}):o.has(s)}return Array.from(u.values()).every(function(n){return o.has(n)})}return Object.keys(u).every(function(e){var c,a=u[e];return(e in o||r(c=a)&&"optional"===c[n]().matcherType)&&t(a,o[e],i)})}return Object.is(o,u)},o=function t(u){var o,c,a;return e(u)?r(u)?null!=(o=null==(c=(a=u[n]()).getSelectionKeys)?void 0:c.call(a))?o:[]:Array.isArray(u)?i(u,t):i(Object.values(u),t):[]},i=function(n,t){return n.reduce(function(n,e){return n.concat(t(e))},[])};function c(t){var e;return(e={})[n]=function(){return{match:function(n){var e={},r=function(n,t){e[n]=t};return void 0===n?(o(t).forEach(function(n){return r(n,void 0)}),{matched:!0,selections:e}):{matched:u(t,n,r),selections:e}},getSelectionKeys:function(){return o(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 o(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 i(e,o)},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 i(e,o).forEach(function(n){return r(n,void 0)}),{matched:e.some(function(t){return u(t,n,r)}),selections:t}},getSelectionKeys:function(){return i(e,o)},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),i="string"==typeof r[0]?r[0]:void 0,c=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!=i?i:t]=n,e);return{matched:void 0===c||u(c,n,function(n,t){r[n]=t}),selections:r}},getSelectionKeys:function(){return[null!=i?i:t].concat(void 0===c?[]:o(c))}}},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}),A=h(function(n){return"symbol"==typeof n}),w=h(function(n){return null==n}),S={__proto__:null,optional:c,array:a,intersection:f,union:s,not:l,when:h,select:v,any:y,_:m,string:d,number:p,boolean:g,bigint:b,symbol:A,nullish:w,instanceOf:function(n){return h(function(n){return function(t){return t instanceof n}}(n))},typed:function(){return{array:a,optional:c,intersection:f,union:s,not:l,select:v,when:h}}};function j(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}var O=function(n){return new K(n,[])},K=/*#__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],o=[e[0]],i=[];return 3===e.length&&"function"==typeof e[1]?(o.push(e[0]),i.push(e[1])):e.length>2&&o.push.apply(o,e.slice(1,e.length-1)),new n(this.value,this.cases.concat([{match:function(n){var e={},r=Boolean(o.some(function(t){return u(t,n,function(n,t){e[n]=t})})&&i.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,t=this.value,e=void 0,r=function(n,t){var e="undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(e)return(e=e.call(n)).next.bind(e);if(Array.isArray(n)||(e=function(n,t){if(n){if("string"==typeof n)return j(n,t);var e=Object.prototype.toString.call(n).slice(8,-1);return"Object"===e&&n.constructor&&(e=n.constructor.name),"Map"===e||"Set"===e?Array.from(n):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?j(n,t):void 0}}(n))){e&&(n=e);var r=0;return function(){return r>=n.length?{done:!0}:{done:!1,value:n[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(this.cases);!(n=r()).done;){var u=n.value,o=u.match(this.value);if(o.matched){t=o.value,e=u.handler;break}}if(!e){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 e(t,this.value)},n}();function k(){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],o=e[1];return u(r,o,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,k as isMatching,O 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={},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};
//# 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)},o=function(n){return n&&!!n[t]},i=function n(e,i,u){if(r(e)){if(o(e)){var c=e[t]().match(i),a=c.matched,f=c.selections;return a&&f&&Object.keys(f).forEach(function(n){return u(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],u)});if(e instanceof Map)return i instanceof Map&&Array.from(e.keys()).every(function(t){return n(e.get(t),i.get(t),u)});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 o(s)?Array.from(i.values()).every(function(t){return n(s,t,u)}):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||o(c=a)&&"optional"===c[t]().matcherType)&&n(a,i[r],u)})}return Object.is(i,e)},u=function n(e){var i,u,a;return r(e)?o(e)?null!=(i=null==(u=(a=e[t]()).getSelectionKeys)?void 0:u.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?(u(n).forEach(function(n){return r(n,void 0)}),{matched:!0,selections:e}):{matched:i(n,t,r),selections:e}},getSelectionKeys:function(){return u(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 u(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,u)},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,u).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,u)},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),o="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!=o?o:e]=n,t);return{matched:void 0===c||i(c,n,function(n,t){r[n]=t}),selections:r}},getSelectionKeys:function(){return[null!=o?o:e].concat(void 0===c?[]:u(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}),A=v(function(n){return"bigint"==typeof n}),w=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:A,symbol:w,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}}};function O(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}var T=/*#__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],o=[t[0]],u=[];return 3===t.length&&"function"==typeof t[1]?(o.push(t[0]),u.push(t[1])):t.length>2&&o.push.apply(o,t.slice(1,t.length-1)),new n(this.value,this.cases.concat([{match:function(n){var t={},r=Boolean(o.some(function(e){return i(e,n,function(n,e){t[n]=e})})&&u.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,t=this.value,e=void 0,r=function(n,t){var e="undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(e)return(e=e.call(n)).next.bind(e);if(Array.isArray(n)||(e=function(n,t){if(n){if("string"==typeof n)return O(n,t);var e=Object.prototype.toString.call(n).slice(8,-1);return"Object"===e&&n.constructor&&(e=n.constructor.name),"Map"===e||"Set"===e?Array.from(n):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?O(n,t):void 0}}(n))){e&&(n=e);var r=0;return function(){return r>=n.length?{done:!0}:{done:!1,value:n[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(this.cases);!(n=r()).done;){var o=n.value,i=o.match(this.value);if(i.matched){t=i.value,e=o.handler;break}}if(!e){var u;try{u=JSON.stringify(this.value)}catch(n){u=this.value}throw new Error("Pattern matching error: no pattern matches value "+u)}return e(t,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],o=e[1];return i(r,o,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 T(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={},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
{
"name": "ts-pattern",
"version": "4.0.2",
"version": "4.0.3-rc.0",
"description": " The exhaustive Pattern Matching library for TypeScript.",

@@ -8,4 +8,12 @@ "type": "module",

"exports": {
"require": "./dist/index.cjs",
"default": "./dist/index.modern.js"
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.modern.js"
},
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.cjs"
}
}
},

@@ -52,7 +60,7 @@ "main": "./dist/index.cjs",

"jest": "^27.4.5",
"microbundle": "^0.14.2",
"microbundle": "^0.15.0",
"prettier": "^2.5.1",
"ts-jest": "^27.1.2",
"typescript": "^4.5.4"
"typescript": "^4.7.2"
}
}

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

- Works on **any data structure**: nested [Objects](#objects), [Arrays](#tuples-arrays), [Tuples](#tuples-arrays), [Sets](#sets), [Maps](#maps) and all primitive types.
- Pattern-match on **any data structure**: nested [Objects](#objects), [Arrays](#tuples-arrays), [Tuples](#tuples-arrays), [Sets](#sets), [Maps](#maps) and all primitive types.
- **Typesafe**, with helpful [type inference](#type-inference).
- **Exhaustiveness checking** support, enforcing that you are matching every possible case with [`.exhaustive()`](#exhaustive).
- Use [patterns](#patterns) to **validate** the shape of your data with [`isMatching`](#ismatching).
- **Expressive API**, with catch-all and type specific **wildcards**: [`P._`](#P_-wildcard), [`P.string`](#Pstring-wildcard), [`P.number`](#Pnumber-wildcard), etc.

@@ -176,2 +177,3 @@ - Supports [**predicates**](#Pwhen-patterns), [**unions**](#Punion-patterns), [**intersections**](#Pintersection-patterns) and [**exclusion**](#Pnot-patterns) patterns for non-trivial cases.

<!-- prettier-ignore -->
```ts

@@ -178,0 +180,0 @@ import { match, P } from 'ts-pattern';

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