daggerheart/module/enrichers/parser.mjs
Carlos Fernandez 5be79f4ab8
Some checks are pending
Project CI / build (24.x) (push) Waiting to run
Fix several issues with inline damage (#1973)
2026-06-05 11:33:20 +02:00

20 lines
757 B
JavaScript

/**
* @param {string} paramString The parameter inside the brackets of something like @Template[] to parse
* @param {Object} options
* @param {string} options.first If set, the first parameter is treated as a value with this as its key
* @returns {Record<string, string | undefined> | null}
*/
export function parseInlineParams(paramString, { first } = {}) {
const parts = paramString.split('|').map(x => x.trim());
const params = {};
for (const [idx, param] of parts.entries()) {
if (first && idx === 0 && !param.includes(':')) {
params[first] = param;
} else {
const parts = param.split(':');
params[parts[0]] = parts.length > 1 ? parts[1] : true;
}
}
return params;
}