Skip to content

Instantly share code, notes, and snippets.

@jaywhy13
Forked from sentientmonkey/pluralize.js
Created June 5, 2013 06:00
Show Gist options
  • Save jaywhy13/5711891 to your computer and use it in GitHub Desktop.
Save jaywhy13/5711891 to your computer and use it in GitHub Desktop.
Number.prototype.plural = function(){
if(this > 1 || this == 0){
return true;
} else {
return false;
}
}
String.prototype.pluralize_rules = function(){
return [[new RegExp('$', 'gi'), 's']];
}
String.prototype.pluralize = function(number){
var str = this;
if(number.plural()){
var str = this;
var rules = this.pluralize_rules();
for(var r=0; r < rules.length; r++){
if(str.match(rules[r][0])){
str = str.replace(rules[r][0], rules[r][1]);
}
}
}
return str.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment