Jdenticon

3.3.0 · active · verified Sun Apr 19

Jdenticon is a JavaScript library for generating unique, recognizable identicons, often used for user avatars or cryptographic hashing visualization. It supports rendering these icons into both HTML5 Canvas (raster) and SVG (vector) elements, providing flexibility for different display needs. The library offers distinct bundles for browser and Node.js environments, enabling client-side display or server-side image generation, including PNG outputs. The current stable version is 3.3.0. Release cadence is somewhat ad-hoc, with several minor releases per year addressing bugs, improving TypeScript support, and enhancing features. Key differentiators include its dual Canvas/SVG rendering capabilities, a wide range of configurable aesthetic properties (padding, saturation, hues), and a CLI tool. Since version 3.0.0, automatic icon rendering on page load requires explicit opt-in.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import and use Jdenticon to render icons on page load and dynamically create/update icons, accounting for v3.0.0 breaking changes.

import { update } from 'jdenticon';

document.addEventListener('DOMContentLoaded', () => {
  // Assume HTML elements with data-jdenticon-value are present
  // e.g., <svg width="80" height="80" data-jdenticon-value="my-icon-seed"></svg>
  // or <canvas width="80" height="80" data-jdenticon-value="my-icon-seed"></canvas>

  // To render all icons on the page with data-jdenticon-value attribute:
  update();

  // To dynamically create and render an icon on a specific element:
  const svgElement = document.createElement('svg');
  svgElement.setAttribute('width', '100');
  svgElement.setAttribute('height', '100');
  // The `update` function can take an element and a value
  update(svgElement, 'dynamic-icon-seed');
  document.body.appendChild(svgElement);

  // Example of using a specific value for an existing element:
  const existingCanvas = document.querySelector('canvas[data-jdenticon-value="icon value"]');
  if (existingCanvas) {
    update(existingCanvas, 'new-seed-for-canvas');
  }
});

view raw JSON →