mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
Implement @Lookup enricher (#1196)
This commit is contained in:
parent
952779000d
commit
86eeba0648
6 changed files with 50 additions and 68 deletions
20
module/enrichers/parser.mjs
Normal file
20
module/enrichers/parser.mjs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/**
|
||||
* @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) {
|
||||
params[first] = param;
|
||||
} else {
|
||||
const parts = param.split(':');
|
||||
params[parts[0]] = parts.length > 1 ? parts[1] : true;
|
||||
}
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue