sanitizeQuerySelector.tsx 382 B

123456789101112
  1. /**
  2. * Sanitizes a string so that it can be used as a query selector
  3. *
  4. * e.g. `feedback:branding` --> `feedback-branding` or
  5. * 'Data Scrubbing' --> 'Data-Scrubbing'
  6. *
  7. * @param str The string to sanitize
  8. * @return Returns a sanitized string (replace
  9. */
  10. export function sanitizeQuerySelector(str: string) {
  11. return typeof str === 'string' ? str.replace(/[ :]+/g, '-') : '';
  12. }