From f6b0e6375115908e1465660836e62db5358cc7e9 Mon Sep 17 00:00:00 2001 From: ztimson Date: Wed, 20 Mar 2024 19:26:13 -0400 Subject: [PATCH] Updated gravatar function to supply default image --- package.json | 2 +- src/misc.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 2bc1642..717ae3a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ztimson/js-utilities", - "version": "0.3.6", + "version": "0.3.7", "description": "JavaScript Utility library", "author": "Zak Timson", "license": "MIT", diff --git a/src/misc.ts b/src/misc.ts index 9040f48..5d6bd00 100644 --- a/src/misc.ts +++ b/src/misc.ts @@ -16,11 +16,12 @@ export function formEncode(data: any): string { * Get profile image from Gravatar * * @param {string} email Account email address + * @param {string} def Default image, can be a link or '404', see: https://docs.gravatar.com/general/images/ * @returns {string} Gravatar URL */ -export function gravatar(email: string) { +export function gravatar(email: string, def='md') { if(!email) return ''; - return `https://www.gravatar.com/avatar/${md5(email)}`; + return `https://www.gravatar.com/avatar/${md5(email)}?d=${def}`; } /** Parts of a URL */