Giter Club home page Giter Club logo

to-title-case's People

Contributors

dillonjay avatar gouch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

to-title-case's Issues

Small words as part of a noun or proper noun are lower-cased

The script obviously has no way of "knowing" the grammatical role of a word, which sometimes produces erroneous output.

For instance: "Review: The book On Again Off Again is horrible".toTitleCase() will produce Review: The Book on Again Off Again Is Horrible, which is wrong, as On Again Off Again is a proper noun in this case.

Similarly, the output of "The on button, a history".toTitleCase() will be The on Button, a History, which again, is erroneous as on button is a noun here, and should therefore be capitalized.

I can think of no programmatic way of solving such edge case, but think that it should at least be possible to manually override lower-casing, maybe by providing an argument controlling the forced lower-casing:
"Review: The book On Again Off Again is horrible".toTitleCase() ==> Review: The Book on Again Off Again Is Horrible

"Review: The book On Again Off Again is horrible".toTitleCase(false) ==> Review: The Book On Again Off Again Is Horrible

List of exclusions

It would be nice to have a list of exclusion words like TV, M.A.C., TMZ, etc.

Example, where 'on' and 'out' are part of the small words list already included on the script, and 'TMZ', 'TV' and 'M.A.S.H.' are part of a (yet to be included) list of exclusion words:

"Check out this TMZ article on TV right after M.A.S.H." => "Check out This TMZ Article on TV Right After M.A.S.H."

Reason for this? Suppose I receive a string from some ancient database where everything's stored in CAPS LOCK, like "BARNES AND NOBLE". If I use toLowerCase() before toTitleCase() it works ok, but it won't work if the string is like "TMZ AND AT&T PARTNERSHIP ROCKS THE WORLD".

Is not converting all caps intended?

If the value you are trying to convert is all caps, it is not converted to title case. Is this intentional? You can call .toLowerCase() first and then it works just fine.

var myTitle = 'MY TITLE'
console.log( myTitle.toTitleCase() ) // MY TITLE

console.log( myTitle.toLowerCase().toTitleCase() ) //My Title

Thanks!

All Uppercase to Title Case

If you start with a string that is all UPPERCASE, then it doesn't get converted to Title Case, it stays all uppercase. The simple way to change this would be to change line 9.

From:

this.replace(...)

To:

this.toLowerCase().replace(...)

Uppercase words are not converted to title case

"HELLO world".toTitleCase() returns "HELLO World" and not "Hello World".

It's possible this is by design, but I think it would be better if the function always returned Title Case unless there was a clear reason not to (i.e. a small word in your list, a website, etc). If you like it ignoring capitalized words, maybe you could add an example to the tests showing that it's intentional? Then the choice would be more explicit.

Thanks for publishing this btw!

Handling words with apostrophes

Words containing apostrophes aren't handled correctly.

Don'T --> Don'T

Related: converting all caps to title case in Excel has the same limitation

Upper case strings aren't converted to title case

Current implementation seems to assume that the argument value is already in lower case.

A quick (though not optimized) fix for this is to insert toLowerCase() in the return line:

  return this.toLowerCase().replace( ...

With this included, you wouldn't need to separately convert the short words to lower case. One lost feature with this approach is the ability to pass in a string with words (such as acronyms, etc.) in upper case, that the user wants to keep in upper case. To me, that's a reasonable trade-off (in favor of what, at least for my set of use cases, is much more common).

Thanks,
D

Period at end of quoted string

"this is a test." gets title cased to "This Is a test." instead of "This Is a Test."

A fix is to update the following code from:

// Ignore intentional capitalization
if (current.substr(1).search(/[A-Z]|\../) > -1) {
  return current;
}

to:

// Ignore intentional capitalization
if (current.substr(1).search(/[A-Z]|\.[a-z0-9\u00C0-\u00FF]/) > -1) {
  return current;
}

or possibly better using test() instead of search():

// Ignore intentional capitalization
if (/[A-Z]|\.[a-z0-9\u00C0-\u00FF]/.test(current.substr(1))) {
  return current;
}

Edge case with ellipsis

This string: On a Mission From... The Gods
Gets converted to: On a Mission From... the Gods

The should have stayed unchanged.

Forcing specific case in a title

I really like this function! It is tremendously helpful in insuring that all user-entered titles have a uniform format. However, there are sometimes exceptions, particularly in technical terms

For example, for the title "Degradation of mRNAs for Centromere and Telomere-Related Genes in Saccharomyces Cerevisiae"
the standard latin format for naming would have cerevisiae in lower case.

Would it be possible for you to incorporate a "tag" for your javascript function where it would pass the case through unchanged. In other words, if the tag was %%, the entry
"Genes In %%Saccharomyces cerevisiae%%"".toTitleCase()
would return the string "Genes in Saccharomyces cerevisiae" instead of Genes in Saccharomyces Cerevisiae?

This may be helpful for other users who want specific capitalization formats for specific words.

Thanks again!
Tom

"on-demand" in the middle expected to be "On-Demand"

Well it is an edge case, but

input: "CODIPHY: composing on-demand intelligent physical layers"
expects: "CODIPHY: Composing On-Demand Intelligent Physical Layers"
output: "CODIPHY: Composing on-Demand Intelligent Physical Layers"

Dutch not supported

There is an issue with the Dutch digraph “ij”. If a word starts with “ij”, for example “ijs” (Dutch for “ice”) it must be converted to “IJ” in title case.

Examples

  • “ijs” → “IJs”
  • “slijterij” →“Slijterij”
  • “mijn ijsbeer blijft in de noordelijke ijszee” → “Mijn IJsbeer Blijft in de Noordelijke IJszee”

ænima => æNima

Obviously the fault of RegEx's \W incorrectly matching 'æ', but it is an issue unfortunately.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.