Skip to content

NoobSolver/title-case-converter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

title-case-converter

title-case-converter is a simple wrapper around title-case-converter to convert first letter of string to capital letter.

Install

Install through npm

npm install title-case-converter

Usage

Require the module

 let capitalizedWord = word.slice(0, 1).toUpperCase() + word.slice(1);

Convert with convert()

 const converter = require("title-case-converter")
 let convertedSentence = converter("my name is gaurav") //"My Name Is Gaurav"

Where

  • text is either a Buffer or a String to be converted
  • toCharset is the characterset to convert the string
  • fromCharset (optional, defaults to UTF-8) is the source charset

Output of the conversion is always a Buffer object.

Example

let capitalized = []
let words = sentence.split(" ") //split the sentence into words
words.forEach(word => { 
	
    let capitalizedWord = word.slice(0, 1).toUpperCase() + word.slice(1)
     //capitalize the first letter of every word
    capitalized.push(capitalizedWord)         
})
let converted = capitalized.join(" ") 
return converted

License

MIT

About

Package for converting the first letter of a word in a sentence into capital letter.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published