Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-pattern

Package Overview
Dependencies
Maintainers
1
Versions
152
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-pattern - npm Package Compare versions

Comparing version 5.0.6 to 5.0.7

2

dist/index.umd.js

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

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

@@ -18,3 +18,3 @@ import { Pattern } from './types/Pattern.js';

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

@@ -21,0 +21,0 @@ * `isMatching` takes pattern and a value and checks if the value matches this pattern.

@@ -10,6 +10,10 @@ import { Compute, Iterator, UpdateAt } from './helpers.js';

] ? BuildOne<Update<data, value, Extract<path, readonly PropertyKey[]>>, tail> : data;
type SafeGet<data, k extends PropertyKey, def> = k extends keyof data ? data[k] : def;
type Update<data, value, path extends readonly PropertyKey[]> = path extends readonly [infer head, ...infer tail] ? data extends readonly [any, ...any] ? head extends number ? UpdateAt<data, Iterator<head>, Update<data[head], value, Extract<tail, readonly PropertyKey[]>>> : never : data extends readonly (infer a)[] ? Update<a, value, Extract<tail, readonly PropertyKey[]>>[] : data extends Set<infer a> ? Set<Update<a, value, Extract<tail, readonly PropertyKey[]>>> : data extends Map<infer k, infer v> ? Map<k, Update<v, value, Extract<tail, readonly PropertyKey[]>>> : Compute<Omit<data, Extract<head, PropertyKey>> & {
[k in Extract<head, PropertyKey>]: Update<SafeGet<data, k, {}>, value, Extract<tail, readonly PropertyKey[]>>;
}> : value;
type Update<data, value, path> = path extends readonly [
infer head,
...infer tail
] ? data extends readonly [any, ...any] ? head extends number ? UpdateAt<data, Iterator<head>, Update<data[head], value, tail>> : never : data extends readonly (infer a)[] ? Update<a, value, tail>[] : data extends Set<infer a> ? Set<Update<a, value, tail>> : data extends Map<infer k, infer v> ? Map<k, Update<v, value, tail>> : head extends keyof data ? Compute<{
[k in Exclude<keyof data, head>]: data[k];
} & {
[k in head]: Update<data[k], value, tail>;
}> : data : value;
export {};
{
"name": "ts-pattern",
"version": "5.0.6",
"version": "5.0.7",
"description": " The exhaustive Pattern Matching library for TypeScript.",

@@ -32,5 +32,7 @@ "type": "module",

"clear-test": "jest --clearCache",
"fmt": "prettier ./src/** ./tests/** -w",
"check": "tsc --strict --noEmit --extendedDiagnostics",
"perf": "tsc --project tests/tsconfig.json --noEmit --extendedDiagnostics",
"fmt": "prettier ./src/** ./tests/** -w",
"check": "tsc --strict --noEmit --extendedDiagnostics"
"trace": "tsc --project tests/tsconfig.json --generateTrace trace --incremental false --noEmit",
"analyzeTrace": "npx @typescript/analyze-trace trace"
},

@@ -63,9 +65,9 @@ "files": [

"@types/jest": "^29.5.2",
"jest": "^29.5.0",
"jest": "^29.7.0",
"microbundle": "^0.15.1",
"prettier": "^2.8.8",
"rimraf": "^5.0.1",
"ts-jest": "^29.1.0",
"typescript": "^5.1.3"
"ts-jest": "^29.1.2",
"typescript": "^5.3.3"
}
}

@@ -144,10 +144,10 @@ <h1 align="center">TS-Pattern</h1>

- [Basic Demo](https://codesandbox.io/s/ts-pattern-examples-v4-bdy5p2?file=/src/examples/basic.tsx)
- [Basic Demo](https://codesandbox.io/p/devbox/ts-pattern-api-examples-bdy5p2?file=%2Fsrc%2Fexamples%2Fbasic.tsx)
- [React gif fetcher app Demo](https://codesandbox.io/s/ts-pattern-gif-search-demo-v4-bkumdw?file=/src/App.tsx)
- [React.useReducer Demo](https://codesandbox.io/s/ts-pattern-reducer-example-v4-fx2yqu?file=/src/App.tsx)
- [Handling untyped API response Demo](https://codesandbox.io/s/ts-pattern-examples-v4-bdy5p2?file=/src/examples/api.tsx)
- [`P.when` Guard Demo](https://codesandbox.io/s/ts-pattern-examples-v4-bdy5p2?file=/src/examples/when.tsx)
- [`P.not` Pattern Demo](https://codesandbox.io/s/ts-pattern-examples-v4-bdy5p2?file=/src/examples/not.tsx)
- [`P.select` Pattern Demo](https://codesandbox.io/s/ts-pattern-examples-v4-bdy5p2?file=/src/examples/select.tsx)
- [`P.union` Pattern Demo](https://codesandbox.io/s/ts-pattern-examples-v4-bdy5p2?file=/src/examples/union.tsx)
- [React.useReducer Demo](https://codesandbox.io/p/devbox/ts-pattern-v4-reducer-example-fx2yqu?file=%2Fsrc%2FApp.tsx)
- [Handling untyped API response Demo](https://codesandbox.io/p/devbox/ts-pattern-api-examples-bdy5p2?file=%2Fsrc%2Fexamples%2Fapi.tsx)
- [`P.when` Guard Demo](https://codesandbox.io/p/devbox/ts-pattern-api-examples-bdy5p2?file=%2Fsrc%2Fexamples%2Fwhen.tsx)
- [`P.not` Pattern Demo](https://codesandbox.io/p/devbox/ts-pattern-api-examples-bdy5p2?file=%2Fsrc%2Fexamples%2Fnot.tsx)
- [`P.select` Pattern Demo](https://codesandbox.io/p/devbox/ts-pattern-api-examples-bdy5p2?file=%2Fsrc%2Fexamples%2Fselect.tsx)
- [`P.union` Pattern Demo](https://codesandbox.io/p/devbox/ts-pattern-api-examples-bdy5p2?file=%2Fsrc%2Fexamples%2Funion.tsx)

@@ -1546,9 +1546,9 @@ ## Getting Started

TS-Pattern takes advantage of some of the most advanced features of the type system to narrow the input type using the current pattern. It is also able to accurately know if you have handled all cases, even when matching on complex data-structures.
TS-Pattern takes advantage the most advanced features of TypeScript to perform type narrowing and accurate exhaustive matching, even when matching on complex data-structures.
Here are some examples of TS-Pattern's inference features.
Here are some examples of TS-Pattern's type inference features.
#### Type narrowing
If you pattern-match on a union type with a discriminant property, TS-Pattern will use this discriminant to narrow the type of input.
When pattern-matching on a input containing union types, TS-Pattern will infer the most precise type possible for the argument of your handler function using the pattern you provide.

@@ -1578,3 +1578,3 @@ ```ts

If you use `P.select`, TS-Pattern will pick up the type of the property you selected, and will inferyour handler's type accordingly.
When using `P.select` in a pattern, TS-Pattern will find and inject the selected value in your handler. The type of your handler's argument is inferred accordingly.

@@ -1599,4 +1599,6 @@ ```ts

If the function given to `P.when` is a [Type Guard](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates), TS-Pattern will use the type guard's return type to narrow the input.
#### Type guard function
If you pass a [type guard](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates) function to `P.when`, TS-Pattern will use its return type to narrow the input.
```ts

@@ -1616,4 +1618,3 @@ const isString = (x: unknown): x is string => typeof x === 'string';

If your data structure contains several union types, you can pattern-match on several of them with a **single pattern**. TS-Pattern will keep track of the cases which have been handled and those which
haven't, so you never forget to handle a case.
TS-Pattern will keep track of handled and unhandled cases of your input type. Even when pattern-matching on several union types at once, you only need to call `.exhaustive()` to make sure that all possible cases are correctly handled.

@@ -1620,0 +1621,0 @@ ```ts

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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