Strip all angle brackets in PF2e attack traits and damage
All checks were successful
CI / check (push) Successful in 2m23s
CI / build-image (push) Successful in 17s

Broaden stripDiceBrackets to stripAngleBrackets to handle all
PF2e tools angle-bracket formatting (e.g. <10 feet>, <15 feet>),
not just dice notation. Also strip in damage text.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lukas
2026-04-07 15:34:28 +02:00
parent 12a089dfd7
commit 3e62e54274
2 changed files with 36 additions and 6 deletions

View File

@@ -114,8 +114,8 @@ describe("normalizePf2eBestiary", () => {
}); });
}); });
describe("attack traits formatting", () => { describe("attack formatting", () => {
it("strips angle-bracket dice notation from traits", () => { it("strips angle brackets from traits", () => {
const [creature] = normalizePf2eBestiary({ const [creature] = normalizePf2eBestiary({
creature: [ creature: [
minimalCreature({ minimalCreature({
@@ -140,6 +140,34 @@ describe("normalizePf2eBestiary", () => {
}), }),
); );
}); });
it("strips angle brackets from reach values in traits", () => {
const [creature] = normalizePf2eBestiary({
creature: [
minimalCreature({
attacks: [
{
name: "tentacle",
range: "Melee",
attack: 18,
traits: ["agile", "chaotic", "magical", "reach <10 feet>"],
damage: "2d8+6 piercing",
},
],
}),
],
});
const attack = creature.attacks?.[0];
expect(attack).toBeDefined();
expect(attack?.segments[0]).toEqual(
expect.objectContaining({
type: "text",
value: expect.stringContaining(
"(agile, chaotic, magical, reach 10 feet)",
),
}),
);
});
}); });
describe("resistances formatting", () => { describe("resistances formatting", () => {

View File

@@ -79,8 +79,8 @@ function capitalize(s: string): string {
return s.charAt(0).toUpperCase() + s.slice(1); return s.charAt(0).toUpperCase() + s.slice(1);
} }
function stripDiceBrackets(s: string): string { function stripAngleBrackets(s: string): string {
return s.replaceAll(/<(\d*d\d+)>/g, "$1"); return s.replaceAll(/<([^>]+)>/g, "$1");
} }
function makeCreatureId(source: string, name: string): CreatureId { function makeCreatureId(source: string, name: string): CreatureId {
@@ -263,9 +263,11 @@ function normalizeAttacks(
const attackMod = a.attack == null ? "" : ` +${a.attack}`; const attackMod = a.attack == null ? "" : ` +${a.attack}`;
const traits = const traits =
a.traits && a.traits.length > 0 a.traits && a.traits.length > 0
? ` (${a.traits.map((t) => stripDiceBrackets(stripTags(t))).join(", ")})` ? ` (${a.traits.map((t) => stripAngleBrackets(stripTags(t))).join(", ")})`
: "";
const damage = a.damage
? `, ${stripAngleBrackets(stripTags(a.damage))}`
: ""; : "";
const damage = a.damage ? `, ${stripTags(a.damage)}` : "";
return { return {
name: capitalize(stripTags(a.name)), name: capitalize(stripTags(a.name)),
segments: [ segments: [