Nodejs String to Upper Case toUpper()

Here you can find the source of toUpper()

Method Source Code

String.prototype.toUpper = function() {
  /**/* w  w  w  .ja va 2 s.c  o m*/
   * Return this String in uppercase.
   */
  return this.replace(/([a-z])/g, function(match){
    return String.fromCharCode(match.charCodeAt(0) - 32);
  });
};

Related

  1. toUpper()
    String.prototype.toUpper = function() {
      var pattern = /[a-z]/g;
      return this.replace(pattern, function(args) {
        return String.fromCharCode(args.charCodeAt() - 32);
      });
    };
    
  2. toUpper()
    String.prototype.toUpper = function(){
      result = this.replace(/[a-z]/g, function(x){
        return x.toUpperCase();
      });
      return result;
    };
    
  3. toUpper()
    String.prototype.toUpper = function() {
      return this.replace(/[a-z]/g, function(x) {
        return String.fromCharCode(x.charCodeAt(0) - 32);
      });
    
  4. toUpperCase()
    String.prototype.toUpperCase = function() {
      var s = "";
      for (var i = 0, len = this.length; i < len; i++) {
        var char = this.charCodeAt(i);
        if (char >= 97 && char <= 122) {
          s += String.fromCharCode(char - 32);
        } else {
          s += this[i];
      return s;
    };
    
  5. toUpperCaseFirst()
    String.prototype.toUpperCaseFirst = function() {
        return this.charAt(0).toUpperCase() + this.slice(1);
    };
    
  6. toUpperCaseFirst()
    String.prototype.toUpperCaseFirst = function() {
        return this[0].toUpperCase() + this.substr(1);
    };