location.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. /**
  3. * @license
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. Object.defineProperty(exports, "__esModule", { value: true });
  7. exports.assign = exports.replace = exports.setHref = void 0;
  8. var url_sanitizer_1 = require("../../builders/url_sanitizer");
  9. /**
  10. * setHref safely sets {@link Location.href} on the given {@link Location} with
  11. * given {@link Url}.
  12. */
  13. function setHref(loc, url) {
  14. var sanitizedUrl = (0, url_sanitizer_1.unwrapUrlOrSanitize)(url);
  15. if (sanitizedUrl !== undefined) {
  16. loc.href = sanitizedUrl;
  17. }
  18. }
  19. exports.setHref = setHref;
  20. /**
  21. * replace safely calls {@link Location.replace} on the given {@link Location}
  22. * with given {@link Url}.
  23. */
  24. function replace(loc, url) {
  25. var sanitizedUrl = (0, url_sanitizer_1.unwrapUrlOrSanitize)(url);
  26. if (sanitizedUrl !== undefined) {
  27. loc.replace(sanitizedUrl);
  28. }
  29. }
  30. exports.replace = replace;
  31. /**
  32. * assign safely calls {@link Location.assign} on the given {@link Location}
  33. * with given {@link Url}.
  34. */
  35. function assign(loc, url) {
  36. var sanitizedUrl = (0, url_sanitizer_1.unwrapUrlOrSanitize)(url);
  37. if (sanitizedUrl !== undefined) {
  38. loc.assign(sanitizedUrl);
  39. }
  40. }
  41. exports.assign = assign;