escape.js 677 B

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