Nodejs Utililty Methods String to Underscore

List of utility methods to do String to Underscore

Description

The list of methods to do String to Underscore are organized into topic(s).

Method

underscore()
String.prototype.underscore = function () {
    var str = this;
    str = str.replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2');
    str = str.replace(/([a-z\d])([A-Z])/g, '$1_$2');
    str = str.replace(/\-/g, '_');
    return str.toLowerCase();
};
underscorize()
String.prototype.underscorize = function() {
  return this.replace(/([A-Z])/g, function($1) {
    return "_" + $1.toLowerCase();
  }).replace(/^_/g, "");
};