JSFiddle - React, Tailwind, and code Playground
JavaScript
const transform = function (string) {
if (string === undefined) {
throw new Error('must provide string');
}
const toUpperCase = function () {
string = string.toUpperCase();
return this;
};
const toLowerCase = function () {
string = string.toLowerCase();
return this;
};
const capitalizeFirstLetter = function () {
string = string.charAt(0).toUpperCase() + string.slice(1);
return this;
};
const end = function(){
return string;
}
return {
toUpperCase,
toLowerCase,
capitalizeFirstLetter,
end,
};
};
var a = transform('someThinG');
a = a.toLowerCase();
a = a.capitalizeFirstLetter();
a = a.end()
console.log(a)
console.log(typeof a)