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

silhouettejs

v1.0.9

Published

A small JS module for generating text based avatars in SVGs.

Downloads

3

Readme

🧑 silhouette

Netlify Status NPM Version Awesomeness Level

Silhouette is a small, dead-simple JS library built to help you text-based avatars without loading other heavy libraries like gravatar. Here's an example of how your avatars might look: https://silhouette-example.netlify.app/.

🍭 Installation

Simply download the files from the dist folder or install the npm version by doing npm install silhouettejs or yarn add silhouette.

You can now use it by require() or import either ways.

  • require() syntax goes on like this:
    const generateAvatar = require('silhouettejs').generateAvatar
  • import goes like this:
    import { generateAvatar } from 'silhouettejs'

Usage

It's really "dead-simple", just call a function and that's it.

  • To call the function:
// Load the module
import { generateAvatar } from 'silhouettejs';

// You can pass your own data from fetch() requests as well.
const names = ["Tom Clancy", "Robin Hood", "William Henry"];

// Store avatar urls in array
const avatars = []

// Loop through the names and call generateAvatar() to generate the avatar. 
names.forEach(name => {
   // Push the newly generate avatar to the avatars array.
   avatars.push(generateAvatar(name));
})

Note that this generates avatars with random colors, to specify your own background color, you can override the default options by passing an optional object.

...
generateAvatar(someName, {backgroundColor: '#customHexColor'})

You can then directly use the returned svg url in an <img> tag like:

<img id="avatar">

<script>
    import { generateAvatar } from 'silhouettejs';
    const avatarElement = document.getElementById('avatar');
    avatarElement.src = generateAvatar("Some Name");
</script>

A more ideal application would be to use this in existing frameworks that support literals. A similar example for React would look something like:

<User name={user.name} picture={generateAvatar(user.name)}>

Rounded Avatar

By default silhouette returns a square shaped avatar however you can change it to a rounded avatar as well by explicitly passing rounded: true in the options object like below.

import { generateAvatar } from 'silhouettejs';

// Run the function to generate the avatar.
generateAvatar('Some name', {rounded: true})

This would return a rounded avatar instead.

Extending on the CSS

You can resize the avatar flexibly with CSS since this is an SVG image.

Todo

  • [ ] Add multiple fonts support.
  • [ ] Add a background color range for selected randomized colors.

Credits

  • Thanks to @Hydrophobefireman for his weirdass but epic framework.
  • Thanks to @Protart for his epic SVG.