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

svg-identicon

v1.0.1

Published

Various configurable identicon styles with SVG output.

Downloads

84

Readme

Identicons

While the GitHub-style identicons are well-designed and widely implemented, they're square. And while this is perfectly acceptable in many designs, variety in choice is never a bad thing. This project aims to apply the simplicity of GitHub identicons to other shapes and styles.

I'd love to hear how you use these!

Use

The first thing you need to do is find a way to hash the data you want to "identify" with an identicon. For example, you could use MD5 to produce this transformation: "Hello, world!" => '6cd3556deb0da54bca060b4c39479839'). The hash doesn't need to be enormous, but should be more than 9 bytes. The function doesn't need to be complex, but each bit in the hash should have about a 50/50 chance of being 1 or 0. The less random the hash is, the more predictable the image will be, so just using incremental user ids is probably not enough for variation.

This hash can either be a string of hexadecimal digits or an ArrayBuffer.

An important note: this code is open source (obviously), does no further processing on the provided hashes, and may or may not use the entirety of the hash to generate an image. DO NOT use these identicons to represent sensitive data, even if you use some supposedly secure hashing algorithm. While it may be tempting to use something like the hex representation of a scrambled user email as a hash, please don't. That's equivalent to setting your user's public username to their email. Identicons are not encryption.

Generation

The best way to learn what the options do is to try them out here.

const identicon = require('svg-identicon')
identicon(options)

Not every option is used for every type of identicon.

  • options: object
    • hash: string
      • A string of hexadecimal digits used to generate the identicon.
    • type: string
      • The type of identicon to generate ('SQUARE', 'CIRCULAR', or 'POLYGONAL').
    • width: number = 128
      • The dimension of the image in pixels.
    • size: number
      • A sort of dimension describing the complexity of the identicon. For squares identicons, it's the number of boxes on a side. For circular it's the number of shells.
    • segments: number
      • Separates each shell into the provided number of segments.
    • symmetricAxisTilt: number = null
      • Simultaneously forces the identicon to be symmetric across a single axis and sets the angle of this axis in degrees. (NOTE: This is not the same thing as rotating the identicon. It will look different at each angle mod 180). To have no symmetry, set this value to null.
    • background: object
      • color: string = '#EEEEEE'
      • width: number = options.width
      • rx: number = 0
Square

Square Identicon Example

Required Options:

  • type = 'SQUARE'
  • hash

Other Options:

  • size
  • width
Circular

Circular Identicon Example

Required Options:

  • type = 'CIRCULAR'
  • hash

Other Options:

  • size
  • width
  • segments
  • symmetricAxisAngle
Polygonal

Polygonal Identicon Example

Required Options:

  • type = 'POLYGONAL'
  • hash

Other Options:

  • size
  • width
  • segments

Output

The return value of identicon is the string representation of an SVG. You can save this to a file, parse it, add it to a DOM, log it, etc...

Node:

const fs = require('fs')

let svg = identicon({ type: 'SQUARE', hash: '1234567890ABCDEF' })

fs.writeFile(./'identicon.svg', svg, console.log)

Browser (after using webpack):

let svg = identicon({ type: 'SQUARE', hash: '1234567890ABCDEF' })

let container = document.getElementById("container");
container.innerHTML = svg;