title-case-converter

Capitalises the first letter of every word in a sentence


Keywords
title-case, converter
License
MIT
Install
npm install title-case-converter@2.0.0

Documentation

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