blob: 0952dc76ed444cb0edd974b75b9090a98578b3a9 [file]
// Copyright (c) 2026, the R8 project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import dom from "./dom.js";
function decodeHash(raw) {
try {
return decodeURIComponent(raw);
} catch (e) {
return unescape(raw);
}
}
const options = decodeHash(window.location.hash.substring(1)).split(",");
function contains(subject) {
return options.includes(subject);
}
function matches(subject) {
for (const filter of options.values()) {
if (filter) {
const pattern = filter
.replace(/[.+?^${}()|[\]\\]/g, "\\$&")
.replaceAll("*", ".*");
if (new RegExp(`^${pattern}$`).test(subject)) {
return true;
}
}
}
return false;
}
function updateHash(state) {
window.location.hash = Array.from(state.selectedBenchmarks)
.concat(
state.selectedLegends.size == state.legends.size
? []
: Array.from(state.selectedLegends),
)
.concat(dom.getSelectedBranch() == "release" ? ["release"] : [])
.join(",");
}
function values() {
return options;
}
export default {
contains: contains,
matches: matches,
updateHash: updateHash,
values: values,
};