/**
 * Capitalizes first letters of words in string.
 * @param {string} str String to be modified.
 * @param {boolean=true} all Whether all words should be capitalised.
 * @return {string}
 * @usage
 *   capitalize('fix this string');     // -> 'Fix This String'
 *   capitalize('javaSCrIPT');          // -> 'JavaSCrIPT'
 */
const capitalize = (str = '', all = true) => {
  if (all) {
    return str.replace(/(?:^|\s|["'([{])+\S/g, match => match.toUpperCase());
  }
  return `${str.charAt(0).toUpperCase()}${str.slice(1)}`;
};
const generateRandomString = (length = 16) => Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, length);

export { capitalize as c, generateRandomString as g };
