Skip to content

Commit

Permalink
Merge pull request #35
Browse files Browse the repository at this point in the history
ADDED: String Function: 'toHtmlEntities, fromHtmlEntities'
  • Loading branch information
SagnikGanguly96 authored Dec 14, 2022
2 parents 3181bca + 0c191d2 commit 420331d
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/js/helpers/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,31 @@ String.prototype.guid = function() {
};

String.prototype.ltrim = function(s) {
return this.replace(new RegExp("^" + s + "*"), '');
return this.replace(new RegExp("^" + s + "*"), "");
};
String.prototype.rtrim = function(s) {
return this.replace(new RegExp(s + "*$"), '');
return this.replace(new RegExp(s + "*$"), "");
};

$.expr[':'].textEquals = $.expr.createPseudo(function(arg) {
/**
* Convert a string to HTML entities
*/
String.prototype.toHtmlEntities = function() {
return escapeHTML(this);
};

/**
* Create string from HTML entities
*/
String.fromHtmlEntities = function(string) {
return (string + "").replace(/&#\d+;/gm, function(s) {
return String.fromCharCode(s.match(/\d+/gm)[0]);
});
};

$.expr[":"].textEquals = $.expr.createPseudo(function(arg) {
arg = arg.trim();
return function(elem) {
return $(elem).text().trim().match("^" + arg + "$");
}
};
});

0 comments on commit 420331d

Please sign in to comment.