Added opt-out trim to capitalize util.

This commit is contained in:
ThePendulum 2020-02-26 04:10:01 +01:00
parent c7fac575e4
commit 51ffcb5be7
1 changed files with 4 additions and 2 deletions

View File

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