npm.io
10.7.0 • Published 2 months ago

@dicebear/core

Licence
MIT
Version
10.7.0
Deps
0
Size
450 kB
Vulns
0
Weekly
0
Stars
10.0K

DiceBear Core (JavaScript)

stars license

JavaScript implementation of the DiceBear avatar library. Generates deterministic SVG avatars from style definitions and a seed string.

DiceBear is available for multiple languages. All implementations share the same PRNG and rendering pipeline, producing identical SVG output for the same seed, style, and options, regardless of the language used.

Playground | Documentation

Installation

npm install @dicebear/core

Requires Node.js 22+ or any modern browser.

Usage

import { Avatar } from '@dicebear/core';

// From a style definition (here from the @dicebear/styles package)
import definition from '@dicebear/styles/lorelei.json' with { type: 'json' };

const avatar = new Avatar(definition, {
  seed: 'John Doe',
  size: 128,
});

avatar.toString(); // SVG string
avatar.toDataUri(); // data:image/svg+xml;charset=utf-8,...
Using the Style class
import { Style, Avatar } from '@dicebear/core';

const style = new Style(definition);

// Create multiple avatars from the same style
const avatar1 = new Avatar(style, { seed: 'Alice' });
const avatar2 = new Avatar(style, { seed: 'Bob' });

Sponsors

Advertisement: Many thanks to our sponsors who provide us with free or discounted products.

bunny.net

Keywords