Файл: library/wysihtml5/src/lang/string.js
Строк: 43
<?php
(function() {
var WHITE_SPACE_START = /^s+/,
WHITE_SPACE_END = /s+$/,
ENTITY_REG_EXP = /[&<>"]/g,
ENTITY_MAP = {
'&': '&',
'<': '<',
'>': '>',
'"': """
};
wysihtml5.lang.string = function(str) {
str = String(str);
return {
/**
* @example
* wysihtml5.lang.string(" foo ").trim();
* // => "foo"
*/
trim: function() {
return str.replace(WHITE_SPACE_START, "").replace(WHITE_SPACE_END, "");
},
/**
* @example
* wysihtml5.lang.string("Hello #{name}").interpolate({ name: "Christopher" });
* // => "Hello Christopher"
*/
interpolate: function(vars) {
for (var i in vars) {
str = this.replace("#{" + i + "}").by(vars[i]);
}
return str;
},
/**
* @example
* wysihtml5.lang.string("Hello Tom").replace("Tom").with("Hans");
* // => "Hello Hans"
*/
replace: function(search) {
return {
by: function(replace) {
return str.split(search).join(replace);
}
};
},
/**
* @example
* wysihtml5.lang.string("hello<br>").escapeHTML();
* // => "hello<br>"
*/
escapeHTML: function() {
return str.replace(ENTITY_REG_EXP, function(c) { return ENTITY_MAP[c]; });
}
};
};
})();
?>