escape.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. "use strict";
  2. /**
  3. * Copyright (C) 2016-2018 Michael Kourlas
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. Object.defineProperty(exports, "__esModule", { value: true });
  18. exports.escapeDoubleQuotes = exports.escapeSingleQuotes = exports.escapeRightAngleBracketsInCdataTerminator = exports.escapeLeftAngleBrackets = exports.escapeAmpersands = void 0;
  19. /**
  20. * Replaces ampersands (&) with the appropriate XML character reference.
  21. */
  22. function escapeAmpersands(str) {
  23. return str.replace(/&/g, "&");
  24. }
  25. exports.escapeAmpersands = escapeAmpersands;
  26. /**
  27. * Replaces left angle brackets (<) with the appropriate XML character
  28. * reference.
  29. */
  30. function escapeLeftAngleBrackets(str) {
  31. return str.replace(/</g, "&lt;");
  32. }
  33. exports.escapeLeftAngleBrackets = escapeLeftAngleBrackets;
  34. /**
  35. * Replaces right angle brackets (&gt;) with the appropriate XML character
  36. * reference when part of the string "]]>".
  37. */
  38. function escapeRightAngleBracketsInCdataTerminator(str) {
  39. return str.replace(/]]>/g, "]]&gt;");
  40. }
  41. exports.escapeRightAngleBracketsInCdataTerminator = escapeRightAngleBracketsInCdataTerminator;
  42. /**
  43. * Replaces single quotes (") with the appropriate XML character reference.
  44. */
  45. function escapeSingleQuotes(str) {
  46. return str.replace(/'/g, "&apos;");
  47. }
  48. exports.escapeSingleQuotes = escapeSingleQuotes;
  49. /**
  50. * Replaces double quotes (") with the appropriate XML character reference.
  51. */
  52. function escapeDoubleQuotes(str) {
  53. return str.replace(/"/g, "&quot;");
  54. }
  55. exports.escapeDoubleQuotes = escapeDoubleQuotes;