Skip to content

tanem/default-avatar-helper

Repository files navigation

default-avatar-helper

npm version build status coverage status npm downloads minzipped size

A helper for creating default avatars.

Usage

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.

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'

// Providing both arguments at once.
const { colour, initials } = getDefaultAvatarDetails(palette, name)

// Making use of currying.
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