跳转至

dot🐟

Dot模板小工具

Quote

轻量前端渲染框架doT,适用自定义数据和模板简单渲染的场合,详情语法及使用参考dot官网1与美团相关解析2

一、dot模板

二、dot模板数据

仅仅支持json格式数据

三、结果

执行

四、内置函数

sayHello = function () {
    return this.name
}

// fisha_shafish_a -> fishaShafishA
camel = function(str, capitalizeFirstLetter) {
    var words = str.split('_');
    var camelCaseStr = words[0];

    for (var i = 1; i < words.length; i++) {
      var capitalizedWord = words[i].charAt(0).toUpperCase() + words[i].slice(1);
      camelCaseStr += capitalizedWord;
    }

    if (capitalizeFirstLetter) {
      camelCaseStr = camelCaseStr.charAt(0).toUpperCase() + camelCaseStr.slice(1);
    }

    return camelCaseStr;
}

// fishaShafishA -> fisha_shafish_a
convertToUnderscore = function(str, uppercase) {
  var underscoreStr = "";

  for (var i = 0; i < str.length; i++) {
    if (str.charAt(i) === str.charAt(i).toUpperCase() && i > 0) {
      underscoreStr += "_" + str.charAt(i).toLowerCase();
    } else {
      underscoreStr += str.charAt(i);
    }
  }

  if (uppercase) {
    underscoreStr = underscoreStr.toUpperCase();
  }

  return underscoreStr;
}

convertToUpperCase = function(str) {
    return str.toUpperCase();
}

convertToLowerCase = function(str) {
    return str.toLowerCase();
}