UNPKG

array-includes-with-glob

Version:

Like _.includes but with wildcards

11 lines (9 loc) 2.66 kB
/** * @name array-includes-with-glob * @fileoverview Like _.includes but with wildcards * @version 5.0.12 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/array-includes-with-glob/} */ "use strict";var arrayIncludesWithGlob=(()=>{var u=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames,m=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable;var h=(t,e,r)=>e in t?u(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,c=(t,e)=>{for(var r in e||(e={}))b.call(e,r)&&h(t,r,e[r]);if(m)for(var r of m(e))A.call(e,r)&&h(t,r,e[r]);return t};var j=(t,e)=>{for(var r in e)u(t,r,{get:e[r],enumerable:!0})},E=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of k(e))!b.call(t,s)&&s!==r&&u(t,s,{get:()=>e[s],enumerable:!(n=S(e,s))||n.enumerable});return t};var M=t=>E(u({},"__esModule",{value:!0}),t);var B={};j(B,{defaults:()=>w,includesWithGlob:()=>V,version:()=>F});function f(t){if(typeof t!="string")throw new TypeError("Expected a string");return t.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}var y=new Map,x=(t,e)=>{if(!Array.isArray(t))switch(typeof t){case"string":t=[t];break;case"undefined":t=[];break;default:throw new TypeError(`Expected '${e}' to be a string or an array, but got a type of '${typeof t}'`)}return t.filter(r=>{if(typeof r!="string"){if(typeof r>"u")return!1;throw new TypeError(`Expected '${e}' to be an array of strings, but found a type of '${typeof r}' in the array`)}return!0})},$=(t,e)=>{e=c({caseSensitive:!1},e);let r=t+JSON.stringify(e);if(y.has(r))return y.get(r);let n=t[0]==="!";n&&(t=t.slice(1)),t=f(t).replace(/\\\*/g,"[\\s\\S]*");let s=new RegExp(`^${t}$`,e.caseSensitive?"":"i");return s.negated=n,y.set(r,s),s},R=(t,e,r,n)=>{if(t=x(t,"inputs"),e=x(e,"patterns"),e.length===0)return[];e=e.map(o=>$(o,r));let{allPatterns:s}=r||{},i=[];for(let o of t){let l,g=[...e].fill(!1);for(let[a,d]of e.entries())if(d.test(o)&&(g[a]=!0,l=!d.negated,!l))break;if(!(l===!1||l===void 0&&e.some(a=>!a.negated)||s&&g.some((a,d)=>!a&&!e[d].negated))&&(i.push(o),n))break}return i};function p(t,e,r){return R(t,e,r,!0).length>0}var v="5.0.12";var F=v,w={arrayVsArrayAllMustBeFound:"any",caseSensitive:!0};function V(t,e,r){if(!t.length||!e.length)return!1;let n=c(c({},w),r),s=typeof t=="string"?[t]:Array.from(t);return typeof e=="string"?s.some(i=>p(i,e,{caseSensitive:n.caseSensitive})):n.arrayVsArrayAllMustBeFound==="any"?e.some(i=>s.some(o=>p(o,i,{caseSensitive:n.caseSensitive}))):e.every(i=>s.some(o=>p(o,i,{caseSensitive:n.caseSensitive})))}return M(B);})();