/**
 * This file contains useful extension to the standard JS objects
 */

String.prototype.capitalize = function() {
  return this.charAt(0).toUpperCase() + this.slice(1);
}

/**
 * Method to work out plural of string
 *
 * Improvements to implement...
 * - Support case recognition (currently only lowercase.
 */
String.prototype.pluralise = function() {
  switch (true) {
    case /y$/.test(this):
      return this.replace(/y$/, 'ies');
      break;
    default:
      return this + 's';
  }

}

String.prototype.toCamelCase = function() {
    return this
        .replace(/([\s_][a-z])/g, function($1) { return $1.charAt(1).toUpperCase(); })
        .replace(/^./, function($1) { return $1.toUpperCase(); });

}

String.prototype.fromCamelCase = function() {
    return this
        .replace(/(^[A-Z])/, function($1) { return $1.toLowerCase(); })
        .replace(/([a-z][A-Z])/, function($1) { return $1.charAt(0) + '_' + $1.charAt(1).toLowerCase(); });

}
