urlsMatch.js 594 B

123456789101112131415161718192021
  1. /*
  2. Copyright 2019 Google LLC
  3. Use of this source code is governed by an MIT-style
  4. license that can be found in the LICENSE file or at
  5. https://opensource.org/licenses/MIT.
  6. */
  7. import '../_version.js';
  8. /**
  9. * Returns true if two URLs have the same `.href` property. The URLS can be
  10. * relative, and if they are the current location href is used to resolve URLs.
  11. *
  12. * @private
  13. * @param {string} url1
  14. * @param {string} url2
  15. * @return {boolean}
  16. */
  17. export function urlsMatch(url1, url2) {
  18. const { href } = location;
  19. return new URL(url1, href).href === new URL(url2, href).href;
  20. }