1.0.2 • Published 1 year ago

emoji-avatar v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Generate an emoji avatar from a string. Demo

Getting Started

npm i emoji-avatar
import { createAvatar } from 'emoji-avatar';

const avatar = createAvatar("john doe")

console.log(avatar)
{
    "color": "hsl(3, 73%, 83%)",
    "url": "https://cdn.../1f368.svg"
}

React Example

function UserAvatar({ username }) {
  const avatar = createAvatar(username);
  return (
    <div style={{ background: avatar.color }}>
      <img src={avatar.url} alt={username} />
    </div>
  );
}

API

  • createAvatar(input: string): Avatar
  • colorHash(hash: number): string
  • emojiHash(hash: number, emojiRanges?: EmojiRangeName[]): string

See JSDoc comments in source for details.

Motivation

Inspired from Rainbow Wallet

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago