index.d.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. Escape a string for use in HTML.
  3. Escapes the following characters in the given `string` argument: `&` `<` `>` `"` `'`.
  4. @example
  5. ```
  6. import {htmlEscape} from 'escape-goat';
  7. htmlEscape('🦄 & 🐐');
  8. //=> '🦄 &amp; 🐐'
  9. htmlEscape('Hello <em>World</em>');
  10. //=> 'Hello &lt;em&gt;World&lt;/em&gt;'
  11. ```
  12. */
  13. export function htmlEscape(string: string): string;
  14. /**
  15. Unescape an HTML string to use as a plain string.
  16. Unescapes the following HTML entities in the given `htmlString` argument: `&amp;` `&lt;` `&gt;` `&quot;` `&#39;`.
  17. @example
  18. ```
  19. import {htmlUnescape} from 'escape-goat';
  20. htmlUnescape('🦄 &amp; 🐐');
  21. //=> '🦄 & 🐐'
  22. ```
  23. */
  24. export function htmlUnescape(htmlString: string): string;
  25. /**
  26. [Tagged template literal](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals#Tagged_template_literals) that escapes interpolated values.
  27. @example
  28. ```
  29. import {htmlEscapeTag} from 'escape-goat';
  30. const url = 'https://sindresorhus.com?x="🦄"';
  31. htmlEscapeTag`<a href="${url}">Unicorn</a>`;
  32. //=> '<a href="https://sindresorhus.com?x=&quot;🦄&quot;">Unicorn</a>'
  33. ```
  34. */
  35. export function htmlEscapeTag(template: TemplateStringsArray, ...substitutions: readonly unknown[]): string;
  36. /**
  37. [Tagged template literal](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals#Tagged_template_literals) that unescapes interpolated values.
  38. @example
  39. ```
  40. import {htmlUnescapeTag} from 'escape-goat';
  41. const escapedUrl = 'https://sindresorhus.com?x=&quot;🦄&quot;';
  42. htmlUnescapeTag`URL from HTML: ${url}`;
  43. //=> 'URL from HTML: https://sindresorhus.com?x="🦄"'
  44. ```
  45. */
  46. export function htmlUnescapeTag(template: TemplateStringsArray, ...substitutions: readonly unknown[]): string;