Skip to content

Instantly share code, notes, and snippets.

@itemir
Created May 3, 2023 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itemir/26638e9c470b990d801f472fd4e1d6c7 to your computer and use it in GitHub Desktop.
Save itemir/26638e9c470b990d801f472fd4e1d6c7 to your computer and use it in GitHub Desktop.
Capitalizes text including all words that are three letters or less
// 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