default-avatar-helper
A helper for creating default avatars.
Usage
import { getDefaultAvatarDetails } from 'default-avatar-helper'
const palette = ['red', 'green', 'blue']
const name = 'random name'
const { colour, initials } = getDefaultAvatarDetails(palette, name)
const getDefaultAvatarDetailsWithPalette = getDefaultAvatarDetails(palette)
const { colour, initials } = getDefaultAvatarDetailsWithPalette(name)
The following live examples show how colour
and initials
can be used to
create a default avatar.
Live Examples
API
getDefaultAvatarDetails(palette, colour)
Arguments
palette
- An array of strings representing the colour palette to use.name
- A string representing a user name.
Returns
If less than two arguments have been provided, returns a function accepting the
remaining argument.
If both arguments have been provided, returns an object containing the
properties defined below:
colour
- A colour string.initials
- The user initials string.
Example
const palette = ['red', 'green', 'blue']
const name = 'random name'
const { colour, initials } = getDefaultAvatarDetails(palette, name)
const getDefaultAvatarDetailsWithPalette = getDefaultAvatarDetails(palette)
const { colour, initials } = getDefaultAvatarDetailsWithPalette(name)
Installation
$ npm install default-avatar-helper
There are also UMD builds available via unpkg:
Make sure you have already included:
License
MIT