gravatar.js 489 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. const crypto = require('crypto');
  3. const querystring = require('querystring');
  4. function md5(str) {
  5. return crypto.createHash('md5').update(str).digest('hex');
  6. }
  7. function gravatarHelper(email, options) {
  8. if (typeof options === 'number') {
  9. options = {s: options};
  10. }
  11. let str = `https://www.gravatar.com/avatar/${md5(email.toLowerCase())}`;
  12. const qs = querystring.stringify(options);
  13. if (qs) str += `?${qs}`;
  14. return str;
  15. }
  16. module.exports = gravatarHelper;