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

davatar

v1.0.3

Published

An npm package to generate avatar.

Downloads

55

Readme

Davatar

codecov npm version npm

🤡 An npm package to generate avatar data-url on both client & server side, using text.

https://nodei.co/npm/davatar.png?downloads=true&downloadRank=true&stars=true

Contents

Installation

npm install davatar

Usage

Import module as given below:

/*
Generated imageDataUrl can be used in <img> tag 
Or can be viewed directly through browser.
*/
const { davatar } = require("davatar");
const imageDataUrl50 = davatar.generate({size:50, text:"deepanshu dhruw", textColor:"blue", backgroundColor:"orange"});

Generated Image-Data-URL:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAABmJLR0QA/wD/AP+gvaeTAAACQElEQVRoge2YTUgUUQCAv9ltN3W32HVkw9LNFqJTkLhtEWQeDFqDfpAg6lDgoTwEGdExpD0FkYcO1sHoUgTRL6RBHvo5FIulYFCXFhstaWu1H1uXXdfp1CI4xAgz02t53/Hx+HgfM/Nm3ij6dXTKANe/XoBVyBDRkCGiIUNEQ4aIhgwRDRkiGjJENJaZmdQz0EV+zrto3OMuEPRN09gwzMb6UdyuoiMeIxQzB6sVHT+Zyfn/Okf1ZzjeeplT8YtU+6ds9RixpJADW27RtO5VaTybr0L7GubJ2xbGvjQAEFY1bp9sJxoZss1jhKlb6w9tm/o52nxt0biuKzx4vYfOq71omTC7zj8imYgRCaVs9SzEkoddUXT2Nt0nmYhRG5gkM6NyrO+Kox5Ld6266gkuHTkBwOCbVoZSUcc8lm+/+zffZXXwEwAPR3Y75rE8xKXMs33DcwCS72OOeWx5IYZrNADSP0KOeWwJqfDkAJjNVzrmsSXk8/dVANQGJh3z2BKSSkdML8Aqj+Uh37IBnr1rBjD9VrbCY3lI72An+TkvbleRfdF7jnksDRkea+TcnbMAHNp2g7CqOeaxJGRed3HzxUF2JJ6SK1SwJviRC4dPO+pZ0kdj/0hbaScBKBQ9TEzV8Xh0Z+nBrFfHGTgTJ7QybbtnIZadR3zLf9HR0kd3ezdB37StHiNMXZGueI/hya7SO8vamg+EVY2t619S5c064jHC1BX5Hyibnw8yRDRkiGjIENGQIaIhQ0RDhohG2YT8BpZRJq7xHedTAAAAAElFTkSuQmCC

Open the generated Image-Data-URL in the browser; you'll see the following image:

In React.js

import React from "react";
const { davatar } = require("davatar");

function App() {
	const imageDataUrl = davatar.generate({
		size: 50,
		text: "deepanshu dhruw",
		textColor: "red",
		backgroundColor: "cyan",
	});
	return <img src={imageDataUrl} alt="image"></img>;
}

export default App;

Run the react-app and you will see below image:

Parameters:

| Parameter | Type | Values | Default | | ------------------------------ | ------- | --------------------------------------------------------------------------- | ---------------------------- | | size (Optional) | Integer | 1 - 512 | 64 | | text (Required) | String | More than 2 characters | | | textColor (Optional) | String | Color Format | Random RGB Value | | backgroundColor (Optional) | String | Color Format | Random RGB Value | | fontFamily (Optional) | String | Font Family | "Arial" | | fontWeight (Optional) | Integer | 100 - 900 | 100 |

Examples

EXAMPLE-1

Generating 64×64 (px) dimension image, with custom parameters:

const { davatar } = require("davatar");
const imageProperty = {
    size: 64,
    text: "John Doe",
    textColor: "red",
    backgroundColor: "green",
    fontFamily: "monospace",
    fontWeight: 600
}
const imageDataUrl = davatar.generate(imageProperty);


EXAMPLE-2

Generating default dimension image, with default parameters:

const { davatar } = require("davatar");
const imageProperty = { text: "John Doe" }
const imageDataUrl = davatar.generate(imageProperty);

Random textColor & backgroundColor:


EXAMPLE-3

Generating 128×128 (px) dimension image, with default parameters:

const { davatar } = require("davatar");
const imageProperty = { size: 128, text: "dd" }
const imageDataUrl = davatar.generate(imageProperty);

Random textColor & backgroundColor:

Tests

npm test

License

MIT