1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | const crypto_1 = require("crypto");
|
6 | const querystring_1 = require("querystring");
|
7 | const cache_1 = __importDefault(require("./cache"));
|
8 | const cache = new cache_1.default();
|
9 | function md5(str) {
|
10 | return (0, crypto_1.createHash)('md5').update(str).digest('hex');
|
11 | }
|
12 | function 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 | }
|
24 | module.exports = gravatarHelper;
|
25 |
|
\ | No newline at end of file |