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

gravatar-img

v2.0.1

Published

Node.js package build to handle the gravatar picture in a simpler no thinking way !

Downloads

16

Readme

gravatar-img

[TOC]

v2.0.1 - 29-01-2024

Simple Gravatar Node.js package, do you want more info? http://en.gravatar.com/

Intro

Simple Node.js module for build https (Snowden teach us) URL for Gravatar pictures. Your Gravatar is an image that follows you from site to site appearing beside your name when you do things like comment or post on a blog. Avatars help identify your posts on blogs and web forums, so why not on any site? You need more info ? Check the official Gravatar page.

Version Details

Main changes by version (if the first number change, old code you have written is not supported, for example between version 1.x.x to version 2.x.x (I apologize for that):

  • 1.1.0 First Version (hunting the bugs)

  • 1.1.3 minor text changes

  • 2.0.0 New version based on sha256 (no-dependencies / breaking changes)

Install

Like all the Node.js module can't be more easy :

  npm install gravatar-img

  # install and save in package.json
  npm install gravatar-img --save

Usage

Install the package with npm, import with the import for latest version and require for version < 2.0.0, and start to use the apis. Yes of course you need to have the gravatar active on the gravatar(wordpress) environment, so take a look at the gravatar link. After that keep in mind

Version >= 2.0.0

import {
  setGravatarSize,
  setGravatarRating,
  setGravatarDefaultImg,
  getGravatarURL,
  getGravatarHTTPS
} from 'gravatar-img'

setGravatarSize(250)

// set the rating for the gravatar to get link ('g', 'pg', 'r', x) (optional)
// g: suitable for display on all websites with any audience type.
// pg: may contain rude gestures,  swear words, or mild violence.
// r: may contain such things as harsh profanity, violence, nudity, drug use.
// x: may contain hardcore sexual imagery or extremely disturbing violence.
setGravatarRating('g')

// set the default image in case of miss the retrieve by email (URL) (optional)
setGravatarDefaultImg('https://placehold.it/350x150')

// get the URL / HTTPS
const url = await getGravatarURL('[email protected]')
const url = await getGravatarHTTPS('[email protected]')

Version < 2.0.0

  var g = require('gravatar-img');

  // set the size of the gravatar to get the link (min 1, MAX 2048) (optional)
  g.setGravatarSize(250);

  // set the rating for the gravatar to get link ('g', 'pg', 'r', x) (optional)
  // g: suitable for display on all websites with any audience type.
  // pg: may contain rude gestures,  swear words, or mild violence.
  // r: may contain such things as harsh profanity, violence, nudity, drug use.
  // x: may contain hardcore sexual imagery or extremely disturbing violence.
  g.setGravatarRating('g');

  // set the default image in case of miss the retrieve by email (URL) (optional)
  g.setGravatarDefaultImg('https://placehold.it/350x150');

If no options will be set, the default values are used :

  • size : 80x80
  • rating : 'g'
  • default-img : default gravatar miss image

  // get the HTTPS link to gravatar img
  // eg. https://www.gravatar.com/avatar/a5ce16777a0e53b502649c1a08fd5bca
  // eg. https://www.gravatar.com/avatar/a5 ... ca?s=250&r=g&d=http://placehold.it/250x250
  g.getGravatarHTTPS('[email protected]', function(err,link){
    if (!err){
      // do stuff with the link
      console.log(link);
    }else {
      // handle the error (wrong email)
    }
  });

  // get the URL link to gravatar img
  // eg. www.gravatar.com/avatar/a5ce16777a0e53b502649c1a08fd5bca
  // eg. www.gravatar.com/avatar/a5c... 8fd5bca?s=250&r=g&d=http://placehold.it/250x250
  g.getGravatarURL('[email protected]', function(err,link){
    if (!err){
      // do stuff with the link
      console.log(link);
    }else {
      // handle the error (wrong email)
    }
  });

Other Methods

The module give you the access to other methods, most of them not commonly used :

// reset all the size, rating, default-img to the default value (80px, 'g', gravatar-img)
g.setGravatarNull();

// return a object with the properties size, rating, defaultImg
g.getGravatarOpts();

// return the email cleaned (trim() + inside space removed + toLowerCase + email REGEX check)
// a possible email not valid error can be returned
g.getCleanedEmail('[email protected]', function(err,cleanedEmail){
  if(err){
    // handle the error
    else {
      // do stuff with the cleaned email
      console.log(cleanedEmail);
    }
  }
});

// get the MD5 hash cypher of the trim(emailPassed) - email won't be validate
g.getMD5Token(email);

Errors

Use the callback to check if an error is raised during the path building operations :

  g.getGravatarURL('[email protected]', function(err,link){
    if (err){
      // handle the error
      console.log('Error', err);
    }
  });

Test

The package is tested with mocha and chai. You can find the test file in the /test folder. If you need to use more tests on the library, open an issue on the github repo (THANKS).