@technobuddha/library
Version:
A large library of useful functions
21 lines • 1.1 kB
JavaScript
/**
* Returns the uppercase initials of the given string.
*
* Extracts the first letter of each word in the input string and concatenates them into a single uppercase string.
*
* @param words - The input string from which to extract initials.
* @returns The uppercase initials of the input string.
* @group String
* @category Operations
* @example
* ```typescript
* initials("John Doe") // "JD"
* initials("alice in wonderland") // "AIW"
* ```
*/
export function initials(words) {
return Array.from(words.matchAll(/\b(\w)/gu), (m) => m[1])
.join('')
.toUpperCase();
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5pdGlhbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5pdGlhbHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7Ozs7Ozs7Ozs7O0dBY0c7QUFDSCxNQUFNLFVBQVUsUUFBUSxDQUFDLEtBQWE7SUFDcEMsT0FBTyxLQUFLLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQyxRQUFRLENBQUMsVUFBVSxDQUFDLEVBQUUsQ0FBQyxDQUFDLEVBQUUsRUFBRSxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQztTQUN2RCxJQUFJLENBQUMsRUFBRSxDQUFDO1NBQ1IsV0FBVyxFQUFFLENBQUM7QUFDbkIsQ0FBQyJ9