MCPcopy Index your code
hub / github.com/TanStack/db / evaluateLike

Function evaluateLike

packages/db/src/query/compiler/evaluators.ts:632–655  ·  view source on GitHub ↗

* Evaluates LIKE/ILIKE patterns

(
  value: any,
  pattern: any,
  caseInsensitive: boolean,
)

Source from the content-addressed store, hash-verified

630 * Evaluates LIKE/ILIKE patterns
631 */
632function evaluateLike(
633 value: any,
634 pattern: any,
635 caseInsensitive: boolean,
636): boolean {
637 if (typeof value !== `string` || typeof pattern !== `string`) {
638 return false
639 }
640
641 const searchValue = caseInsensitive ? value.toLowerCase() : value
642 const searchPattern = caseInsensitive ? pattern.toLowerCase() : pattern
643
644 // Convert SQL LIKE pattern to regex
645 // First escape all regex special chars except % and _
646 let regexPattern = searchPattern.replace(/[.*+?^${}()|[\]\\]/g, `\\$&`)
647
648 // Then convert SQL wildcards to regex
649 regexPattern = regexPattern.replace(/%/g, `.*`) // % matches any sequence
650 regexPattern = regexPattern.replace(/_/g, `.`) // _ matches any single char
651
652 // 's' (dotAll flag) makes '.' match all characters including line terminations
653 const regex = new RegExp(`^${regexPattern}$`, 's')
654 return regex.test(searchValue)
655}

Callers 1

compileFunctionFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected