Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request new feature ".toTitleCase" #77

Closed
chongwang87 opened this issue Feb 20, 2014 · 6 comments
Closed

Request new feature ".toTitleCase" #77

chongwang87 opened this issue Feb 20, 2014 · 6 comments

Comments

@chongwang87
Copy link

Wish to has a function to convert string to title case.

for example:
'a simple CCTV test' -> 'A Simple CCTV Test'

It's good only convert words except 'a, and, the... etc'
And do not lower user's input upper case

@jprichardson
Copy link
Owner

This is a good idea, I'll leave it open for reference.

@chongwang87
Copy link
Author

any idea when will this implement?

@jprichardson
Copy link
Owner

Not sure, but you can extend string.js without too much trouble:

var S = require('string')

MyS.prototype = S('');
MyS.prototype.constructor = MyS;

function MyS(val) {
  this.setValue(val);
}

MyS.prototype.toTitleCase = function() {
  var newStr = this.s.split(' ').map(function(w) { return w.substr(0, 1).toUpperCase() + w.substr(1) }).join(' ');
  return new this.constructor(newStr);
}

S = function(str) {
  return new MyS(str);
}

var w = S('a simple CCTV test').toTitleCase().s;
console.log(w)

as an example...

@chongwang87
Copy link
Author

i need this function in a lot of places, can this be add in to core? So i no need to copy paste the script a over my website.

@jprichardson
Copy link
Owner

Sure. Pull requests with tests welcome.

On Monday, May 19, 2014, chongwang87 notifications@github.com wrote:

i need this function in a lot of places, can this be add in to core? So i
no need to copy paste the script a over my website.


Reply to this email directly or view it on GitHubhttps://github.com//issues/77#issuecomment-43475511
.

Simple & Secure Bitcoin Wallet: https://www.coinbolt.com
Follow me on Twitter: http://twitter.com/jprichardson

@chongwang87
Copy link
Author

Pull request created
#87

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants