openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 871 B
JavaScript
import{t as escapeRegExp}from"./regexp-DAJp1ywh.mjs";
//!src/agents/glob-pattern.ts
function compileGlobPattern(e){const t=e.normalize(e.raw);if(t===`*`)return{kind:`all`};if(!t.includes(`*`))return{kind:`exact`,value:t};return{kind:`regex`,value:new RegExp(`^${escapeRegExp(t).replaceAll(`\\*`,`.*`)}$`)}}function compileGlobPatterns(e){if(!Array.isArray(e.raw))return[];return e.raw.map(t=>compileGlobPattern({raw:t,normalize:e.normalize})).filter(e=>e.kind!==`exact`||e.value)}function matchesAnyGlobPattern(e,t){for(const n of t)if(n.kind===`all`||n.kind===`exact`&&e===n.value||n.kind===`regex`&&n.value.test(e))return true;return false}function mayMatchGlobWithPrefix(e,t){const n=e.indexOf(`*`);if(n<0)return false;const r=e.slice(0,n);return t.startsWith(r)||r.startsWith(t)}export{matchesAnyGlobPattern as n,mayMatchGlobWithPrefix as r,compileGlobPatterns as t};