UNPKG

908 BJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5const crypto_1 = require("crypto");
6const querystring_1 = require("querystring");
7const cache_1 = __importDefault(require("./cache"));
8const cache = new cache_1.default();
9function md5(str) {
10 return (0, crypto_1.createHash)('md5').update(str).digest('hex');
11}
12function gravatarHelper(email, options) {
13 if (typeof options === 'number') {
14 options = { s: options };
15 }
16 const hash = cache.has(email) ? cache.get(email) : md5(email.toLowerCase());
17 let str = `https://www.gravatar.com/avatar/${hash}`;
18 const qs = (0, querystring_1.stringify)(options);
19 if (qs)
20 str += `?${qs}`;
21 cache.set('email', hash);
22 return str;
23}
24module.exports = gravatarHelper;
25//# sourceMappingURL=gravatar.js.map
\No newline at end of file