Moved inline cacultion regex to a constant to ensure constistency
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
|
import INLINE_CALCULATION_REGEX from '/imports/constants/INLINE_CALCULTION_REGEX.js';
|
||||||
|
|
||||||
export default function embedInlineCalculations(string, calculations){
|
export default function embedInlineCalculations(string, calculations){
|
||||||
if (!string) return '';
|
if (!string) return '';
|
||||||
if (!calculations) return string;
|
if (!calculations) return string;
|
||||||
let index = 0;
|
let index = 0;
|
||||||
return string.replace(/\{([^{}]*)\}/g, () => {
|
return string.replace(INLINE_CALCULATION_REGEX, () => {
|
||||||
let comp = calculations && calculations[index++];
|
let comp = calculations && calculations[index++];
|
||||||
return comp && comp.result ? comp.result : string;
|
return comp && comp.result ? comp.result : string;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import evaluateCalculation from '/imports/api/creature/computation/engine/evaluateCalculation.js';
|
import evaluateCalculation from '/imports/api/creature/computation/engine/evaluateCalculation.js';
|
||||||
|
import INLINE_CALCULATION_REGEX from '/imports/constants/INLINE_CALCULTION_REGEX.js';
|
||||||
import ErrorNode from '/imports/parser/parseTree/ErrorNode.js';
|
import ErrorNode from '/imports/parser/parseTree/ErrorNode.js';
|
||||||
import { union } from 'lodash';
|
import { union } from 'lodash';
|
||||||
|
|
||||||
@@ -14,7 +15,7 @@ export default function computeInlineCalculations(prop, memo){
|
|||||||
function computeInlineCalcsForField(prop, memo, field){
|
function computeInlineCalcsForField(prop, memo, field){
|
||||||
let string = prop[field];
|
let string = prop[field];
|
||||||
let inlineComputations = [];
|
let inlineComputations = [];
|
||||||
let matches = string.matchAll(/\{([^{}]*)\}/g);
|
let matches = string.matchAll(INLINE_CALCULATION_REGEX);
|
||||||
for (let match of matches){
|
for (let match of matches){
|
||||||
let calculation = match[1];
|
let calculation = match[1];
|
||||||
let {
|
let {
|
||||||
|
|||||||
3
app/imports/constants/INLINE_CALCULTION_REGEX.js
Normal file
3
app/imports/constants/INLINE_CALCULTION_REGEX.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
const INLINE_CALCULATION_REGEX = /\{([^{}]*)\}/g;
|
||||||
|
|
||||||
|
export default INLINE_CALCULATION_REGEX;
|
||||||
Reference in New Issue
Block a user