What is titleize?
The titleize npm package is a utility for converting strings to title case, where the first letter of each word is capitalized. It is useful for formatting titles or headings in text content.
What are titleize's main functionalities?
Title casing a single string
This feature allows you to convert a single string to title case. It capitalizes the first letter of each word while keeping the rest of the letters in lowercase.
const titleize = require('titleize');
console.log(titleize('mr. jones is from new york.')); // 'Mr. Jones Is From New York.'
Title casing an array of strings
This feature allows you to map over an array of strings and convert each one to title case.
const titleize = require('titleize');
const titles = ['mr. jones', 'dr. smith'];
const titleCased = titles.map(title => titleize(title));
console.log(titleCased); // ['Mr. Jones', 'Dr. Smith']
Ignoring certain words from being capitalized
This feature allows you to specify an array of words to ignore during the title casing process, so they remain in lowercase.
const titleize = require('titleize');
titleize('the wind in the willows', { ignore: ['the', 'in'] }); // 'The Wind in the Willows'
Other packages similar to titleize
to-title-case
The 'to-title-case' package also converts strings to title case. It is similar to 'titleize' but does not provide options to ignore certain words from being capitalized.
capitalize
The 'capitalize' package can capitalize the first letter of each word in a string, similar to 'titleize'. However, it also offers functions to capitalize or lowercase entire strings, which 'titleize' does not.
change-case
The 'change-case' package is a more comprehensive string manipulation library that includes a function for title casing among many other case conversion functions. It offers more versatility compared to 'titleize' which is focused solely on title casing.