function Fake (faker) {
  
  this.fake = function fake (str) {
    // setup default response as empty string
    var res = '';

    // if incoming str parameter is not provided, return error message
    if (typeof str !== 'string' || str.length === 0) {
      res = 'string parameter is required!';
      return res;
    }

    // find first matching {{ and }}
    var start = str.search('{{');
    var end = str.search('}}');

    // if no {{ and }} is found, we are done
    if (start === -1 && end === -1) {
      return str;
    }

    // console.log('attempting to parse', str);

    // extract method name from between the {{ }} that we found
    // for example: {{name.firstName}}
    var method = str.substr(start + 2,  end - start - 2);
    method = method.replace('}}', '');
    method = method.replace('{{', '');

    // console.log('method', method)

    // split the method into module and function
    var parts = method.split('.');

    if (typeof faker[parts[0]] === "undefined") {
      throw new Error('Invalid module: ' + parts[0]);
    }

    if (typeof faker[parts[0]][parts[1]] === "undefined") {
      throw new Error('Invalid method: ' + parts[0] + "." + parts[1]);
    }

    // assign the function from the module.function namespace
    var fn = faker[parts[0]][parts[1]];

    // replace the found tag with the returned fake value
    res = str.replace('{{' + method + '}}', fn());

    // return the response recursively until we are done finding all tags
    return fake(res);    
  }
  
  return this;
  
  
}
/*
  fake.js - generator method for combining faker methods based on string input

*/
fake.js - generator method for combining faker methods based on string input
fake . js - generator method for combining faker methods based on string input
function Fake (faker) {
  this.fake = function fake (str) {
    var res = '';
    if (typeof str !== 'string' || str.length === 0) {
      res = 'string parameter is required!';
      return res;
    }
    var start = str.search('{{');
    var end = str.search('}}');
    if (start === -1 && end === -1) {
      return str;
    }
    var method = str.substr(start + 2,  end - start - 2);
    method = method.replace('}}', '');
    method = method.replace('{{', '');
    var parts = method.split('.');
    if (typeof faker[parts[0]] === "undefined") {
      throw new Error('Invalid module: ' + parts[0]);
    }
    if (typeof faker[parts[0]][parts[1]] === "undefined") {
      throw new Error('Invalid method: ' + parts[0] + "." + parts[1]);
    }
    var fn = faker[parts[0]][parts[1]];
    res = str.replace('{{' + method + '}}', fn());
    return fake(res);    
  }
  return this;
}
function Fake ( faker ) { this . fake = function fake ( str ) { var res = '' ; if ( typeof str !== 'string' || str . length === 0 ) { res = 'string parameter is required!' ; return res ; } var start = str . search ( '{{' ) ; var end = str . search ( '}}' ) ; if ( start === - 1 && end === - 1 ) { return str ; } var method = str . substr ( start + 2 , end - start - 2 ) ; method = method . replace ( '}}' , '' ) ; method = method . replace ( '{{' , '' ) ; var parts = method . split ( '.' ) ; if ( typeof faker [ parts [ 0 ] ] === "undefined" ) { throw new Error ( 'Invalid module: ' + parts [ 0 ] ) ; } if ( typeof faker [ parts [ 0 ] ] [ parts [ 1 ] ] === "undefined" ) { throw new Error ( 'Invalid method: ' + parts [ 0 ] + "." + parts [ 1 ] ) ; } var fn = faker [ parts [ 0 ] ] [ parts [ 1 ] ] ; res = str . replace ( '{{' + method + '}}' , fn ( ) ) ; return fake ( res ) ; } return this ; }
fake.js - generator method for combining faker methods based on string input
fake . js - generator method for combining faker methods based on string input
// setup default response as empty string // if incoming str parameter is not provided, return error message // find first matching {{ and }} // if no {{ and }} is found, we are done // console.log('attempting to parse', str); // extract method name from between the {{ }} that we found // for example: {{name.firstName}} // console.log('method', method) // split the method into module and function // assign the function from the module.function namespace // replace the found tag with the returned fake value // return the response recursively until we are done finding all tags