See also: capitalizeFirstCharacter

Captitalizes the words in a string according to user specified rules.

Syntax

JSV_capitalize(expS [, donotCapitalizelList, RESETCASE, TITLECASE, CAPITALIZEHYPHENATEDWORDS])

Prototype

n/a

Returns

The capitalize function returns the string with each word capitalized according to user specified rules.

Parameters

The capitalize function uses the following arguments.

Argument Description
expS String containing the words to be capitalized. The following articles, conjunctions and prepositions are not capitalized unless TITLECASE is selected, then they will be capitalized according to title case rules:
donotCapitalizelList Optional. Comma-delimited list of words that should remain as they are passed (e.g., HTML, XML, JavaScript). See Argument Placement below.
RESETCASE Optional. Converts the entire string to lowercase before capitalizing each word. Useful for those instances where the string may be passed in ALL CAPITAL LETTERS. See Argument Placement below.
TITLECASE Optional. See the definition of title case. See Argument Placement below.
CAPITALIZEHYPHENATEDWORDS Optional. Capitalizes all words in the hyphenated word except articles, conjunctions and prepositions; and words defined in the donotCapitalizelList list. See Argument Placement below.

Remarks

Acronyms

Acronyms should be written in capital letters without periods. The only exceptions are those acronyms that have become accepted as common nouns, which are written in lowercase letters.

EXAMPLES: HTML, XML, laser, scuba

Initialisms, or acronyms, may be written either uppercase or lowercase. In general, do not use periods when they are uppercase; always use periods when they are lowercase. Two exceptions are geographic names and academic degrees.

EXAMPLES: EDP/e.d.p, EOM/e.o.m, OD/o.d.
  U.S.A., U.S.S.R.
  B.S., M.B.A.

Title Case

Capitlaize the initial letters of the first and last words of a title (e.g., book, article, play, or film) as well as all major words in the title. Do not capitalize articles (a, an, the), conjunctions (and, but, if), or short prepositions (at, in, on, of) unless they begin the title. Capitalize prepositions that contain more than four letters (between, because, until, after).

Brusaw, Charles T.; Alred, Gerald J.; Oliu, Walter E. Handbook of Technical Writing,
Second Edition, New York: St. Martin's Press, 1982.

Argument Placement

The arguments donotCapitalizelList, RESETCASE, TITLECASE, and CAPITALIZEHYPHENATEDWORDS can appear in any order after the string that is to be capitalized.

For example,
JSV_capitalize(expS, RESETCASE, TITLECASE, donotCapitalizelList)
and
JSV_capitalize(expS, CAPITALIZEHYPHENATEDWORDS, donotCapitalizelList, RESETCASE, TITLECASE)
are valid calls to the JSV_capitalize function.

Surnames

JSV_capitalize currently handles two surname (i.e., last name) capitalizations: those names that contain a single quote (e.g., O'Malley) and those names that start with 'Mc' (e.g., McCoy).

Dependencies

The JSV_capitalize function requires JavaScript 1.2 or better (Internet Explorer or Netscape 4+).

JSV_listAppend, JSV_capitalizeFirstCharacter

Example

The following lines of code

var myStatement = "DR. STRANGELOVE. OR, HOW I LEARNED TO STOP WORRYING AND LOVE THE BOMB";
document.write(
    JSV_capitalize(myStatement, TITLECASE)
);
myStatement = "JAVASCRIPT VISION is a product of roaring fork software and does not USE CUT-AND-PASTE";
document.write(
    JSV_capitalize(myStatement, "JavaScript", CAPITALIZEHYPHENATEDWORDS)
);
var myStatement = "jack o'malley";
document.write( JSV_capitalize(myStatement) );
var myStatement = "william mccoy";
document.write( JSV_capitalize(myStatement) );

produce