Comparing version 0.2.6 to 1.0.0
64
doT.js
// doT.js | ||
// 2011, Laura Doktorova, https://github.com/olado/doT | ||
// | ||
// doT.js is an open source component of http://bebedo.com | ||
// Licensed under the MIT license. | ||
// | ||
(function() { | ||
@@ -11,14 +9,16 @@ "use strict"; | ||
var doT = { | ||
version: '0.2.0', | ||
version: '1.0.0', | ||
templateSettings: { | ||
evaluate: /\{\{([\s\S]+?)\}\}/g, | ||
evaluate: /\{\{([\s\S]+?\}?)\}\}/g, | ||
interpolate: /\{\{=([\s\S]+?)\}\}/g, | ||
encode: /\{\{!([\s\S]+?)\}\}/g, | ||
use: /\{\{#([\s\S]+?)\}\}/g, | ||
useParams: /(^|[^\w$])def(?:\.|\[[\'\"])([\w$\.]+)(?:[\'\"]\])?\s*\:\s*([\w$\.]+|\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})/g, | ||
define: /\{\{##\s*([\w\.$]+)\s*(\:|=)([\s\S]+?)#\}\}/g, | ||
defineParams:/^\s*([\w$]+):([\s\S]+)/, | ||
conditional: /\{\{\?(\?)?\s*([\s\S]*?)\s*\}\}/g, | ||
iterate: /\{\{~\s*(?:\}\}|([\s\S]+?)\s*\:\s*([\w$]+)\s*(?:\:\s*([\w$]+))?\s*\}\})/g, | ||
varname: 'it', | ||
strip: true, | ||
append: true, | ||
varname: 'it', | ||
strip: true, | ||
append: true, | ||
selfcontained: false | ||
@@ -30,4 +30,2 @@ }, | ||
var global = (function(){ return this || (0,eval)('this'); }()); | ||
if (typeof module !== 'undefined' && module.exports) { | ||
@@ -38,3 +36,3 @@ module.exports = doT; | ||
} else { | ||
global.doT = doT; | ||
(function(){ return this || (0,eval)('this'); }()).doT = doT; | ||
} | ||
@@ -45,11 +43,11 @@ | ||
matchHTML = /&(?!#?\w+;)|<|>|"|'|\//g; | ||
return function(code) { | ||
return code ? code.toString().replace(matchHTML, function(m) {return encodeHTMLRules[m] || m;}) : code; | ||
return function() { | ||
return this ? this.replace(matchHTML, function(m) {return encodeHTMLRules[m] || m;}) : this; | ||
}; | ||
} | ||
global.encodeHTML = encodeHTMLSource(); | ||
String.prototype.encodeHTML = encodeHTMLSource(); | ||
var startend = { | ||
append: { start: "'+(", end: ")+'", startencode: "'+encodeHTML(" }, | ||
split: { start: "';out+=(", end: ");out+='", startencode: "';out+=encodeHTML("} | ||
append: { start: "'+(", end: ")+'", endencode: "||'').toString().encodeHTML()+'" }, | ||
split: { start: "';out+=(", end: ");out+='", endencode: "||'').toString().encodeHTML();out+='"} | ||
}, skip = /$^/; | ||
@@ -65,5 +63,8 @@ | ||
if (assign === ':') { | ||
def[code]= value; | ||
if (c.defineParams) value.replace(c.defineParams, function(m, param, v) { | ||
def[code] = {arg: param, text: v}; | ||
}); | ||
if (!(code in def)) def[code]= value; | ||
} else { | ||
eval("def['"+code+"']=" + value); | ||
new Function("def", "def['"+code+"']=" + value)(def); | ||
} | ||
@@ -74,3 +75,11 @@ } | ||
.replace(c.use || skip, function(m, code) { | ||
var v = eval(code); | ||
if (c.useParams) code = code.replace(c.useParams, function(m, s, d, param) { | ||
if (def[d] && def[d].arg && param) { | ||
var rw = (d+":"+param).replace(/'|\\/g, '_'); | ||
def.__exp = def.__exp || {}; | ||
def.__exp[rw] = def[d].text.replace(new RegExp("(^|[^\\w$])" + def[d].arg + "([^\\w$])", "g"), "$1" + param + "$2"); | ||
return s + "def.__exp['"+rw+"']"; | ||
} | ||
}); | ||
var v = new Function("def", "return " + code)(def); | ||
return v ? resolveDefs(c, v, def) : v; | ||
@@ -86,10 +95,5 @@ }); | ||
c = c || doT.templateSettings; | ||
var cse = c.append ? startend.append : startend.split, str, needhtmlencode, sid=0, indv; | ||
var cse = c.append ? startend.append : startend.split, needhtmlencode, sid = 0, indv, | ||
str = (c.use || c.define) ? resolveDefs(c, tmpl, def || {}) : tmpl; | ||
if (c.use || c.define) { | ||
var olddef = global.def; global.def = def || {}; // workaround minifiers | ||
str = resolveDefs(c, tmpl, global.def); | ||
global.def = olddef; | ||
} else str = tmpl; | ||
str = ("var out='" + (c.strip ? str.replace(/(^|\r|\n)\t* +| +\t*(\r|\n|$)/g,' ') | ||
@@ -103,3 +107,3 @@ .replace(/\r|\n|\t|\/\*[\s\S]*?\*\//g,''): str) | ||
needhtmlencode = true; | ||
return cse.startencode + unescape(code) + cse.end; | ||
return cse.start + unescape(code) + cse.endencode; | ||
}) | ||
@@ -122,7 +126,7 @@ .replace(c.conditional || skip, function(m, elsecase, code) { | ||
.replace(/\n/g, '\\n').replace(/\t/g, '\\t').replace(/\r/g, '\\r') | ||
.replace(/(\s|;|}|^|{)out\+='';/g, '$1').replace(/\+''/g, '') | ||
.replace(/(\s|;|}|^|{)out\+=''\+/g,'$1out+='); | ||
.replace(/(\s|;|\}|^|\{)out\+='';/g, '$1').replace(/\+''/g, '') | ||
.replace(/(\s|;|\}|^|\{)out\+=''\+/g,'$1out+='); | ||
if (needhtmlencode && c.selfcontained) { | ||
str = "var encodeHTML=(" + encodeHTMLSource.toString() + "());" + str; | ||
str = "String.prototype.encodeHTML=(" + encodeHTMLSource.toString() + "());" + str; | ||
} | ||
@@ -129,0 +133,0 @@ try { |
@@ -10,4 +10,7 @@ { | ||
], | ||
"version": "0.2.6", | ||
"main": "doT", | ||
"version": "1.0.0", | ||
"main": "index", | ||
"bin": { | ||
"dottojs": "./bin/dottojs" | ||
}, | ||
"homepage": "http://github.com/olado/doT", | ||
@@ -18,3 +21,15 @@ "repository": "git://github.com/olado/doT.git", | ||
"node >=0.2.6" | ||
] | ||
], | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"dependencies": { | ||
}, | ||
"devDependencies": { | ||
"commander": "*", | ||
"uglify-js": "*", | ||
"mkdirp": "*", | ||
"mocha":"*", | ||
"jshint":"*" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
15507
7
272
0
49
5
2
1