UNPKG

1.06 kBJavaScriptView Raw
1/*
2 Copyright 2018 Google LLC
3
4 Use of this source code is governed by an MIT-style
5 license that can be found in the LICENSE file or at
6 https://opensource.org/licenses/MIT.
7*/
8import '../_version.js';
9/**
10 * Removes any URL search parameters that should be ignored.
11 *
12 * @param {URL} urlObject The original URL.
13 * @param {Array<RegExp>} ignoreURLParametersMatching RegExps to test against
14 * each search parameter name. Matches mean that the search parameter should be
15 * ignored.
16 * @return {URL} The URL with any ignored search parameters removed.
17 *
18 * @private
19 * @memberof workbox-precaching
20 */
21export function removeIgnoredSearchParams(urlObject, 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}