UNPKG

hd-utils

Version:

A handy utils for modern JS developers

14 lines (13 loc) 549 B
import getFirstNLetters from './getFirstNLetters'; import splitUpperCase from './splitUpperCase'; /** *@description Will return the initials of the passed name at provided length; * @example visual studio => vs; * @example JavaScript => JS */ const getNameInitials = (name, length = 1) => splitUpperCase(name).reduce((prev, curr, _, arr) => { if (arr.length === 1) return (prev += getFirstNLetters(curr, length)); return prev.length >= length ? prev : (prev += getFirstNLetters(curr, 1)); }, ''); export default getNameInitials;