npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@basementuniverse/marble-identicons

v0.1.2

Published

Generate marble-style identicons

Downloads

1,372

Readme

Marble Identicons

Generate random marble-style identicons.

Identicons Preview

Installation

npm install @basementuniverse/marble-identicons

Usage

API:

function identicon(
  name: string,
  settings: Partial<IdenticonSettings>
) => HTMLCanvasElement

See below for more information on configuration settings.

In a browser environment

Include the script in your page and call the identicon function. It will return a HTMLCanvasElement node which can be appended to the DOM or drawn into another canvas.

Example:

<script src="build/identicon.js"></script>
<script>

const myIdenticon = identicon('Alan Turing');

document.body.appendChild(myIdenticon);

</script>

In React

This example shows one way of wrapping the HTMLCanvasElement inside a JSX element:

import { useRef, useLayoutEffect } from 'react';
import { identicon } from '@basementuniverse/marble-identicons';

export function MarbleIdenticon({ name }: { name: string }) {
  const ref = useRef<HTMLDivElement>(null);

  useLayoutEffect(() => {
    if (ref.current) {
      ref.current.innerHTML = '';
      ref.current.appendChild(identicon(name));
    }
  });

  return (
    <div className="identicon" ref={ref}></div>
  );
}

This component can then be used like so:

ReactDOM.render(
  <MarbleIdenticon name="Alan Turing" />,
  document.getElementById('root')
);

Settings

type IdenticonSettings = {
  size: number;
  baseSeed: string;
  font: string;
  fontStyle: FontStyle;
  fontSize: number;
  backgroundColours: string[];
  initialsColours: string[];
  initialsOffset: vec;
  initialsAlpha: number;
  initialsCompositeOperation: CompositeOperation;
  stripeColours: string[];
  stripeAlpha: number;
  stripeCompositeOperation: CompositeOperation;
  stripes: [number, number];
  stripeWidth: [number, number];
  stripeDeviation: [number, number];
  curveAmount: [number, number];
  curveOffset: [number, number];
  startWidthSign: WidthSign[];
  endWidthSign: WidthSign[];
};

| Setting | Type | Description | Default value | |------------------------------|----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------| | size | number | The size of the identicon in pixels | 100 | | baseSeed | string | A string that will be prefixed onto the name when seeding the RNG | '' | | font | string | The font family used for the initials | 'Helvetica' | | fontStyle | FontStyle | The font style used for the initials. Must be one of '', 'normal', 'bold', 'italic' | 'bold' | | fontSize | number | The font size used for the initials, as a factor of size | 0.4 | | backgroundColours | string[] | An array of background colours. One will be picked at random from this list. | ['#16a085', '#1abc9c', '#2ecc71', '#3498db', '#1970b9', '#9b59b6', '#e67e22', '#e74c3c', '#e0395b'] | | initialsColours | string[] | An array of colours used for the initials. The index of the randomly-chosen background colour will be used to select from this list, clamped to the size of the array. | ['#ffffff'] | | initialsOffset | vec | The initials offset position. { x: number, y: number } | { x: 0, y: 0 } | | initialsAlpha | number | The alpha opacity of the initials | 1 | | initialsCompositeOperation | CompositeOperation | The global composite operation used for the initials. Must be one of 'source-over', 'lighter', 'multiply', 'screen', 'overlay', 'color-dodge', 'color-burn', 'hard-light', 'soft-light' | 'source-over' | | stripeColours | string[] | An array of colours used for the stripes. The index of the randomly-chosen background colour will be used to select from this list, clamped to the size of the array. | ['#f1c40f'] | | stripeAlpha | number | The alpha opacity of the stripes | 0.15 | | stripeCompositeOperation | CompositeOperation | The global composite operation used for the stripes. Must be one of 'source-over', 'lighter', 'multiply', 'screen', 'overlay', 'color-dodge', 'color-burn', 'hard-light', 'soft-light' | 'lighter' | | stripes | [number, number] | A tuple containing the minimum and maximum number of stripes to draw | [3, 8] | | stripeWidth | [number, number] | A tuple containing the minimum and maximum stripe width, measured in radians. | [0.2, 0.7] | | stripeDeviation | [number, number] | A tuple containing minimum and maximum distances between successive stripes, measured in radians. | [-0.5, 0.5] | | curveAmount | [number, number] | A tuple containing the minimum and maximum radius multiplier for the control point circle. | [0.2, 0.4] | | curveOffset | [number, number] | A tuple containing the minimum and maximum offset angle for the control point measured in radians. | [0, 0.5] | | startWidthSign | WidthSign[] | An array of signs ('positive' or 'negative') for the starting edge of each stripe. If startWidthSign is ['positive'] and endWidthSign is ['negative'] (or vice-versa) then the stripe side edges will not cross over. | ['positive', 'negative'] | | endWidthSign | WidthSign[] | An array of signs ('positive' or 'negative') for the ending edge of each stripe. | ['positive', 'negative'] |