Created
November 4, 2009 07:12
-
-
Save yoko/225877 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> | |
<title>String.prototype.capitalize</title> | |
<link rel="stylesheet" type="text/css" href="http://github.com/jquery/qunit/raw/master/qunit/qunit.css"/> | |
<script type="text/javascript" src="http://github.com/jquery/qunit/raw/master/qunit/qunit.js"></script> | |
<script type="text/javascript" src="String.prototype.capitalize.js"></script> | |
</head> | |
<body> | |
<h1 id="qunit-header">String.prototype.capitalize</h1> | |
<h2 id="qunit-banner"></h2> | |
<h2 id="qunit-userAgent"></h2> | |
<ol id="qunit-tests"></ol> | |
<script type="text/javascript"> | |
module('String.prototype.capitalize'); | |
test('capitalize', 3, function() { | |
equals('foo bar baz'.capitalize(), 'Foo Bar Baz'); | |
equals('foo-bar-baz'.capitalize(), 'Foo-Bar-Baz'); | |
equals('foo_bar_baz'.capitalize(), 'Foo_bar_baz'); | |
}); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.capitalize = function() { | |
return this.toString().replace(/\b[a-z]/g, function(w) { | |
return w.toUpperCase(); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment