npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-intials-avatar-generator

v1.0.3

Published

Customizable initials-based avatar component for React applications.

Readme

React Initials Avatar Generator

A lightweight, customizable React component for generating beautiful initials-based avatars. Perfect for user profiles, contact lists, and any application that needs elegant placeholder avatars.

Features

  • 🎨 Fully customizable colors, sizes, and styles
  • 🔤 Smart initials extraction from names
  • 📦 Zero dependencies (except React)
  • 🎯 Full TypeScript support with exported types
  • ⚡ Lightweight and performant (~1.2KB gzipped)
  • 🎭 Flexible styling options
  • 📘 Complete type definitions included
  • 🔧 Works with React 18+

Installation

npm install react-intials-avatar-generator

or

yarn add react-intials-avatar-generator

or

pnpm add react-intials-avatar-generator

Quick Start

import { InitialsAvatar } from 'react-intials-avatar-generator';

function App() {
  return (
    <div>
      {/* Basic usage */}
      <InitialsAvatar name="John Doe" />
      
      {/* With custom styling */}
      <InitialsAvatar 
        name="Jane Smith"
        styles={{
          size: 80,
          bgColor: "#10b981",
          textColor: "#ffffff"
        }}
      />
    </div>
  );
}

Props

Component Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | name | string | required | The full name to extract initials from | | styles | StyleProps | {} | Styling configuration object | | options | InitialOptions | {} | Options for initials extraction |

StyleProps

Configure the visual appearance of the avatar:

| Property | Type | Default | Description | |----------|------|---------|-------------| | size | number | 50 | Avatar size in pixels (width and height) | | radius | number \| string | "50%" | Border radius (use "50%" for circle, number for rounded square) | | bgColor | string | "#4f46e5" | Background color (any valid CSS color) | | textColor | string | "#ffffff" | Text color for initials | | fontFamily | string | "inherit" | Font family for the initials | | fontSize | number | size * 0.4 | Font size in pixels (auto-calculated if not provided) | | fontWeight | number \| string | 600 | Font weight (100-900 or CSS keywords) | | lineHeight | number \| string | size + "px" | Line height for vertical centering | | letterSpacing | number \| string | 0 | Letter spacing in pixels or CSS units |

InitialOptions

Control how initials are extracted from names:

| Property | Type | Default | Description | |----------|------|---------|-------------| | maxLength | number | Infinity | Maximum number of initials to display | | uppercase | boolean | true | Convert initials to uppercase | | fallback | string | "" | Fallback text when name is empty or invalid |

Examples

Basic Avatar

<InitialsAvatar name="John Doe" />

Custom Size and Colors

<InitialsAvatar 
  name="Jane Smith"
  styles={{
    size: 80,
    bgColor: "#10b981",
    textColor: "#ffffff"
  }}
/>

Square Avatar with Rounded Corners

<InitialsAvatar 
  name="Alice Johnson"
  styles={{
    size: 60,
    radius: 8,
    bgColor: "#f59e0b"
  }}
/>

Custom Font Styling

<InitialsAvatar 
  name="Bob Wilson"
  styles={{
    size: 100,
    fontFamily: "Arial, sans-serif",
    fontSize: 45,
    fontWeight: 700,
    letterSpacing: 2
  }}
/>

Limit Initials Length

<InitialsAvatar 
  name="Christopher Alexander Montgomery"
  options={{
    maxLength: 2  // Will show "CA" instead of "CAM"
  }}
/>

Lowercase Initials

<InitialsAvatar 
  name="David Brown"
  options={{
    uppercase: false
  }}
/>

With Fallback

<InitialsAvatar 
  name=""
  options={{
    fallback: "?"
  }}
  styles={{
    bgColor: "#6b7280"
  }}
/>

Complete Custom Example

<InitialsAvatar 
  name="Emily Rose Parker"
  styles={{
    size: 120,
    radius: "20%",
    bgColor: "#8b5cf6",
    textColor: "#fef3c7",
    fontFamily: "Georgia, serif",
    fontSize: 50,
    fontWeight: 500,
    letterSpacing: 3
  }}
  options={{
    maxLength: 2,
    uppercase: true
  }}
/>

How Initials Are Extracted

The component intelligently extracts initials from names:

  1. Removes special characters like hyphens, periods, and apostrophes
  2. Splits the name by spaces
  3. Takes the first letter of each word
  4. Applies the maxLength limit if specified
  5. Converts to uppercase by default (unless uppercase: false)

Examples:

  • "John Doe""JD"
  • "Mary-Jane Watson""MJW"
  • "Dr. James Smith Jr.""DJSJ"
  • "Anne O'Brien""AOB"

TypeScript Support

The package includes full TypeScript definitions with automatic type inference. No manual type definitions needed!

Available Types

The package exports the following types:

  • InitialsAvatar - The main component
  • StyleProps - Type for styling configuration
  • InitialsAvatarProps - Type for component props
  • InitialOptions - Type for initials extraction options
  • getInitials - Utility function for extracting initials

TypeScript Usage

import { InitialsAvatar } from 'react-intials-avatar-generator';
import type { 
  StyleProps, 
  InitialsAvatarProps, 
  InitialOptions 
} from 'react-intials-avatar-generator';

// Define styles with type safety
const styles: StyleProps = {
  size: 60,
  bgColor: "#3b82f6",
  textColor: "#ffffff",
  radius: "50%"
};

// Define options with type safety
const options: InitialOptions = {
  maxLength: 2,
  uppercase: true,
  fallback: "?"
};

// Use in your component
function MyAvatar() {
  return (
    <InitialsAvatar 
      name="John Doe"
      styles={styles}
      options={options}
    />
  );
}

Type Definitions

All types are automatically included when you install the package. TypeScript will provide:

  • ✅ Full autocomplete for all props
  • ✅ Type checking for prop values
  • ✅ IntelliSense documentation
  • ✅ Error detection at compile time

No need to create separate type.d.ts files!

API Reference

Exported Components and Types

// Component
export { InitialsAvatar }

// Types
export type { StyleProps, InitialsAvatarProps, InitialOptions }

// Utility
export { getInitials }

Using the getInitials Utility

You can also use the getInitials function directly:

import { getInitials } from 'react-intials-avatar-generator';

const initials = getInitials("John Doe", { 
  maxLength: 2, 
  uppercase: true 
});
// Returns: "JD"

Browser Support

Works in all modern browsers that support React 18+:

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Edge (latest)

Package Information

  • Size: ~1.2KB (gzipped)
  • Dependencies: React 18+ (peer dependency)
  • TypeScript: Full type definitions included
  • Module Formats: ESM and UMD

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT © Ankit Kumar Pandey

Repository

Keywords

react, avatar, initials, react-avatar, profile-avatar, user-avatar, placeholder-avatar, avatar-component, typescript, react-component