index.js 797 B

123456789101112131415161718192021222324252627282930313233
  1. 'use strict';
  2. exports.htmlEscape = string => string
  3. .replace(/&/g, '&')
  4. .replace(/"/g, '"')
  5. .replace(/'/g, ''')
  6. .replace(/</g, '&lt;')
  7. .replace(/>/g, '&gt;');
  8. exports.htmlUnescape = htmlString => htmlString
  9. .replace(/&gt;/g, '>')
  10. .replace(/&lt;/g, '<')
  11. .replace(/&#0?39;/g, '\'')
  12. .replace(/&quot;/g, '"')
  13. .replace(/&amp;/g, '&');
  14. exports.htmlEscapeTag = (strings, ...values) => {
  15. let output = strings[0];
  16. for (let i = 0; i < values.length; i++) {
  17. output = output + exports.htmlEscape(String(values[i])) + strings[i + 1];
  18. }
  19. return output;
  20. };
  21. exports.htmlUnescapeTag = (strings, ...values) => {
  22. let output = strings[0];
  23. for (let i = 0; i < values.length; i++) {
  24. output = output + exports.htmlUnescape(String(values[i])) + strings[i + 1];
  25. }
  26. return output;
  27. };