workbox-routing
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "workbox-routing", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A service worker helper library to route request URLs to handlers.", | ||
@@ -25,4 +25,4 @@ "keywords": [ | ||
"homepage": "https://github.com/GoogleChrome/workbox/tree/master/packages/workbox-routing", | ||
"main": "build/importScripts/workbox-routing.prod.v1.0.0.js", | ||
"module": "build/modules/workbox-routing.prod.v1.0.0.mjs" | ||
"main": "build/importScripts/workbox-routing.prod.v1.1.0.js", | ||
"module": "build/modules/workbox-routing.prod.v1.1.0.mjs" | ||
} |
@@ -17,3 +17,3 @@ /* | ||
import Route from './route'; | ||
import assert from '../../../../lib/assert'; | ||
import {isArrayOfClass} from '../../../../lib/assert'; | ||
import logHelper from '../../../../lib/log-helper'; | ||
@@ -34,4 +34,6 @@ | ||
* matched by this route. The regular expressions in `whitelist` and `blacklist` | ||
* are matched against the [`pathname`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/pathname) | ||
* portion of the requested URL. | ||
* are matched against the concatenated | ||
* [`pathname`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/pathname) | ||
* and [`search`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/search) | ||
* portions of the requested URL. | ||
* | ||
@@ -73,5 +75,5 @@ * To match all navigations, use a `whitelist` array containing a RegExp that | ||
constructor({whitelist, blacklist, handler} = {}) { | ||
assert.isArrayOfClass({whitelist}, RegExp); | ||
isArrayOfClass({whitelist}, RegExp); | ||
if (blacklist) { | ||
assert.isArrayOfClass({blacklist}, RegExp); | ||
isArrayOfClass({blacklist}, RegExp); | ||
} else { | ||
@@ -86,4 +88,5 @@ blacklist = []; | ||
if (event.request.mode === 'navigate') { | ||
if (whitelist.some((regExp) => regExp.test(url.pathname))) { | ||
if (blacklist.some((regExp) => regExp.test(url.pathname))) { | ||
const pathnameAndSearch = url.pathname + url.search; | ||
if (whitelist.some((regExp) => regExp.test(pathnameAndSearch))) { | ||
if (blacklist.some((regExp) => regExp.test(pathnameAndSearch))) { | ||
message = `The navigation route is not being used, since the ` + | ||
@@ -90,0 +93,0 @@ `request URL matches both the whitelist and blacklist.`; |
@@ -1,2 +0,2 @@ | ||
import assert from '../../../../lib/assert'; | ||
import {hasMethod, isType} from '../../../../lib/assert'; | ||
@@ -11,8 +11,8 @@ /** | ||
if (typeof handler === 'object') { | ||
assert.hasMethod({handler}, 'handle'); | ||
hasMethod({handler}, 'handle'); | ||
return handler; | ||
} else { | ||
assert.isType({handler}, 'function'); | ||
isType({handler}, 'function'); | ||
return {handle: handler}; | ||
} | ||
} |
@@ -17,3 +17,3 @@ /* | ||
import Route from './route'; | ||
import assert from '../../../../lib/assert'; | ||
import {isInstance} from '../../../../lib/assert'; | ||
import logHelper from '../../../../lib/log-helper.js'; | ||
@@ -87,3 +87,3 @@ | ||
constructor({regExp, handler, method}) { | ||
assert.isInstance({regExp}, RegExp); | ||
isInstance({regExp}, RegExp); | ||
@@ -90,0 +90,0 @@ const match = ({url}) => { |
@@ -16,3 +16,3 @@ /* | ||
import assert from '../../../../lib/assert'; | ||
import {isType, isOneOf} from '../../../../lib/assert'; | ||
import normalizeHandler from './normalize-handler'; | ||
@@ -125,7 +125,7 @@ import {defaultMethod, validMethods} from './constants'; | ||
assert.isType({match}, 'function'); | ||
isType({match}, 'function'); | ||
this.match = match; | ||
if (method) { | ||
assert.isOneOf({method}, validMethods); | ||
isOneOf({method}, validMethods); | ||
this.method = method; | ||
@@ -132,0 +132,0 @@ } else { |
@@ -17,3 +17,3 @@ /* | ||
import Route from './route'; | ||
import assert from '../../../../lib/assert'; | ||
import {isArrayOfClass, isInstance} from '../../../../lib/assert'; | ||
import logHelper from '../../../../lib/log-helper.js'; | ||
@@ -224,3 +224,3 @@ import normalizeHandler from './normalize-handler'; | ||
registerRoutes({routes} = {}) { | ||
assert.isArrayOfClass({routes}, Route); | ||
isArrayOfClass({routes}, Route); | ||
@@ -249,8 +249,69 @@ for (let route of routes) { | ||
registerRoute({route} = {}) { | ||
assert.isInstance({route}, Route); | ||
isInstance({route}, Route); | ||
this.registerRoutes({routes: [route]}); | ||
} | ||
/** | ||
* Unregisters an array of routes with the router. | ||
* | ||
* @example | ||
* const firstRoute = new RegExpRoute({ ... }); | ||
* const secondRoute = new RegExpRoute({ ... }); | ||
* router.registerRoutes({routes: [firstRoute, secondRoute]}); | ||
* | ||
* // Later, if you no longer want the routes to be used: | ||
* router.unregisterRoutes({routes: [firstRoute, secondRoute]}); | ||
* | ||
* @param {Object} input | ||
* @param {Array<module:workbox-routing.Route>} input.routes An array of | ||
* routes to unregister. | ||
*/ | ||
unregisterRoutes({routes} = {}) { | ||
isArrayOfClass({routes}, Route); | ||
for (let route of routes) { | ||
if (!this._routes.has(route.method)) { | ||
logHelper.error({ | ||
that: this, | ||
message: `Can't unregister route; there are no ${route.method} | ||
routes registered.`, | ||
data: {route}, | ||
}); | ||
} | ||
const routeIndex = this._routes.get(route.method).indexOf(route); | ||
if (routeIndex > -1) { | ||
this._routes.get(route.method).splice(routeIndex, 1); | ||
} else { | ||
logHelper.error({ | ||
that: this, | ||
message: `Can't unregister route; the route wasn't previously | ||
registered.`, | ||
data: {route}, | ||
}); | ||
} | ||
} | ||
} | ||
/** | ||
* Unregisters a single route with the router. | ||
* | ||
* @example | ||
* const route = new RegExpRoute({ ... }); | ||
* router.registerRoute({route}); | ||
* | ||
* // Later, if you no longer want the route to be used: | ||
* router.unregisterRoute({route}); | ||
* | ||
* @param {Object} input | ||
* @param {module:workbox-routing.Route} input.route The route to unregister. | ||
*/ | ||
unregisterRoute({route} = {}) { | ||
isInstance({route}, Route); | ||
this.unregisterRoutes({routes: [route]}); | ||
} | ||
} | ||
export default Router; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
479150
1215