UNPKG

hd-utils

Version:

A handy utils for modern JS developers

15 lines (14 loc) 445 B
import isString from '../validation/isString'; /** * @description will return the passed string with the first character capitalized. * @example capitalize("javascript") // "Javascript" */ export default function capitalize(str) { if (!isString(str)) return ''; return str.split('').reduce((prev, curr, i) => { if (i === 0) return (prev += curr.toUpperCase()); return (prev += curr); }, ''); }