mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-23 17:08:10 -07:00
28 lines
816 B
JavaScript
28 lines
816 B
JavaScript
/** @type {[RegExp, string][]} */
|
|
const ALIASES = [
|
|
[/\bcapitalised\b/g, "capitalized"],
|
|
[/\ball time high\b/g, "ath"],
|
|
[/\blong term holders?\b/g, "lth"],
|
|
[/\bshort term holders?\b/g, "sth"],
|
|
[/\b(?:one )?(?:bitcoin|btc) worth\b/g, "bitcoin spot price"],
|
|
];
|
|
|
|
/** @param {string} query */
|
|
function expand(query) {
|
|
return ALIASES.reduce(
|
|
(value, [pattern, replacement]) => value.replace(pattern, replacement),
|
|
query.toLowerCase().replace(/[-_]+/g, " "),
|
|
).replace(
|
|
/\b(\d+(?:\.\d+)?)\s+to\s+(\d+(?:\.\d+)?)\s*(btc|sats?)\b/g,
|
|
"$1$3 to $2$3",
|
|
);
|
|
}
|
|
|
|
/** @param {string[]} queries */
|
|
export function expandMetricQueries(queries) {
|
|
return [...new Set(queries.flatMap((query) => {
|
|
const expanded = expand(query);
|
|
return expanded === query ? [query] : [expanded, query];
|
|
}))];
|
|
}
|