removeIgnoredSearchParams.mjs 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. Copyright 2018 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.mjs';
  8. /**
  9. * Removes any URL search parameters that should be ignored.
  10. *
  11. * @param {URL} urlObject The original URL.
  12. * @param {Array<RegExp>} ignoreURLParametersMatching RegExps to test against
  13. * each search parameter name. Matches mean that the search parameter should be
  14. * ignored.
  15. * @return {URL} The URL with any ignored search parameters removed.
  16. *
  17. * @private
  18. * @memberof module:workbox-precaching
  19. */
  20. export function removeIgnoredSearchParams(urlObject,
  21. ignoreURLParametersMatching) {
  22. // Convert the iterable into an array at the start of the loop to make sure
  23. // deletion doesn't mess up iteration.
  24. for (const paramName of [...urlObject.searchParams.keys()]) {
  25. if (ignoreURLParametersMatching.some((regExp) => regExp.test(paramName))) {
  26. urlObject.searchParams.delete(paramName);
  27. }
  28. }
  29. return urlObject;
  30. }