Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
static parseNotation(notation){
const parsed = [];
// only continue if a notation was passed
if(notation) {
// build the regex for matching a die (including exploding and pool dice etc. notation)
const dieRegex = DiceRoll.notationPatterns.get('dieFull', 'g');
// split the notation into its parenthesis groupings
const groups = XRegExp.matchRecursive(
notation,
'\\(', '\\)',
'g',
{
valueNames: [
'between', 'left', 'match', 'right',
],
}
);
// loop through each group and parse it
groups.forEach(group => {
if (group.name === 'match') {
// this is a match within the parenthesis group (ie. `3d6+2` in `(3d6+2)*4`
// recursively parse it in case it has nested parenthesis
parsed.push(DiceRoll.parseNotation(group.value));
const matchRecursive = str => XRegExp.matchRecursive(str, '{', '}', 'gi')
function matchReplacePass(content) {
var matches = XRegExp.matchRecursive(content, rule.start, rule.end, 'gmi', {
valueNames: ['between', 'left', 'match', 'right']
});
var matchGroup = {
left: null,
match: null,
right: null
};
return matches.reduce(function (builder, match) {
switch(match.name) {
case 'between':
builder += match.value;
break;
case 'left':
matchGroup.left = startRegex.exec(match.value);