Skip to content

Commit

Permalink
updated to-title-case, uppercase after colons
Browse files Browse the repository at this point in the history
  • Loading branch information
ianstormtaylor committed Sep 19, 2013
1 parent a22c40b commit b5ea01a
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 10 deletions.
5 changes: 5 additions & 0 deletions History.md
@@ -1,3 +1,8 @@
0.1.0 - September 18, 2013
--------------------------
* updated `to-capital-case`
* uppercase after colors

0.0.1 - September 18, 2013
--------------------------
:sparkles:
3 changes: 0 additions & 3 deletions Readme.md
Expand Up @@ -11,9 +11,6 @@
```js
var title = require('to-title-case');

title('the lion, the witch and the wardrobe');
// "The Lion, the Witch and the Wardrobe"

title('the catcher in the rye');
// "The Catcher in the Rye"
```
Expand Down
4 changes: 2 additions & 2 deletions component.json
Expand Up @@ -2,14 +2,14 @@
"name": "to-title-case",
"repo": "ianstormtaylor/to-title-case",
"license": "MIT",
"version": "0.0.1",
"version": "0.1.0",
"description": "Convert a non-title-case string to a title-case string.",
"keywords": ["title", "case", "titlecase", "string"],
"dependencies": {
"component/escape-regexp": "1.0.2",
"ianstormtaylor/map": "0.0.1",
"ianstormtaylor/title-case-minors": "0.0.2",
"ianstormtaylor/to-capital-case": "0.0.1"
"ianstormtaylor/to-capital-case": "0.1.0"
},
"development": {
"component/assert": "*"
Expand Down
11 changes: 8 additions & 3 deletions index.js
Expand Up @@ -18,6 +18,7 @@ module.exports = toTitleCase;

var escaped = map(minors, escape);
var minorMatcher = new RegExp('[^^]\\b(' + escaped.join('|') + ')\\b', 'ig');
var colonMatcher = /:\s*(\w)/g;


/**
Expand All @@ -29,7 +30,11 @@ var minorMatcher = new RegExp('[^^]\\b(' + escaped.join('|') + ')\\b', 'ig');


function toTitleCase (string) {
return capital(string).replace(minorMatcher, function (minor) {
return minor.toLowerCase();
});
return capital(string)
.replace(minorMatcher, function (minor) {
return minor.toLowerCase();
})
.replace(colonMatcher, function (letter) {
return letter.toUpperCase();
});
}
40 changes: 38 additions & 2 deletions test/tests.js
Expand Up @@ -3,8 +3,44 @@ describe('to-title-case', function () {
var assert = require('assert');
var title = require('to-title-case');

it('the catcher in the rye', function () {
assert('The Catcher in the Rye' == title('the catcher in the rye'));
it('shouldnt touch title case', function () {
assert('A Title: Case of String' == title('A Title: Case of String'));
});

it('should convert space case', function () {
assert('A Space Case of String' == title('a space case of string'));
});

it('should convert camel case', function () {
assert('A Camel Case of String' == title('aCamelCaseOfString'));
});

it('should convert snake case', function () {
assert('A Snake Case of String' == title('a_snake_case_of_string'));
});

it('should convert dot case', function () {
assert('A Dot Case of String' == title('a.dot.case.of.string'));
});

it('should convert constant case', function () {
assert('A Constant Case of String' == title('A_CONSTANT_CASE_OF_STRING'));
});

it('should convert "the lord of the flies"', function () {
assert('The Lord of the Flies' == title('the lord of the flies'));
});

it('should convert "a tale of two cities"', function () {
assert('A Tale of Two Cities' == title('a tale of two cities'));
});

it('should convert "the lion, the witch and the wardrobe"', function () {
assert('The Lion, the Witch and the Wardrobe' == title('the lion, the witch and the wardrobe'));
});

it('should convert "she: a history of adventure"', function () {
assert('She: A History of Adventure' == title('she: a history of adventure'));
});

});

0 comments on commit b5ea01a

Please sign in to comment.