12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- /*
- Copyright 2018 Google LLC
- Use of this source code is governed by an MIT-style
- license that can be found in the LICENSE file or at
- https://opensource.org/licenses/MIT.
- */
- import '../_version.js';
- const _cacheNameDetails = {
- googleAnalytics: 'googleAnalytics',
- precache: 'precache-v2',
- prefix: 'workbox',
- runtime: 'runtime',
- suffix: typeof registration !== 'undefined' ? registration.scope : '',
- };
- const _createCacheName = (cacheName) => {
- return [_cacheNameDetails.prefix, cacheName, _cacheNameDetails.suffix]
- .filter((value) => value && value.length > 0)
- .join('-');
- };
- const eachCacheNameDetail = (fn) => {
- for (const key of Object.keys(_cacheNameDetails)) {
- fn(key);
- }
- };
- export const cacheNames = {
- updateDetails: (details) => {
- eachCacheNameDetail((key) => {
- if (typeof details[key] === 'string') {
- _cacheNameDetails[key] = details[key];
- }
- });
- },
- getGoogleAnalyticsName: (userCacheName) => {
- return userCacheName || _createCacheName(_cacheNameDetails.googleAnalytics);
- },
- getPrecacheName: (userCacheName) => {
- return userCacheName || _createCacheName(_cacheNameDetails.precache);
- },
- getPrefix: () => {
- return _cacheNameDetails.prefix;
- },
- getRuntimeName: (userCacheName) => {
- return userCacheName || _createCacheName(_cacheNameDetails.runtime);
- },
- getSuffix: () => {
- return _cacheNameDetails.suffix;
- },
- };
|