Created
May 3, 2023 19:18
-
-
Save itemir/26638e9c470b990d801f472fd4e1d6c7 to your computer and use it in GitHub Desktop.
Capitalizes text including all words that are three letters or less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Capitalizes text including all words that are three letters or less | |
function capitalize(str) { | |
var lower = String(str).toLowerCase(); | |
return lower.replace(/\b([a-z]{1,3}\b|\w)/g, function(x) { | |
return x.toUpperCase(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment