traxxx/src/utils/capitalize.js

17 lines
395 B
JavaScript
Executable File

'use strict';
function capitalize(string, { trim = true, uncapitalize = false } = {}) {
if (!string) {
return '';
}
const capitalized = string
.split(/\s+/)
.map((component) => `${component.charAt(0).toUpperCase()}${uncapitalize ? component.slice(1).toLowerCase() : component.slice(1)}`)
.join(' ');
return trim ? capitalized.trim() : capitalized;
}
module.exports = capitalize;