Skip to content

Instantly share code, notes, and snippets.

@yoko
Created November 4, 2009 07:12
Show Gist options
  • Save yoko/225877 to your computer and use it in GitHub Desktop.
Save yoko/225877 to your computer and use it in GitHub Desktop.
<!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>
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