This module provides a class for capitalizing the first letter of a string while converting the rest of the string to lowercase.
To use this module, you should have the "node-string-methods" npm package installed. You can install it using npm or yarn:
npm install node-string-methods
const Capitalize = require('node-string-methods/capitalize');
// Create an instance of the Capitalize class with a string as input
const str = 'hello WoRLD';
const capitalizer = new Capitalize(str);
// Execute the capitalization operation
const result = capitalizer.execute();
console.log(result); // Output: 'Hello world'
str
(String): The input string that you want to capitalize.
Creates a new instance of the Capitalize
class with the provided string.
Capitalizes the first letter of the input string while converting the rest of the string to lowercase.
- Returns: The capitalized string.
const Capitalize = require('node-string-methods/capitalize');
const str = 'eXaMPLe StRIng';
const capitalizer = new Capitalize(str);
const result = capitalizer.execute();
console.log(result); // Output: 'Example string'
- Throws an
Error
if the input provided to the constructor is not a string.