sanitize.js 462 B

123456789101112131415161718192021
  1. /**
  2. * Removes carriage returns, newline characters, tabs, non-breaking spaces, and trailing spaces from string
  3. * @method sanitize
  4. * @memberof axe.commons.text
  5. * @instance
  6. * @param {String} str String to be cleaned
  7. * @return {String} Sanitized string
  8. */
  9. function sanitize(str) {
  10. if (!str) {
  11. return '';
  12. }
  13. return str
  14. .replace(/\r\n/g, '\n')
  15. .replace(/\u00A0/g, ' ')
  16. .replace(/[\s]{2,}/g, ' ')
  17. .trim();
  18. }
  19. export default sanitize;