'use strict';

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;
