A helper for creating default avatars.
import { getDefaultAvatarDetails } from 'default-avatar-helper'
const palette = ['red', 'green', 'blue']
const name = 'random name'
// Providing both arguments at once will return a result object straight away:
const { colour, initials } = getDefaultAvatarDetails(palette, name)
// Alternatively, since `getDefaultAvatarDetails` is curried, you can do
// something like:
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.
- Vanilla: Source | Sandbox
- UMD Build (Development): Source | Sandbox
- UMD Build (Production): Source | Sandbox
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'
// Providing both arguments at once.
const { colour, initials } = getDefaultAvatarDetails(palette, name)
// Making use of currying.
const getDefaultAvatarDetailsWithPalette = getDefaultAvatarDetails(palette)
const { colour, initials } = getDefaultAvatarDetailsWithPalette(name)
$ npm install default-avatar-helper
There are also UMD builds available via unpkg:
- https://unpkg.com/default-avatar-helper/dist/default-avatar-helper.umd.development.js
- https://unpkg.com/default-avatar-helper/dist/default-avatar-helper.umd.production.js
Make sure you have already included:
MIT