js-gravatar
Version:
A vanilla JS library to get a user's gravatar and if it doesn't exist provides one different from gravatar default
8 lines • 8.3 kB
JavaScript
!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.jsGravatar=r():t.jsGravatar=r()}(window,(function(){return function(t){var r={};function n(e){if(r[e])return r[e].exports;var o=r[e]={i:e,l:!1,exports:{}};return t[e].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=r,n.d=function(t,r,e){n.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:e})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,r){if(1&r&&(t=n(t)),8&r)return t;if(4&r&&"object"==typeof t&&t&&t.__esModule)return t;var e=Object.create(null);if(n.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var o in t)n.d(e,o,function(r){return t[r]}.bind(null,o));return e},n.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(r,"a",r),r},n.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},n.p="dist/",n(n.s=4)}([function(t,r){var n={utf8:{stringToBytes:function(t){return n.bin.stringToBytes(unescape(encodeURIComponent(t)))},bytesToString:function(t){return decodeURIComponent(escape(n.bin.bytesToString(t)))}},bin:{stringToBytes:function(t){for(var r=[],n=0;n<t.length;n++)r.push(255&t.charCodeAt(n));return r},bytesToString:function(t){for(var r=[],n=0;n<t.length;n++)r.push(String.fromCharCode(t[n]));return r.join("")}}};t.exports=n},function(t,r,n){var e,o,u,i,a;e=n(2),o=n(0).utf8,u=n(3),i=n(0).bin,(a=function(t,r){t.constructor==String?t=r&&"binary"===r.encoding?i.stringToBytes(t):o.stringToBytes(t):u(t)?t=Array.prototype.slice.call(t,0):Array.isArray(t)||(t=t.toString());for(var n=e.bytesToWords(t),c=8*t.length,f=1732584193,s=-271733879,l=-1732584194,d=271733878,p=0;p<n.length;p++)n[p]=16711935&(n[p]<<8|n[p]>>>24)|4278255360&(n[p]<<24|n[p]>>>8);n[c>>>5]|=128<<c%32,n[14+(c+64>>>9<<4)]=c;var y=a._ff,h=a._gg,b=a._hh,g=a._ii;for(p=0;p<n.length;p+=16){var v=f,m=s,_=l,A=d;f=y(f,s,l,d,n[p+0],7,-680876936),d=y(d,f,s,l,n[p+1],12,-389564586),l=y(l,d,f,s,n[p+2],17,606105819),s=y(s,l,d,f,n[p+3],22,-1044525330),f=y(f,s,l,d,n[p+4],7,-176418897),d=y(d,f,s,l,n[p+5],12,1200080426),l=y(l,d,f,s,n[p+6],17,-1473231341),s=y(s,l,d,f,n[p+7],22,-45705983),f=y(f,s,l,d,n[p+8],7,1770035416),d=y(d,f,s,l,n[p+9],12,-1958414417),l=y(l,d,f,s,n[p+10],17,-42063),s=y(s,l,d,f,n[p+11],22,-1990404162),f=y(f,s,l,d,n[p+12],7,1804603682),d=y(d,f,s,l,n[p+13],12,-40341101),l=y(l,d,f,s,n[p+14],17,-1502002290),f=h(f,s=y(s,l,d,f,n[p+15],22,1236535329),l,d,n[p+1],5,-165796510),d=h(d,f,s,l,n[p+6],9,-1069501632),l=h(l,d,f,s,n[p+11],14,643717713),s=h(s,l,d,f,n[p+0],20,-373897302),f=h(f,s,l,d,n[p+5],5,-701558691),d=h(d,f,s,l,n[p+10],9,38016083),l=h(l,d,f,s,n[p+15],14,-660478335),s=h(s,l,d,f,n[p+4],20,-405537848),f=h(f,s,l,d,n[p+9],5,568446438),d=h(d,f,s,l,n[p+14],9,-1019803690),l=h(l,d,f,s,n[p+3],14,-187363961),s=h(s,l,d,f,n[p+8],20,1163531501),f=h(f,s,l,d,n[p+13],5,-1444681467),d=h(d,f,s,l,n[p+2],9,-51403784),l=h(l,d,f,s,n[p+7],14,1735328473),f=b(f,s=h(s,l,d,f,n[p+12],20,-1926607734),l,d,n[p+5],4,-378558),d=b(d,f,s,l,n[p+8],11,-2022574463),l=b(l,d,f,s,n[p+11],16,1839030562),s=b(s,l,d,f,n[p+14],23,-35309556),f=b(f,s,l,d,n[p+1],4,-1530992060),d=b(d,f,s,l,n[p+4],11,1272893353),l=b(l,d,f,s,n[p+7],16,-155497632),s=b(s,l,d,f,n[p+10],23,-1094730640),f=b(f,s,l,d,n[p+13],4,681279174),d=b(d,f,s,l,n[p+0],11,-358537222),l=b(l,d,f,s,n[p+3],16,-722521979),s=b(s,l,d,f,n[p+6],23,76029189),f=b(f,s,l,d,n[p+9],4,-640364487),d=b(d,f,s,l,n[p+12],11,-421815835),l=b(l,d,f,s,n[p+15],16,530742520),f=g(f,s=b(s,l,d,f,n[p+2],23,-995338651),l,d,n[p+0],6,-198630844),d=g(d,f,s,l,n[p+7],10,1126891415),l=g(l,d,f,s,n[p+14],15,-1416354905),s=g(s,l,d,f,n[p+5],21,-57434055),f=g(f,s,l,d,n[p+12],6,1700485571),d=g(d,f,s,l,n[p+3],10,-1894986606),l=g(l,d,f,s,n[p+10],15,-1051523),s=g(s,l,d,f,n[p+1],21,-2054922799),f=g(f,s,l,d,n[p+8],6,1873313359),d=g(d,f,s,l,n[p+15],10,-30611744),l=g(l,d,f,s,n[p+6],15,-1560198380),s=g(s,l,d,f,n[p+13],21,1309151649),f=g(f,s,l,d,n[p+4],6,-145523070),d=g(d,f,s,l,n[p+11],10,-1120210379),l=g(l,d,f,s,n[p+2],15,718787259),s=g(s,l,d,f,n[p+9],21,-343485551),f=f+v>>>0,s=s+m>>>0,l=l+_>>>0,d=d+A>>>0}return e.endian([f,s,l,d])})._ff=function(t,r,n,e,o,u,i){var a=t+(r&n|~r&e)+(o>>>0)+i;return(a<<u|a>>>32-u)+r},a._gg=function(t,r,n,e,o,u,i){var a=t+(r&e|n&~e)+(o>>>0)+i;return(a<<u|a>>>32-u)+r},a._hh=function(t,r,n,e,o,u,i){var a=t+(r^n^e)+(o>>>0)+i;return(a<<u|a>>>32-u)+r},a._ii=function(t,r,n,e,o,u,i){var a=t+(n^(r|~e))+(o>>>0)+i;return(a<<u|a>>>32-u)+r},a._blocksize=16,a._digestsize=16,t.exports=function(t,r){if(null==t)throw new Error("Illegal argument "+t);var n=e.wordsToBytes(a(t,r));return r&&r.asBytes?n:r&&r.asString?i.bytesToString(n):e.bytesToHex(n)}},function(t,r){var n,e;n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e={rotl:function(t,r){return t<<r|t>>>32-r},rotr:function(t,r){return t<<32-r|t>>>r},endian:function(t){if(t.constructor==Number)return 16711935&e.rotl(t,8)|4278255360&e.rotl(t,24);for(var r=0;r<t.length;r++)t[r]=e.endian(t[r]);return t},randomBytes:function(t){for(var r=[];t>0;t--)r.push(Math.floor(256*Math.random()));return r},bytesToWords:function(t){for(var r=[],n=0,e=0;n<t.length;n++,e+=8)r[e>>>5]|=t[n]<<24-e%32;return r},wordsToBytes:function(t){for(var r=[],n=0;n<32*t.length;n+=8)r.push(t[n>>>5]>>>24-n%32&255);return r},bytesToHex:function(t){for(var r=[],n=0;n<t.length;n++)r.push((t[n]>>>4).toString(16)),r.push((15&t[n]).toString(16));return r.join("")},hexToBytes:function(t){for(var r=[],n=0;n<t.length;n+=2)r.push(parseInt(t.substr(n,2),16));return r},bytesToBase64:function(t){for(var r=[],e=0;e<t.length;e+=3)for(var o=t[e]<<16|t[e+1]<<8|t[e+2],u=0;u<4;u++)8*e+6*u<=8*t.length?r.push(n.charAt(o>>>6*(3-u)&63)):r.push("=");return r.join("")},base64ToBytes:function(t){t=t.replace(/[^A-Z0-9+\/]/gi,"");for(var r=[],e=0,o=0;e<t.length;o=++e%4)0!=o&&r.push((n.indexOf(t.charAt(e-1))&Math.pow(2,-2*o+8)-1)<<2*o|n.indexOf(t.charAt(e))>>>6-2*o);return r}},t.exports=e},function(t,r){function n(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}
/*!
* Determine if an object is a Buffer
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/
t.exports=function(t){return null!=t&&(n(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&n(t.slice(0,0))}(t)||!!t._isBuffer)}},function(t,r,n){"use strict";n.r(r),n.d(r,"validateOptions",(function(){return c})),n.d(r,"buildQueryStringFromOptions",(function(){return f}));var e=n(1),o=n.n(e);function u(t){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var i={BASE_URL:"https:"!==window.location.protocol?"http:".concat("//www.gravatar.com/avatar"):"https:".concat("//www.gravatar.com/avatar"),GRAVATAR_DEFAULTS:["404","mp","identicon","monsterid","wavatar","retro","robohash","blank"]},a={MISSING_ARGUMENT_ERROR:function(t){return"".concat(t," is required but was not provided.")},INVALID_ARGUMENT_TYPE:function(t,r){return"".concat(t," is expected to be of type ").concat(r,", but received ").concat(u(t))},DEFAULT_IMAGE_ERROR:"defaultImage can only be oneOf: ".concat(i.GRAVATAR_DEFAULTS.join(",")),IMAGE_SIZE_ERROR:"Size should not be greater than 2048 or less than 1."};function c(t){var r=t.email,n=t.md5Hash,e=t.size,o=t.defaultImage;if(!r&&!n)throw new Error(a.MISSING_ARGUMENT_ERROR("email or md5Hash"));if(e&&Number.isNaN(Number(e)))throw new Error(a.INVALID_ARGUMENT_TYPE(e,"number"));if(e>2048||e<1)throw new Error(a.IMAGE_SIZE_ERROR);if(o&&!i.GRAVATAR_DEFAULTS.includes(o))throw new Error(a.DEFAULT_IMAGE_ERROR)}function f(t){var r=t.size,n=t.defaultImage,e="?";return r&&(e+="s=".concat(r,"&")),n&&(e+="d=".concat(n,"&")),e.endsWith("&")||e.endsWith("?")?e.substr(0,e.length-1):e}r.default=function(t){c(t);var r=function(t){var r=t.email,n=t.md5Hash;return n||o()(r.trim().toLowerCase())}(t),n=f(t);return"".concat(i.BASE_URL,"/").concat(r).concat(n)}}]).default}));