@toolkit5e/statblock
v1.1.7
Published
Renders a D&D 5th edition statblock into a target DOM element. Framework-agnostic — works with any setup that has access to the DOM.
Maintainers
Readme
@toolkit5e/statblock
Renders a D&D 5th edition statblock into a target DOM element. Framework-agnostic — works with any setup that has access to the DOM.
Installation
npm install @toolkit5e/statblockUsage
import { renderStatblock } from '@toolkit5e/statblock';
import { scaleMonster, monsterList } from '@toolkit5e/monster-scaler';
const statblock = scaleMonster(monsterList.wolf, '5');
renderStatblock(statblock, document.getElementById('statblock-container'));The target element just needs to exist — renderStatblock clears it and builds all required DOM from scratch. Optional sections (saving throws, skills, resistances, languages, traits, bonus actions, legendary actions, etc.) are only added when the statblock has data for them.
API
renderStatblock(statblock, target)
Renders a Statblock object into the provided element.
statblock— aStatblockobject, typically fromscaleMonstertarget— anyHTMLElement; its contents will be replaced and its class set tostat-block
replaceTokensInString(str, statblock, trait)
Resolves template tokens in a description string. Tokens use {{tokenName}} or {{category:value}} syntax.
import { replaceTokensInString } from '@toolkit5e/statblock';
replaceTokensInString('{{description}} has advantage.', statblock, trait);
// "The wolf has advantage."Supported tokens include {{description}}, {{pronoun:subject}}, {{trait:DC}}, {{trait:damage}}, {{DC:str}}, {{size:-1}}, and more. Trait names also go through token replacement, so {{trait:count}} in a name resolves correctly (e.g. "Legendary Resistance (3/Day)"). If a {{trait:key}} value is a string matching an attack key on the statblock, it resolves to that attack's display name — used by tramplingCharge to reference the correct attack regardless of creature type.
License
MIT
