escape.js 780 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
  3. _Object$defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = escape;
  7. /*
  8. * Copyright (c) 2015-present, Parse, LLC.
  9. * All rights reserved.
  10. *
  11. * This source code is licensed under the BSD-style license found in the
  12. * LICENSE file in the root directory of this source tree. An additional grant
  13. * of patent rights can be found in the PATENTS file in the same directory.
  14. *
  15. * @flow
  16. */
  17. var encoded = {
  18. '&': '&',
  19. '<': '&lt;',
  20. '>': '&gt;',
  21. '/': '&#x2F;',
  22. "'": '&#x27;',
  23. '"': '&quot;'
  24. };
  25. function escape(str
  26. /*: string*/
  27. )
  28. /*: string*/
  29. {
  30. return str.replace(/[&<>/'"]/g, function (char) {
  31. return encoded[char];
  32. });
  33. }