Like operator Helper

The LIKE operator uses the following method helper to be transformed:

You might also be interested in Like operator transformation.

Like Operator Helper Function Definition

function LIKE(expr,pattern,esc,cs) {
   function fixPattern(pattern,esc) {
      const specials = '/.*+?|(){}[]\\'.split('');
      var newPattern = "";
      var fix = (c) => specials.includes(c) ? '\\' + c : c;
      for(var i = 0;i < pattern.length;i++) {
         var c = pattern[i];
         if (c === esc) {
            newPattern += pattern[i + 1]
            i++
         } else if (c === '%') {
            newPattern += ".*?"
         } else if (c === '_') {
            newPattern += "."
         } else if (c === '[' || ']') {
            newPattern += c
         } else newPattern += fix(c)
      }
      return newPattern;
   }
   return new RegExp(`^${fixPattern(pattern,esc)}$`,cs ? '' : 'i').exec(expr) != null;
}

Last updated