Converts a camelized or dasherized string into an underscored one - Node.js String

Node.js examples for String:Case

Description

Converts a camelized or dasherized string into an underscored one

Demo Code


/**//from  w  ww  .  j a  va 2  s.  co  m
 * converts a camelized or dasherized string into an underscored one
 * @return String underscored version
 */
underscored: function() {
  return this.replace(/([a-z\d])([A-Z]+)/g, '$1_$2').replace(/\-/g, '_').toLowerCase();
},

Related Tutorials