Home / File/ tmpl.js — express Source File

tmpl.js — express Source File

Architecture documentation for tmpl.js, a javascript file in the express codebase.

Entity Profile

Relationship Graph

Source Code

var fs = require('node:fs');

var variableRegExp = /\$([0-9a-zA-Z\.]+)/g;

module.exports = function renderFile(fileName, options, callback) {
  function onReadFile(err, str) {
    if (err) {
      callback(err);
      return;
    }

    try {
      str = str.replace(variableRegExp, generateVariableLookup(options));
    } catch (e) {
      err = e;
      err.name = 'RenderError'
    }

    callback(err, str);
  }

  fs.readFile(fileName, 'utf8', onReadFile);
};

function generateVariableLookup(data) {
  return function variableLookup(str, path) {
    var parts = path.split('.');
    var value = data;

    for (var i = 0; i < parts.length; i++) {
      value = value[parts[i]];
    }

    return value;
  };
}

Domain

Subdomains

Frequently Asked Questions

What does tmpl.js do?
tmpl.js is a source file in the express codebase, written in javascript. It belongs to the ExpressCore domain, PrototypalExtension subdomain.
What functions are defined in tmpl.js?
tmpl.js defines 2 function(s): generateVariableLookup, module.
Where is tmpl.js in the architecture?
tmpl.js is located at test/support/tmpl.js (domain: ExpressCore, subdomain: PrototypalExtension, directory: test/support).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free