query_utils.ts 458 B

123456789101112131415161718
  1. const selectorRegexp = /(?:^|\s){[^{]*}/g;
  2. export function parseQuery(input: string) {
  3. input = input || '';
  4. const match = input.match(selectorRegexp);
  5. let query = '';
  6. let regexp = input;
  7. if (match) {
  8. query = match[0].trim();
  9. regexp = input.replace(selectorRegexp, '').trim();
  10. }
  11. return { query, regexp };
  12. }
  13. export function formatQuery(selector: string, search: string): string {
  14. return `${selector || ''} ${search || ''}`.trim();
  15. }