import { RE2JS } from "re2js";
const DEFAULT_MAX_PATTERN_LENGTH = 500;
const DEFAULT_MAX_INPUT_LENGTH = 1e4;
const MAX_REGEX_CACHE_SIZE = 256;
const compiledRegexCache = /* @__PURE__ */ new Map();
function getCachedRegex(pattern) {
  const cached = compiledRegexCache.get(pattern);
  if (cached) return cached;
  const compiled = RE2JS.compile(pattern);
  if (compiledRegexCache.size >= MAX_REGEX_CACHE_SIZE) {
    const oldestKey = compiledRegexCache.keys().next().value;
    if (oldestKey) compiledRegexCache.delete(oldestKey);
  }
  compiledRegexCache.set(pattern, compiled);
  return compiled;
}
function testLinearRegex(pattern, input, options = {}) {
  const maxPatternLength = options.maxPatternLength ?? DEFAULT_MAX_PATTERN_LENGTH;
  const maxInputLength = options.maxInputLength ?? DEFAULT_MAX_INPUT_LENGTH;
  if (pattern.length > maxPatternLength) return { ok: false, reason: "pattern_too_long" };
  if (input.length > maxInputLength) return { ok: false, reason: "input_too_long" };
  try {
    return { ok: true, matched: getCachedRegex(pattern).test(input) };
  } catch {
    return { ok: false, reason: "invalid_pattern" };
  }
}
export {
  testLinearRegex
};
//# sourceMappingURL=linear.js.map
