question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use Case Suggestion: Make First Letter Uppercase Of Each Word

See original GitHub issue

		function toUpper(str) {
			if(typeof str === "undefined"){return "";}
			if(typeof str.length < 2){return "";}
			
			return_string = decodeEntities(str)
				.toLowerCase()
				.split(' ')				
				.map(function(word) {
					if(typeof word[0] === "undefined"){return "";}
					return word[0].toUpperCase() + word.substr(1);
				})
				.join(' ');

			return_string = return_string
				.split('-')				
				.map(function(word) {
					if(typeof word[0] === "undefined"){return "";}
					return word[0].toUpperCase() + word.substr(1);
				})
				.join('-');	

			return return_string
		}

     console.log(toUpper("make words with uppercase first letter. Works-even-with-spaces"));

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
randallwhitlockcommented, Dec 15, 2017
const titleCase = (str) => {
  str = str.replace(/([^\W_]+[^\s-]*) */g, (txt) => {
    return txt.charAt(0).toUpperCase() + txt.substr(1);
  });
  return str;
}

console.log(titleCase('this is s a string')) //'This Is S A String'
1reaction
kylealwyncommented, Dec 15, 2017
import startCase from 'lodash/startCase'

console.log(startCase('i understand this is probably showcasing vanilla snipz but tested code you dont have to maintain is 💯')) // I Understand This Is Probably Showcasing Vanilla Snipz But Tested Code You Dont Have To Maintain is 💯

Great work on the site!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Capitalize the first letter of every word - javascript
Turn to lower case, cut into individual words by splitting by whitespace, toUpperCase() on the first char of each word. – user684934. Sep...
Read more >
How to Uppercase the First Letter of a Word in Python
In this article, we focus on a specific string operation in Python: how to change the letter case of the first letter in...
Read more >
Capitalise first letter of each word - Power Platform Community
Use an expression to make every word lower case with the first letter still in upper case. concat(substring(item(),0,1),tolower(substring(item(),1 ...
Read more >
How to Capitalize the First Letter of Each Word in JavaScript
Use the built-in method toUpperCase() on the letter you want to transform to uppercase. Capitalize the first letter of each word from a...
Read more >
How do I Capitalize First Letter of Each Word of a Field?
Solved: Is there a way that I can have an end-user enter a sentence into a normal string field and that each first...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found