stringzy
Version:
A versatile string manipulation library providing a range of text utilities for JavaScript and Node.js applications.
15 lines (14 loc) • 422 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.titleCase = titleCase;
function titleCase(text) {
if (text == null)
return '';
return text
.trim()
.toLowerCase()
.replace(/([^\w\s]|_)/g, ' ')
.replace(/\s+/g, ' ')
.replace(/(^|\s)(.)/g, (_, prefix, character) => prefix + character.toUpperCase())
.replace(/\s/g, ' ');
}