if (typeof String.prototype.supplant !== 'function') {
String.prototype.supplant = function (o) {
return this.replace(/{{([^{}]*)}}/g, function (a, b) {
var r = o[b];
return typeof r === 'string' ? r : a;
});
};
}
var obj = {
a: "text",
b: "text 2",
c: "text 3"
}
var stringA = "http://{{a}}.something.com/",
stringB = "http://something.{{b}}.com/",
stringC = "http://something.com/{{c}}";
alert(stringA.supplant(obj));
function escapeHTML(text) {
var replacements = {
"<": "<",
">": ">",
"&": "&",
"\"": """
};
return text.replace(/[<>&"]/g, function(character) {
return replacements[character];
});
}
var list = [1,2,3,4,5,6,7,8,9];
list = list.sort(function() {
return Math.random() - 0.5;
});
console.log(list);