Nodejs String Escape escape()

Here you can find the source of escape()

Method Source Code

String.prototype.escape = function() {
  return escape(this.replace(/\s/g, '-'));
}

Related

  1. escape()
    String.prototype.escape = function () {
        var tagsToReplace = {
            '&': '&',
            '<': '&lt;',
            '>': '&gt;'
        };
        return this.replace(/[&<>]/g, function (tag) {
            return tagsToReplace[tag] || tag;
        });
    ...
    
  2. escape()
    String.prototype.escape = function () {
        var entityMap = {
            '&': '&amp;',
            '<': '&lt;',
            '>': '&gt;',
            '"': '&quot;',
            "'": '&#39;',
            '/': '&#x2F;'
        };
    ...
    
  3. escape()
    String.prototype.escape = function() {
      return this
        .replace(/&(?!\w+;)/g, '&amp;')
        .replace(/</g, '&lt;')
        .replace(/>/g, '&gt;')
        .replace(/"/g, '&quot;');
    };
    
  4. escape()
    String.prototype.escape = function () {
        var tagsToReplace = {
            '&': '&amp;',
            '<': '&lt;',
            '>': '&gt;',
        };
        return this.replace(/[&<>]/g, function (tag) {
            return tagsToReplace[tag] || tag;
        });
    ...
    
  5. escape()
    String.prototype.escape = function() {
      var tagsToReplace = {
          '&': '&amp;',
          '<': '&lt;',
          '>': '&gt;'
      };
      return nl2br(this.replace(/[&<>]/g, function(tag) {
          return tagsToReplace[tag] || tag;
      }));
    ...
    
  6. escapeSpecialChars()
    String.prototype.escapeSpecialChars = function() {
        return this.replace(/\\n/g, "\\n")
                   .replace(/\\'/g, "\\'")
                   .replace(/\\"/g, '\\"')
                   .replace(/\\&/g, "\\&")
                   .replace(/\\r/g, "\\r")
                   .replace(/\\t/g, "\\t")
                   .replace(/\\b/g, "\\b")
                   .replace(/\\f/g, "\\f");
    ...
    
  7. escapeSpecialChars()
    String.prototype.escapeSpecialChars = function () {
      return this.replace(/\\n/g, '\\\\n')
      .replace(/\\'/g, '\\\'')
      .replace(/\\'/g, '\\\'')
      .replace(/\\&/g, '\\\&')
      .replace(/\\r/g, '\\\r')
      .replace(/\\t/g, '\\\\t')
      .replace(/\\b/g, '\\\b')
      .replace(/\\f/g, '\\\f');
    ...
    
  8. escapeCharacters(chars)
    String.prototype.escapeCharacters = function(chars) {
        var foundChar = false;
        var length = chars.length;
        for (var i = 0; i < length; ++i) {
            if (this.indexOf(chars.charAt(i)) !== -1) {
                foundChar = true;
                break;
        if (!foundChar)
            return this;
        var result = "";
        for (var j = 0; j < this.length; ++j) {
            if (chars.indexOf(this.charAt(j)) !== -1)
                result += "\\";
            result += this.charAt(j);
        return result;
    };
    
  9. escapeForRegExp()
    String.prototype.escapeForRegExp = function() {
        return this.escapeCharacters("^[]{}()\\.$*+?|");
    };