diff --git a/History.md b/History.md index 47bb120..2eb891b 100644 --- a/History.md +++ b/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: \ No newline at end of file diff --git a/Readme.md b/Readme.md index b37c070..7e235e8 100644 --- a/Readme.md +++ b/Readme.md @@ -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" ``` diff --git a/component.json b/component.json index 5befebf..a75856d 100644 --- a/component.json +++ b/component.json @@ -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": "*" diff --git a/index.js b/index.js index 0b20098..f8a8f46 100644 --- a/index.js +++ b/index.js @@ -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; /** @@ -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(); + }); } \ No newline at end of file diff --git a/test/tests.js b/test/tests.js index e0af145..7ab9a1b 100644 --- a/test/tests.js +++ b/test/tests.js @@ -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')); }); }); \ No newline at end of file