/* Copyright (c) 2007 Ryan Schuft (ryan.schuft@gmail.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* This code is based in part on the work done in Ruby to support infection as part of Ruby on Rails in the ActiveSupport's Inflector and Inflections classes. It was initally ported to Javascript by Ryan Schuft (ryan.schuft@gmail.com). The code is available at http://code.google.com/p/inflection-js/ The basic usage is: 1. Include this script on your web page. 2. Call functions on any String object in Javascript Currently implemented functions: String.pluralize(plural) == String renders a singular English language noun into its plural form normal results can be overridden by passing in an alternative String.singularize(singular) == String renders a plural English language noun into its singular form normal results can be overridden by passing in an alterative String.camelize(lowFirstLetter) == String renders a lower case underscored word into camel case the first letter of the result will be upper case unless you pass true also translates "/" into "::" (underscore does the opposite) String.underscore() == String renders a camel cased word into words seperated by underscores also translates "::" back into "/" (camelize does the opposite) String.humanize(lowFirstLetter) == String renders a lower case and underscored word into human readable form defaults to making the first letter capitalized unless you pass true String.capitalize() == String renders all characters to lower case and then makes the first upper String.dasherize() == String renders all underbars and spaces as dashes String.titleize() == String renders words into title casing (as for book titles) String.demodulize() == String renders class names that are prepended by modules into just the class String.tableize() == String renders camel cased singular words into their underscored plural form String.classify() == String renders an underscored plural word into its camel cased singular form String.foreign_key(dropIdUbar) == String renders a class name (camel cased singular noun) into a foreign key defaults to seperating the class from the id with an underbar unless you pass true String.ordinalize() == String renders all numbers found in the string into their sequence like "22nd" */ /* This function adds plurilization support to every String object Signature: String.pluralize(plural) == String Arguments: plural - String (optional) - overrides normal output with said String Returns: String - singular English language nouns are returned in plural form Examples: "person".pluralize() == "people" "octopus".pluralize() == "octopi" "Hat".pluralize() == "Hats" "person".pluralize("guys") == "guys" */ if(!String.prototype.pluralize)String.prototype.pluralize=function(plural) { var str=this; if(plural)str=plural; else { var uncountable=false; for(var x=0;!uncountable&&x