TankopediaCharacteristics

This commit is contained in:
tresabhi committed 2026-09-30 18:22:18 -05:00
1 parent 5cae5d1583
commit 74fbd15c5f
9 files changed
+521 -68

No files matched your search

+37 -8
View File
@@ -1,16 +1,45 @@
export function literals(
string: string,
literals?: Record<string, string | number | undefined>
literals?: Record<string, string | number | undefined>,
) {
for (const key in literals) {
const mutated = string.replaceAll(`{${key}}`, `${literals[key]}`);
if (import.meta.env.DEV && mutated === string) {
console.warn(`Could not find literal {${key}} in string "${string}"`);
}
string = mutated;
string = string.replaceAll(`{${key}}`, `${literals[key]}`);
}
return string;
}
export function literalsArray<Type, Literal = Type | string>(
string: string,
literals?: Record<string, Literal>,
) {
if (!literals) return [string];
let array: (string | Literal)[] = [string];
for (const key in literals) {
const value = literals[key];
const next: (string | Literal)[] = [];
for (const chunk of array) {
if (typeof chunk !== "string") {
next.push(chunk);
continue;
}
const parts = chunk.split(`{${key}}`);
for (let index = 0; index < parts.length; index++) {
if (parts[index]) next.push(parts[index]);
if (index < parts.length - 1) {
next.push(value);
}
}
}
array = next;
}
return array;
}
+11
View File
@@ -1,4 +1,15 @@
{
"units": {
"m": "{value}m",
"mm": "{value}mm",
"deg": "{value}°",
"hp": "{value}hp",
"x": "x{value}",
"percentage": "{value}%",
"deg_s": "{value}°/s",
"plus": "+{value}"
},
"tanks": {
"characteristics": {
"titles": {