Nodejs String Escape escape()

Here you can find the source of escape()

Method Source Code

String.prototype.escape = function () {
    var entityMap = {
        '&': '&',
        '<': '&lt;',
        '>': '&gt;',
        '"': '&quot;',
        "'": '&#39;',
        '/': '&#x2F;'
    };/*from   www.  j  a  v a2  s .  c  o  m*/

    return this.replace(/[&<>"'\/]/g, function (s) {
        return entityMap[s];
    });
};

Related

  1. escape()
    String.prototype.escape = function(){
      return this.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/])/g,'\\$1')
    
  2. escape()
    String.prototype.escape = function () {
        var entityMap = {
            "&": "&amp;",
            "<": "&lt;",
            ">": "&gt;",
            '"': '&quot;',
            "'": '&#39;'
        };
        return this.replace(/[&<>"']/g, function (s) {
    ...
    
  3. escape()
    String.prototype.escape = function() {
        var tagsToReplace = {
            '&': '&amp;',
            '<': '&lt;',
            '>': '&gt;'
        };
        return this.replace(/[&<>]/g, function(tag) {
            return tagsToReplace[tag] || tag;
        });
    ...
    
  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() {
      return this
        .replace(/&(?!\w+;)/g, '&amp;')
        .replace(/</g, '&lt;')
        .replace(/>/g, '&gt;')
        .replace(/"/g, '&quot;');
    };
    
  6. escape()
    String.prototype.escape = function () {
        var tagsToReplace = {
            '&': '&amp;',
            '<': '&lt;',
            '>': '&gt;',
        };
        return this.replace(/[&<>]/g, function (tag) {
            return tagsToReplace[tag] || tag;
        });
    ...
    
  7. escape()
    String.prototype.escape = function() {
      var tagsToReplace = {
          '&': '&amp;',
          '<': '&lt;',
          '>': '&gt;'
      };
      return nl2br(this.replace(/[&<>]/g, function(tag) {
          return tagsToReplace[tag] || tag;
      }));
    ...
    
  8. escape()
    String.prototype.escape = function() {
      return escape(this.replace(/\s/g, '-'));