html-entities.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /******/ (function() { // webpackBootstrap
  2. /******/ "use strict";
  3. /******/ // The require scope
  4. /******/ var __webpack_require__ = {};
  5. /******/
  6. /************************************************************************/
  7. /******/ /* webpack/runtime/define property getters */
  8. /******/ !function() {
  9. /******/ // define getter functions for harmony exports
  10. /******/ __webpack_require__.d = function(exports, definition) {
  11. /******/ for(var key in definition) {
  12. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  13. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  14. /******/ }
  15. /******/ }
  16. /******/ };
  17. /******/ }();
  18. /******/
  19. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  20. /******/ !function() {
  21. /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
  22. /******/ }();
  23. /******/
  24. /******/ /* webpack/runtime/make namespace object */
  25. /******/ !function() {
  26. /******/ // define __esModule on exports
  27. /******/ __webpack_require__.r = function(exports) {
  28. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  29. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  30. /******/ }
  31. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  32. /******/ };
  33. /******/ }();
  34. /******/
  35. /************************************************************************/
  36. var __webpack_exports__ = {};
  37. __webpack_require__.r(__webpack_exports__);
  38. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  39. /* harmony export */ "decodeEntities": function() { return /* binding */ decodeEntities; }
  40. /* harmony export */ });
  41. /** @type {HTMLTextAreaElement} */
  42. let _decodeTextArea;
  43. /**
  44. * Decodes the HTML entities from a given string.
  45. *
  46. * @param {string} html String that contain HTML entities.
  47. *
  48. * @example
  49. * ```js
  50. * const result = decodeEntities( 'á' );
  51. * console.log( result ); // result will be "á"
  52. * ```
  53. *
  54. * @return {string} The decoded string.
  55. */
  56. function decodeEntities(html) {
  57. // Not a string, or no entities to decode.
  58. if ('string' !== typeof html || -1 === html.indexOf('&')) {
  59. return html;
  60. } // Create a textarea for decoding entities, that we can reuse.
  61. if (undefined === _decodeTextArea) {
  62. if (document.implementation && document.implementation.createHTMLDocument) {
  63. _decodeTextArea = document.implementation.createHTMLDocument('').createElement('textarea');
  64. } else {
  65. _decodeTextArea = document.createElement('textarea');
  66. }
  67. }
  68. _decodeTextArea.innerHTML = html;
  69. const decoded = _decodeTextArea.textContent;
  70. _decodeTextArea.innerHTML = '';
  71. /**
  72. * Cast to string, HTMLTextAreaElement should always have `string` textContent.
  73. *
  74. * > The `textContent` property of the `Node` interface represents the text content of the
  75. * > node and its descendants.
  76. * >
  77. * > Value: A string or `null`
  78. * >
  79. * > * If the node is a `document` or a Doctype, `textContent` returns `null`.
  80. * > * If the node is a CDATA section, comment, processing instruction, or text node,
  81. * > textContent returns the text inside the node, i.e., the `Node.nodeValue`.
  82. * > * For other node types, `textContent returns the concatenation of the textContent of
  83. * > every child node, excluding comments and processing instructions. (This is an empty
  84. * > string if the node has no children.)
  85. *
  86. * @see https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent
  87. */
  88. return (
  89. /** @type {string} */
  90. decoded
  91. );
  92. }
  93. (window.wp = window.wp || {}).htmlEntities = __webpack_exports__;
  94. /******/ })()
  95. ;