@4players/odin-foundation
Version:
A set of classes defining a standard protocol for messaging and user data built on top of the Odin protocol.
25 lines (24 loc) • 806 B
JavaScript
import * as hash from 'hash.js';
/**
* Simple wrapper around the DiceBear API.
* @see https://avatars.dicebear.com/docs/getting-started
*/
export class DiceBear {
/**
* Generates a random seed used to generate the avatar.
*/
static randomSeed() {
return hash.sha256().update(Math.random().toString(36)).digest('hex');
}
/**
* Generates an avatar URL.
* @param avatarStyleName {DiceBearAvatarStyleName} The avatar style name.
* @param seed {string} The seed used to generate the avatar.
*/
static getAvatarUrl(avatarStyleName, seed) {
if (!seed) {
seed = this.randomSeed();
}
return `https://avatars.dicebear.com/api/${avatarStyleName}/${seed}.svg?backgroundColor=%23333333&textureChance=0&margin=10`;
}
}