A collection of the String Object methods and functions.
Use them like any other string method.
"AnimalCracker".pluralize()
By default, camelize converts strings to UpperCamelCase. If the argument to camelize is set to true then camelize produces lowerCamelCase.
str.camelize();
"active_record".camelize(2); // "ActiveRecord" "post_category".camelize(true); // "postCategory"
Create a class name from a plural table name like Rails does for table names to models. Note that this returns a string and not a Class.
str.classify();
"egg_and_hams".classify(); // "EggAndHam" "posts".classify(); // "Post"
Replaces underscores and spaces with dashes in the string.
str.dasherize();
"puni_puni".dasherize(); // "puni-puni" "puni puni".dasherize(); // "puni-puni"
Creates a foreign key name from a class name.
str.foreign_key([dontUnderScoreId]);
"Message".foreign_key(); // "message_id" "Message".foreign_key(false); // "messageid"
Capitalizes the first word and turns underscores into spaces and strips a trailing "_id", if any. Like titleize, this is meant for creating pretty output.
str.humanize();
"employee_salary".humanize(); // "Employee salary" "author_id".humanize(); // "Author"
Turns a number into an ordinal string used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
str.ordinalize();
"1".ordinalize(); // "1st" "3".ordinalize(); // "3rd" "24".ordinalize(); // "24th"
See also Number.ordinalize.
Returns the plural form of the word in the string.
str.pluralize([count]);
"post".pluralize(); // "posts" "sheep".pluralize(); // "sheep" "matrix".pluralize(); // "matrices" "person".pluralize(); // "people" "CrazyOctopus".pluarlize(); // "CrazyOctopi" "post".pluralize(1); // "post" "post".pluralize(0); // "posts" "post".pluralize(10); // "posts"
The reverse of pluralize, returns the singular form of a word in a string.
str.singularize();
"posts".singularize(); // "post" "octopi".singularize(); // "octopus" "CamelOctopi".singularize(); // "CamelOctopus"
Create the name of a table like Rails does for models to table names. This method uses the pluralize method on the last word in the string.
str.tableize();
"RawScaledScorer".tableize(); // "raw_scaled_scorers" "egg_and_ham".tableize(); // "egg_and_hams" "fancyCategory".tableize(); // "fancy_categories"
Capitalizes all the words and replaces some characters in the string to create a nicer looking title.
str.titleize();
"man from the boondocks".titleize(); // "Man From the Boondocks" "x-men: the last stand".titleize(); // "X Men: The Last Stand"
The reverse of camelize. Makes an underscored, lowercase form from the expression in the string.
str.underscore();
"ActiveRecord".underscore(); // "active_record"
Capitalizes the first letter of a string.
str.capitalizeFirst();
"hello my name is Simon".capitalizeFirst(); // "Hell my name is Simon"
Lower cases the first letter of a string
str.lowercaseFirst();
"Hello my name is Simon".lowercaseFirst(); // "hello my name is Simon"
A note on comments here: These comments are moderated. No comments will show up until they are approved. Comments that are not productive (i.e. inflammatory, rude, etc) will not be approved.
Found a bug in this plugin? Please report it this repository's Github Issues.
blog comments powered by Disqus