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

facitars

v1.0.1

Published

Lightweight, gender neutral, avatar generator for project where you need not just unique avatars but color codes too!

Downloads

14

Readme

Facitars!

Sample Facitars

Lightweight avatar generator for the browser and server (NodeJs) that creates colorful and gender neutral avatars and also conveniently returns the avatars primary color too!

Facitars was built after I tried dozens of others and couldn't find one that provided support for all of the following:

  1. Creating lightweight (no complex curves and paths) SVG avatars with the help of SVG.js. The minified javascript file is only 17.8 KBs of awesomeness!

  2. Generating and Returning a unique (seed generated) color for each avatar. This is useful for applications where you wish to color code certain parts of your UI based on a users ID/email or whatever your seed value may be.

  3. Most importantly, this project is generates SVG avatars both in the browser and on the server in a consistent manner. To do so, it relies on JSDOM and SVG.js while avoiding SVG operations that would produce inconsistent SVGs on browser and server. This means that facitars goes beyond other avatar generators out there!

  4. Finally, all avatars generated should be of the same size so as to fit well in grids and UIs

Generating Facitars on the Browser

On the browser all you need is:

1. Load the js file

<!-- Add this line preferably to your <head> -->
<script src="../dist/facitars.min.js"></script>

Note that Facitars uses SVG.js. Consequently the minified svg.js file from jsdelivr will be automatically loaded if no instance of window.SVG is found.

If svg.js has already been loaded prior to loading facitars, then that instance is used.

2. Initialize the class

<script>
	// init
	const facitars = new Facitars();
</script>

3. Generate your Facitar

<script>
	// Note generate() function is asynchronous
	(async () => {
		// create 300x300px facitar for the seed 'Anthony Mugendi'
		let { svg, color } = await facitars.generate('Anthony Mugendi', 100);
		// use the svg and color values returned as you desire
	})();
</script>

Generating Facitars on the Server

1. Require Facitars

Of course start with installing facitars yarn add facitars

// require
const Facitars = require('facitars').node();

Note: You must call .node() when using on the server. This method wraps in JSDOM which is used to mock browser svg rendering.

For the server version. A local version of svg.js is included. This is because we cannot trust any scripts from jsdelivr or any other source as JSDOM is known to leak its sandbox.

2. Initialize the class

// init
const facitars = new Facitars();

3. Generate your Facitar

// Note generate() function is asynchronous
(async () => {
	// create 300x300px facitar for the seed 'Anthony Mugendi'
	let { svg, color } = await facitars.generate('Anthony Mugendi', 100);
	// use the svg and color values returned as you desire
})();

Using Facitars with Webpack and other package managers

// simply require facitars
const Facitar = require('facitars').browser();

// proceed to use as desired
const facitar = new Facitar();

Note: Ensure you call .browser() not .node() as JSDOM is not needed, nor would it work anyway, in a browser environment. Also .browser() provides only the facitar class and therefore is perfect for your tree-shaking.

For Server renders, you can write the SVG data returned to an svg file for later serving via HTTP or any other use. See the Node Example folder for more.

For both browser and server examples above, the following Facitar is generated against the seed "Anthony Mugendi" 🙂

Anthony Mugendi Facitar

API

.generate(seed,size)

The seed can be any value so long as it can be converted into a string using seed.toString().

The size argument determines the dimensions of the final SVG. Default is 80.

Examples

Have a look at Browser Example as well as the NODE/Server Examples for more.