mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-13 20:36:35 +00:00
Prefer regex literals over constructors (#15553)
This commit is contained in:
parent
ab231eec4f
commit
03e3f161f7
@ -60,7 +60,6 @@
|
||||
"no-restricted-globals": [2, "event"],
|
||||
"prefer-promise-reject-errors": "off",
|
||||
"no-unsafe-optional-chaining": "warn",
|
||||
"prefer-regex-literals": ["warn"],
|
||||
"import/prefer-default-export": "off",
|
||||
"import/no-default-export": "off",
|
||||
"import/no-unresolved": "off",
|
||||
|
@ -66,7 +66,7 @@ const incrementalUnits = ["clients", "queries", "ads"];
|
||||
|
||||
export const mockHistory = (mockHass: MockHomeAssistant) => {
|
||||
mockHass.mockAPI(
|
||||
new RegExp("history/period/.+"),
|
||||
/history\/period\/.+/,
|
||||
(hass, _method, path, _parameters) => {
|
||||
const params = parseQuery<HistoryQueryParams>(path.split("?")[1]);
|
||||
const entities = params.filter_entity_id.split(",");
|
||||
|
@ -1,4 +1,4 @@
|
||||
const isTemplateRegex = new RegExp("{%|{{");
|
||||
const isTemplateRegex = /{%|{{/;
|
||||
|
||||
export const isTemplate = (value: string): boolean =>
|
||||
isTemplateRegex.test(value);
|
||||
|
@ -13,10 +13,8 @@ import {
|
||||
StaleWhileRevalidate,
|
||||
} from "workbox-strategies";
|
||||
|
||||
const noFallBackRegEx = new RegExp(
|
||||
"/(api|static|auth|frontend_latest|frontend_es5|local)/.*"
|
||||
);
|
||||
|
||||
const noFallBackRegEx =
|
||||
/\/(api|static|auth|frontend_latest|frontend_es5|local)\/.*/;
|
||||
// Clean up caches from older workboxes and old service workers.
|
||||
// Will help with cleaning up Workbox v4 stuff
|
||||
cleanupOutdatedCaches();
|
||||
@ -33,22 +31,22 @@ function initRouting() {
|
||||
|
||||
// Cache static content (including translations) on first access.
|
||||
registerRoute(
|
||||
new RegExp("/(static|frontend_latest|frontend_es5)/.+"),
|
||||
/\/(static|frontend_latest|frontend_es5)\/.+/,
|
||||
new CacheFirst({ matchOptions: { ignoreSearch: true } })
|
||||
);
|
||||
|
||||
// Get api from network.
|
||||
registerRoute(new RegExp("/(api|auth)/.*"), new NetworkOnly());
|
||||
registerRoute(/\/(api|auth)\/.*/, new NetworkOnly());
|
||||
|
||||
// Get manifest, service worker, onboarding from network.
|
||||
registerRoute(
|
||||
new RegExp("/(service_worker.js|manifest.json|onboarding.html)"),
|
||||
/\/(service_worker.js|manifest.json|onboarding.html)/,
|
||||
new NetworkOnly()
|
||||
);
|
||||
|
||||
// For the root "/" we ignore search
|
||||
registerRoute(
|
||||
new RegExp(/\/(\?.*)?$/),
|
||||
/\/(\?.*)?$/,
|
||||
new StaleWhileRevalidate({ matchOptions: { ignoreSearch: true } })
|
||||
);
|
||||
|
||||
@ -57,7 +55,7 @@ function initRouting() {
|
||||
// First access might bring stale data from cache, but a single refresh will bring updated
|
||||
// file.
|
||||
registerRoute(
|
||||
new RegExp(/\/.*/),
|
||||
/\/.*/,
|
||||
new StaleWhileRevalidate({
|
||||
cacheName: "file-cache",
|
||||
plugins: [
|
||||
|
@ -116,7 +116,7 @@ export const provideHass = (
|
||||
}
|
||||
|
||||
mockAPI(
|
||||
new RegExp("states/.+"),
|
||||
/states\/.+/,
|
||||
(
|
||||
// @ts-ignore
|
||||
method,
|
||||
|
Loading…
x
Reference in New Issue
Block a user