{"size": 3467, "ext": "js", "max_stars_repo_path": "packages/browser/sifrr-serviceworker/dist/sifrr.serviceworker.min.js", "max_stars_repo_name": "cmnstmntmn/sifrr", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "packages/browser/sifrr-serviceworker/dist/sifrr.serviceworker.min.js", "max_issues_repo_name": "cmnstmntmn/sifrr", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packages/browser/sifrr-serviceworker/dist/sifrr.serviceworker.min.js", "max_forks_repo_name": "cmnstmntmn/sifrr", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 866.75, "max_line_length": 3341, "alphanum_fraction": 0.7649264494}
/*! Sifrr.Serviceworker v0.0.3 - sifrr project | MIT licensed | https://github.com/sifrr/sifrr */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):((e=e||self).Sifrr=e.Sifrr||{},e.Sifrr.Serviceworker=t())}(this,function(){"use strict";return class{constructor(e){this.options=Object.assign({version:1,fallbackCacheName:"fallbacks",defaultCacheName:"default",policies:{},fallbacks:{},precacheUrls:[]},e),this.options.policies.default=Object.assign(this.options.policies.default||{},{policy:"NETWORK_FIRST",cacheName:this.options.defaultCacheName})}setup(){self.addEventListener("install",this.installEventListener.bind(this)),self.addEventListener("activate",this.activateEventListener.bind(this)),self.addEventListener("fetch",this.fetchEventListener.bind(this))}setupPushNotification(e="",t={body:""}){this.defaultPushTitle=e,this.defaultPushOptions=t,self.addEventListener("push",this.pushEventListener.bind(this)),self.addEventListener("notificationclick",this.onNotificationClick.bind(this))}installEventListener(e){e.waitUntil(this.precache()),this.onInstall(e)}onInstall(){}activateEventListener(){const e="-v"+this.options.version;caches.keys().then(t=>t.filter(t=>t.indexOf(e)<0)).then(e=>Promise.all(e.map(e=>caches.delete(e)))).then(()=>self.clients.claim())}fetchEventListener(e){const t=e.request,s=t.clone(),i=t.clone();"GET"===t.method&&e.respondWith(this.respondWithPolicy(t).then(e=>{if(!e.ok&&e.status>0&&this.findRegex(i.url,this.options.fallbacks))throw Error("response status "+e.status);return e}).catch(e=>this.respondWithFallback(s,e)))}pushEventListener(e){let t={};e.data&&(t="function"==typeof e.data.json?e.data.json():e.data||{});const s=t.title||this.defaultPushTitle,i=Object.assign(this.defaultPushOptions,t);return self.registration.showNotification(s,i)}onNotificationClick(){}precache(e=this.options.precacheUrls,t=this.options.fallbacks){const s=this;let i=[];e.forEach(e=>{let t=s.createRequest(e);return i.push(s.responseFromNetwork(t,s.findRegex(e,s.options.policies).cacheName))});for(let e of Object.values(t)){let t=this.createRequest(e);i.push(this.responseFromNetwork(t,this.options.fallbackCacheName))}return Promise.all(i)}respondWithFallback(e,t){const s=this.createRequest(this.findRegex(e.url,this.options.fallbacks));if(void 0!==s)return this.responseFromCache(s,this.options.fallbackCacheName);throw t}respondWithPolicy(e){const t=e.clone(),s=e.clone(),i=this.findRegex(e.url,this.options.policies),n=i.policy,o=i.cacheName||this.options.defaultCacheName;let r;switch(n){case"NETWORK_ONLY":r=this.responseFromNetwork(t,o,!1);break;case"CACHE_FIRST":case"CACHE_ONLY":r=this.responseFromCache(t,o).catch(()=>this.responseFromNetwork(e,o));break;case"CACHE_AND_UPDATE":r=this.responseFromCache(t,o).catch(()=>this.responseFromNetwork(e,o)),this.responseFromNetwork(s,o);break;default:r=this.responseFromNetwork(t,o).catch(()=>this.responseFromCache(e,o))}return r}responseFromNetwork(e,t,s=!0){return caches.open(t+"-v"+this.options.version).then(t=>fetch(e).then(i=>(s&&t.put(e,i.clone()),i)))}responseFromCache(e,t){return caches.open(t+"-v"+this.options.version).then(t=>t.match(e)).then(t=>{if(t)return t;throw"Cache not found for "+e.url})}createRequest(e,t={method:"GET"}){return new Request(e,t)}findRegex(e,t){for(let[s,i]of Object.entries(t))if(new RegExp(s).test(e))return i;return t.default}}});
/*! (c) @aadityataparia */
