UNPKG

initials-extractor

Version:

A lightweight Node.js package that takes a full name (e.g., Adão Angelo João or Bernardo Silva) and returns the corresponding initials (e.g., AA or BS). Perfect for generating user avatars, profile initials, or any other use case where name abbreviation i

16 lines 586 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getInitials = getInitials; function getInitials(name) { if (!name || typeof name !== "string") { throw new Error("Invalid name"); } const nameSplit = name.split(" "); if (nameSplit.length < 2) { return nameSplit[0].charAt(0).toUpperCase(); } const firstInitial = nameSplit[0].charAt(0).toUpperCase(); const lastInitial = nameSplit[nameSplit.length - 1].charAt(0).toUpperCase(); return `${firstInitial}${lastInitial}`; } //# sourceMappingURL=index.js.map