to-title-case
Advanced tools
Comparing version 0.1.5 to 1.0.0
1.0.0 - January 21, 2016 | ||
------------------------ | ||
* drop component support | ||
* cleanup readme | ||
* add travis ci | ||
* update coding style | ||
0.1.5 - September 26, 2014 | ||
@@ -31,2 +38,2 @@ -------------------------- | ||
-------------------------- | ||
:sparkles: | ||
:sparkles: |
46
index.js
try { | ||
var escape = require('escape-regexp'); | ||
} catch (e) { | ||
var escape = require('escape-regexp-component'); | ||
} | ||
var sentence = require('to-sentence-case') | ||
var escape = require('escape-regexp-component') | ||
var minors = require('title-case-minors') | ||
var capital = require('to-capital-case'); | ||
var minors = require('title-case-minors'); | ||
/** | ||
* Expose `toTitleCase`. | ||
* Export. | ||
*/ | ||
module.exports = toTitleCase; | ||
module.exports = toTitleCase | ||
/** | ||
* Minors. | ||
* Matchers. | ||
*/ | ||
var escaped = minors.map(escape); | ||
var minorMatcher = new RegExp('[^^]\\b(' + escaped.join('|') + ')\\b', 'ig'); | ||
var colonMatcher = /:\s*(\w)/g; | ||
var escaped = minors.map(escape) | ||
var minorMatcher = new RegExp('[^^]\\b(' + escaped.join('|') + ')\\b', 'ig') | ||
var punctuationMatcher = /:\s*(\w)/g | ||
/** | ||
* Convert a `string` to camel case. | ||
* Convert a `string` to title case. | ||
* | ||
@@ -35,11 +27,13 @@ * @param {String} string | ||
function toTitleCase (string) { | ||
return capital(string) | ||
function toTitleCase(string) { | ||
return sentence(string) | ||
.replace(/(^|\s)(\w)/g, function (matches, previous, letter) { | ||
return previous + letter.toUpperCase() | ||
}) | ||
.replace(minorMatcher, function (minor) { | ||
return minor.toLowerCase(); | ||
return minor.toLowerCase() | ||
}) | ||
.replace(colonMatcher, function (letter) { | ||
return letter.toUpperCase(); | ||
}); | ||
} | ||
.replace(punctuationMatcher, function (letter) { | ||
return letter.toUpperCase() | ||
}) | ||
} |
{ | ||
"name": "to-title-case", | ||
"version": "1.0.0", | ||
"description": "Convert a string to title case.", | ||
"repository": "git://github.com/ianstormtaylor/to-title-case.git", | ||
"license": "MIT", | ||
"version": "0.1.5", | ||
"description": "Convert a string to title case.", | ||
"dependencies": { | ||
"escape-regexp-component": "^1.0.2", | ||
"title-case-minors": "^1.0.0", | ||
"to-capital-case": "^1.0.0", | ||
"to-sentence-case": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^2.3.4" | ||
}, | ||
"keywords": [ | ||
@@ -12,8 +21,3 @@ "title", | ||
"string" | ||
], | ||
"dependencies": { | ||
"escape-regexp-component": "1.0.2", | ||
"title-case-minors": "0.0.2", | ||
"to-capital-case": "0.1.1" | ||
} | ||
} | ||
] | ||
} |
@@ -1,19 +0,24 @@ | ||
# to-title-case | ||
Convert a string to a title case. | ||
# to-title-case [![Build Status](https://travis-ci.org/ianstormtaylor/to-space-case.svg?branch=master)](https://travis-ci.org/ianstormtaylor/to-space-case) | ||
Convert a string to a title case. Part of the series of [case helpers](https://github.com/ianstormtaylor/to-case). | ||
## Installation | ||
$ component install ianstormtaylor/to-title-case | ||
$ npm install to-title-case | ||
``` | ||
$ npm install to-title-case | ||
``` | ||
## Example | ||
```js | ||
var title = require('to-title-case'); | ||
var toTitleCase = require('to-title-case'); | ||
title('the catcher in the rye'); | ||
toTitleCase('the catcher in the rye'); | ||
// "The Catcher in the Rye" | ||
``` | ||
## API | ||
@@ -23,6 +28,15 @@ | ||
Returns the title-case variant of a `string`. | ||
Returns the `string` converted to title case, preserving punctuation. | ||
## License | ||
MIT | ||
The MIT License (MIT) | ||
Copyright © 2016, Ian Storm Taylor | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
42
1
5370
4
1
7
68
1
+ Addedto-sentence-case@^1.0.0
+ Addedtitle-case-minors@1.0.0(transitive)
+ Addedto-capital-case@1.0.0(transitive)
+ Addedto-no-case@1.0.2(transitive)
+ Addedto-sentence-case@1.0.0(transitive)
+ Addedto-space-case@1.0.0(transitive)
- Removedtitle-case-minors@0.0.2(transitive)
- Removedto-capital-case@0.1.1(transitive)
- Removedto-no-case@0.1.1(transitive)
Updatedtitle-case-minors@^1.0.0
Updatedto-capital-case@^1.0.0