2020-02-24 02:12:58 +00:00
|
|
|
'use strict';
|
|
|
|
|
2020-07-22 02:12:20 +00:00
|
|
|
function capitalize(string, { trim = true, uncapitalize = false } = {}) {
|
2020-05-14 02:26:05 +00:00
|
|
|
if (!string) {
|
|
|
|
return '';
|
|
|
|
}
|
2020-03-11 02:01:37 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
const capitalized = string
|
|
|
|
.split(/\s+/)
|
2021-11-20 22:59:15 +00:00
|
|
|
.map((component) => `${component.charAt(0).toUpperCase()}${uncapitalize ? component.slice(1).toLowerCase() : component.slice(1)}`)
|
2020-05-14 02:26:05 +00:00
|
|
|
.join(' ');
|
2020-02-26 03:10:01 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return trim ? capitalized.trim() : capitalized;
|
2020-02-24 02:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = capitalize;
|