let variables = {};

const VAR_REGEX = /\$([a-zA-Z0-9_-]*)/g;

export function addVariables(...varObjects) {
  varObjects.forEach(vO => {
    for(let k in vO) {
      variables[k] = vO[k];
    }
  });
}

export function getVariable(key) {
  return variables[key];
}

export function parseVariables(string, touchedVariables) {
  if(typeof string !== 'string') return string;

  return string.replace(VAR_REGEX, (v1, varName) => {
    const result = variables[varName];
    if(touchedVariables) {
      touchedVariables[`$${varName}`] = result;
    }
    if(typeof result === 'undefined') {
      console.warn('swiss unknown variable: ' + varName);
    } else if(['bool', 'number', 'string'].indexOf(typeof result) === -1) {
      console.warn(`swiss invalid varible of type: ${typeof result}. Expected string, number of bool`);
    } else {
      return result;
    }
    return v1;
  });
}
@@ -150,24 +150,216 @@
  k in vO) %7B%0A
+      if(%5B'bool', 'number', 'string'%5D.indexOf(typeof vO%5Bk%5D) === -1)%7B%0A        console.warn(%60swiss invalid varible of type: $%7Btypeof result%7D. Expected string, number of bool%60);%0A      %7D else %7B%0A  
       variab
@@ -374,16 +374,24 @@
  vO%5Bk%5D;%0A
+      %7D%0A
     %7D%0A  
@@ -730,26 +730,34 @@
 %7D%60%5D = result
+ %7C%7C null
 ;%0A
-
     %7D%0A    if
@@ -786,24 +786,24 @@
 defined') %7B%0A
+
       consol
@@ -852,188 +852,8 @@
 e);%0A
-    %7D else if(%5B'bool', 'number', 'string'%5D.indexOf(typeof result) === -1) %7B%0A      console.warn(%60swiss invalid varible of type: $%7Btypeof result%7D. Expected string, number of bool%60);%0A
     

check if variable is valid upon assigning