Nodejs Utililty Methods String Template

List of utility methods to do String Template

Description

The list of methods to do String Template are organized into topic(s).

Method

template()
String.prototype.template = function () {
  var current = this;
  function safeRegexEscape(str) {
    return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
  for (var i = 0; i < arguments.length; i++) {
    var arg = arguments[i];
    current = current.replace(new RegExp(safeRegexEscape("%%")), arg);
  return current;
};
template(fn, object)
String.prototype.template = function (fn, object) {'use strict';
  var
    hasTransformer = typeof fn === 'function',
    stringify = JSON.stringify,
    re = /\$\{([\S\s]*?)\}/g,
    strings = [],
    values = hasTransformer ? [] : strings,
    i = 0,
    str,
...
template(map)
String.prototype.template=function(map){
    return $(this.replace(/{([^}]+)}/g, function(m,g) {
        console.log(map, m,g)
        var segments = g.split('.');
        var val = map;
        for(var i in segments) {
            val=val[segments[i]];
        return val;
...
template(objVar)
String.prototype.template = function (objVar)
  var strVar = this;
  if(typeof objVar === "object")
    var length = strVar.length;
    var start = -1;
    var key = "";
    for(var index = 0; index < length; index++)
...
tmpl(d)
String.prototype.tmpl = function(d) {
  return this.replace(/\$\$([^$]+)\$\$/g,
    Function('d', 'return function(_,s){with(d) return eval(s)}')(d||{}))
};
tmpl(o)
String.prototype.tmpl = function(o) {
  return this.replace(/\{([^{}]*)\}/g, function(a, b) {
    var r = o[b];
    return typeof r === 'string' || typeof r === 'number' ? r : a;
  });
};
tmpl(obj)
String.prototype.tmpl = function(obj){
    var str, keys, _do;
    str = this.toString();
    if(!obj || typeof obj !== "object"){
        return str;
    keys = Object.keys(obj);
    _do = function(key){
        var rgx = new RegExp("#{"+key+"}", "g");
...