Pattern Library Utilities

convertRecursiveJsonVariables

method
exports.convertRecursiveJsonVariables()

@param Type Description
object Object self-referencing object with variables
regex Object regular expression to find variables within the object

Convert variables in a json object recursively

exports.convertRecursiveJsonVariables = function (object, regex) {
  'use strict';

  var checkForVariables;
  // go through objects's contents, find the variables, replace them
  while ((checkForVariables = regex.exec(JSON.stringify(object))) !== null) {
    object = resolve(object);
    checkForVariables = regex.exec(JSON.stringify(object));
  }
  return object;
};