"use strict";

exports.__esModule = true;
exports.searchStringToRegExp = searchStringToRegExp;
exports.getHighlightRegExp = getHighlightRegExp;

function searchStringToRegExp(str) {
  var trimmed = str.trim();
  var escaped;

  if (trimmed.length === 0) {
    return null;
  }

  if (/^[-+()\s\d]+$/.test(trimmed)) {
    // it is supposed that it's a phone number
    escaped = trimmed.replace(/[-+()\s]+/g, '').split('').join(')(\\D*?[-\\+\\(\\)\\s]*\\D*?)(');
  } else {
    escaped = trimmed.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&') // escape symbols for use in regexp
    .replace(/\s+/g, ')(.*?\\s+.*?)('); // extend spaces
  }

  return new RegExp('(.*?)(' + escaped + ')(.*?)', 'gi');
}

function getHighlightRegExp(str) {
  var trimmed = str.trim();

  if (trimmed.length === 0) {
    return null;
  }

  var escaped = trimmed.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&') // escape symbols for use in regexp
  .replace(/\s+/g, '|'); // turn spaces into OR operator

  return new RegExp(escaped, 'gi');
}