text: /**
   * Copyright 2015 Google Inc. All rights reserved.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  'use strict';
  
  var URL = require('dom-urls');
  
  module.exports = {
    stripIgnoredUrlParameters: function(originalUrl, ignoreUrlParametersMatching) {
      var url = new URL(originalUrl);
  
      url.search = url.search.slice(1) // Exclude initial '?'
        .split('&') // Split into an array of 'key=value' strings
        .map(function(kv) {
          return kv.split('='); // Split each 'key=value' string into a [key, value] array
        })
        .filter(function(kv) {
          return ignoreUrlParametersMatching.every(function(ignoredRegex) {
            return !ignoredRegex.test(kv[0]); // Return true iff the key doesn't match any of the regexes.
          });
        })
        .map(function(kv) {
          return kv.join('='); // Join each [key, value] array into a 'key=value' string
        })
        .join('&'); // Join the array of 'key=value' strings into a string with '&' in between each
  
      return url.toString();
    },
  
    populateCurrentCacheNames: function(precacheConfig, cacheNamePrefix, baseUrl) {
      var absoluteUrlToCacheName = {};
      var currentCacheNamesToAbsoluteUrl = {};
  
      precacheConfig.forEach(function(cacheOption) {
        var absoluteUrl = new URL(cacheOption[0], baseUrl).toString();
        var cacheName = cacheNamePrefix + absoluteUrl + '-' + cacheOption[1];
        currentCacheNamesToAbsoluteUrl[cacheName] = absoluteUrl;
        absoluteUrlToCacheName[absoluteUrl] = cacheName;
      });
  
      return {
        absoluteUrlToCacheName: absoluteUrlToCacheName,
        currentCacheNamesToAbsoluteUrl: currentCacheNamesToAbsoluteUrl
      };
    },
  
    addDirectoryIndex: function(originalUrl, index) {
      var url = new URL(originalUrl);
      if (url.pathname.slice(-1) === '/') {
        url.pathname += index;
      }
      return url.toString();
    }
  };
  