animal-identicon
Version:
JavaScript library for generation animal icons using SVG
2 lines (1 loc) • 12.1 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("animalIdenticon",[],e):"object"==typeof exports?exports.animalIdenticon=e():t.animalIdenticon=e()}(window,function(){return function(t){var e={};function r(o){if(e[o])return e[o].exports;var n=e[o]={i:o,l:!1,exports:{}};return t[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=t,r.c=e,r.d=function(t,e,o){r.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:o})},r.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=5)}([function(t,e){(function(e){t.exports=e}).call(this,{})},function(t,e){var r;r=function(){return this}();try{r=r||Function("return this")()||(0,eval)("this")}catch(t){"object"==typeof window&&(r=window)}t.exports=r},function(t,e){var r,o,n=t.exports={};function i(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function s(t){if(r===setTimeout)return setTimeout(t,0);if((r===i||!r)&&setTimeout)return r=setTimeout,setTimeout(t,0);try{return r(t,0)}catch(e){try{return r.call(null,t,0)}catch(e){return r.call(this,t,0)}}}!function(){try{r="function"==typeof setTimeout?setTimeout:i}catch(t){r=i}try{o="function"==typeof clearTimeout?clearTimeout:a}catch(t){o=a}}();var c,h=[],u=!1,l=-1;function f(){u&&c&&(u=!1,c.length?h=c.concat(h):l=-1,h.length&&b())}function b(){if(!u){var t=s(f);u=!0;for(var e=h.length;e;){for(c=h,h=[];++l<e;)c&&c[l].run();l=-1,e=h.length}c=null,u=!1,function(t){if(o===clearTimeout)return clearTimeout(t);if((o===a||!o)&&clearTimeout)return o=clearTimeout,clearTimeout(t);try{o(t)}catch(e){try{return o.call(null,t)}catch(e){return o.call(this,t)}}}(t)}}function p(t,e){this.fun=t,this.array=e}function _(){}n.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];h.push(new p(t,e)),1!==h.length||u||s(b)},p.prototype.run=function(){this.fun.apply(null,this.array)},n.title="browser",n.browser=!0,n.env={},n.argv=[],n.version="",n.versions={},n.on=_,n.addListener=_,n.once=_,n.off=_,n.removeListener=_,n.removeAllListeners=_,n.emit=_,n.prependListener=_,n.prependOnceListener=_,n.listeners=function(t){return[]},n.binding=function(t){throw new Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(t){throw new Error("process.chdir is not supported")},n.umask=function(){return 0}},function(module,exports,__webpack_require__){(function(process,global){var __WEBPACK_AMD_DEFINE_RESULT__;!function(){"use strict";var root="object"==typeof window?window:{},NODE_JS=!root.JS_SHA1_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;NODE_JS&&(root=global);var COMMON_JS=!root.JS_SHA1_NO_COMMON_JS&&"object"==typeof module&&module.exports,AMD=__webpack_require__(0),HEX_CHARS="0123456789abcdef".split(""),EXTRA=[-2147483648,8388608,32768,128],SHIFT=[24,16,8,0],OUTPUT_TYPES=["hex","array","digest","arrayBuffer"],blocks=[],createOutputMethod=function(t){return function(e){return new Sha1(!0).update(e)[t]()}},createMethod=function(){var t=createOutputMethod("hex");NODE_JS&&(t=nodeWrap(t)),t.create=function(){return new Sha1},t.update=function(e){return t.create().update(e)};for(var e=0;e<OUTPUT_TYPES.length;++e){var r=OUTPUT_TYPES[e];t[r]=createOutputMethod(r)}return t},nodeWrap=function(method){var crypto=eval("require('crypto')"),Buffer=eval("require('buffer').Buffer"),nodeMethod=function(t){if("string"==typeof t)return crypto.createHash("sha1").update(t,"utf8").digest("hex");if(t.constructor===ArrayBuffer)t=new Uint8Array(t);else if(void 0===t.length)return method(t);return crypto.createHash("sha1").update(new Buffer(t)).digest("hex")};return nodeMethod};function Sha1(t){t?(blocks[0]=blocks[16]=blocks[1]=blocks[2]=blocks[3]=blocks[4]=blocks[5]=blocks[6]=blocks[7]=blocks[8]=blocks[9]=blocks[10]=blocks[11]=blocks[12]=blocks[13]=blocks[14]=blocks[15]=0,this.blocks=blocks):this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],this.h0=1732584193,this.h1=4023233417,this.h2=2562383102,this.h3=271733878,this.h4=3285377520,this.block=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0}Sha1.prototype.update=function(t){if(!this.finalized){var e="string"!=typeof t;e&&t.constructor===root.ArrayBuffer&&(t=new Uint8Array(t));for(var r,o,n=0,i=t.length||0,a=this.blocks;n<i;){if(this.hashed&&(this.hashed=!1,a[0]=this.block,a[16]=a[1]=a[2]=a[3]=a[4]=a[5]=a[6]=a[7]=a[8]=a[9]=a[10]=a[11]=a[12]=a[13]=a[14]=a[15]=0),e)for(o=this.start;n<i&&o<64;++n)a[o>>2]|=t[n]<<SHIFT[3&o++];else for(o=this.start;n<i&&o<64;++n)(r=t.charCodeAt(n))<128?a[o>>2]|=r<<SHIFT[3&o++]:r<2048?(a[o>>2]|=(192|r>>6)<<SHIFT[3&o++],a[o>>2]|=(128|63&r)<<SHIFT[3&o++]):r<55296||r>=57344?(a[o>>2]|=(224|r>>12)<<SHIFT[3&o++],a[o>>2]|=(128|r>>6&63)<<SHIFT[3&o++],a[o>>2]|=(128|63&r)<<SHIFT[3&o++]):(r=65536+((1023&r)<<10|1023&t.charCodeAt(++n)),a[o>>2]|=(240|r>>18)<<SHIFT[3&o++],a[o>>2]|=(128|r>>12&63)<<SHIFT[3&o++],a[o>>2]|=(128|r>>6&63)<<SHIFT[3&o++],a[o>>2]|=(128|63&r)<<SHIFT[3&o++]);this.lastByteIndex=o,this.bytes+=o-this.start,o>=64?(this.block=a[16],this.start=o-64,this.hash(),this.hashed=!0):this.start=o}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296<<0,this.bytes=this.bytes%4294967296),this}},Sha1.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,e=this.lastByteIndex;t[16]=this.block,t[e>>2]|=EXTRA[3&e],this.block=t[16],e>=56&&(this.hashed||this.hash(),t[0]=this.block,t[16]=t[1]=t[2]=t[3]=t[4]=t[5]=t[6]=t[7]=t[8]=t[9]=t[10]=t[11]=t[12]=t[13]=t[14]=t[15]=0),t[14]=this.hBytes<<3|this.bytes>>>29,t[15]=this.bytes<<3,this.hash()}},Sha1.prototype.hash=function(){var t,e,r=this.h0,o=this.h1,n=this.h2,i=this.h3,a=this.h4,s=this.blocks;for(t=16;t<80;++t)e=s[t-3]^s[t-8]^s[t-14]^s[t-16],s[t]=e<<1|e>>>31;for(t=0;t<20;t+=5)r=(e=(o=(e=(n=(e=(i=(e=(a=(e=r<<5|r>>>27)+(o&n|~o&i)+a+1518500249+s[t]<<0)<<5|a>>>27)+(r&(o=o<<30|o>>>2)|~r&n)+i+1518500249+s[t+1]<<0)<<5|i>>>27)+(a&(r=r<<30|r>>>2)|~a&o)+n+1518500249+s[t+2]<<0)<<5|n>>>27)+(i&(a=a<<30|a>>>2)|~i&r)+o+1518500249+s[t+3]<<0)<<5|o>>>27)+(n&(i=i<<30|i>>>2)|~n&a)+r+1518500249+s[t+4]<<0,n=n<<30|n>>>2;for(;t<40;t+=5)r=(e=(o=(e=(n=(e=(i=(e=(a=(e=r<<5|r>>>27)+(o^n^i)+a+1859775393+s[t]<<0)<<5|a>>>27)+(r^(o=o<<30|o>>>2)^n)+i+1859775393+s[t+1]<<0)<<5|i>>>27)+(a^(r=r<<30|r>>>2)^o)+n+1859775393+s[t+2]<<0)<<5|n>>>27)+(i^(a=a<<30|a>>>2)^r)+o+1859775393+s[t+3]<<0)<<5|o>>>27)+(n^(i=i<<30|i>>>2)^a)+r+1859775393+s[t+4]<<0,n=n<<30|n>>>2;for(;t<60;t+=5)r=(e=(o=(e=(n=(e=(i=(e=(a=(e=r<<5|r>>>27)+(o&n|o&i|n&i)+a-1894007588+s[t]<<0)<<5|a>>>27)+(r&(o=o<<30|o>>>2)|r&n|o&n)+i-1894007588+s[t+1]<<0)<<5|i>>>27)+(a&(r=r<<30|r>>>2)|a&o|r&o)+n-1894007588+s[t+2]<<0)<<5|n>>>27)+(i&(a=a<<30|a>>>2)|i&r|a&r)+o-1894007588+s[t+3]<<0)<<5|o>>>27)+(n&(i=i<<30|i>>>2)|n&a|i&a)+r-1894007588+s[t+4]<<0,n=n<<30|n>>>2;for(;t<80;t+=5)r=(e=(o=(e=(n=(e=(i=(e=(a=(e=r<<5|r>>>27)+(o^n^i)+a-899497514+s[t]<<0)<<5|a>>>27)+(r^(o=o<<30|o>>>2)^n)+i-899497514+s[t+1]<<0)<<5|i>>>27)+(a^(r=r<<30|r>>>2)^o)+n-899497514+s[t+2]<<0)<<5|n>>>27)+(i^(a=a<<30|a>>>2)^r)+o-899497514+s[t+3]<<0)<<5|o>>>27)+(n^(i=i<<30|i>>>2)^a)+r-899497514+s[t+4]<<0,n=n<<30|n>>>2;this.h0=this.h0+r<<0,this.h1=this.h1+o<<0,this.h2=this.h2+n<<0,this.h3=this.h3+i<<0,this.h4=this.h4+a<<0},Sha1.prototype.hex=function(){this.finalize();var t=this.h0,e=this.h1,r=this.h2,o=this.h3,n=this.h4;return HEX_CHARS[t>>28&15]+HEX_CHARS[t>>24&15]+HEX_CHARS[t>>20&15]+HEX_CHARS[t>>16&15]+HEX_CHARS[t>>12&15]+HEX_CHARS[t>>8&15]+HEX_CHARS[t>>4&15]+HEX_CHARS[15&t]+HEX_CHARS[e>>28&15]+HEX_CHARS[e>>24&15]+HEX_CHARS[e>>20&15]+HEX_CHARS[e>>16&15]+HEX_CHARS[e>>12&15]+HEX_CHARS[e>>8&15]+HEX_CHARS[e>>4&15]+HEX_CHARS[15&e]+HEX_CHARS[r>>28&15]+HEX_CHARS[r>>24&15]+HEX_CHARS[r>>20&15]+HEX_CHARS[r>>16&15]+HEX_CHARS[r>>12&15]+HEX_CHARS[r>>8&15]+HEX_CHARS[r>>4&15]+HEX_CHARS[15&r]+HEX_CHARS[o>>28&15]+HEX_CHARS[o>>24&15]+HEX_CHARS[o>>20&15]+HEX_CHARS[o>>16&15]+HEX_CHARS[o>>12&15]+HEX_CHARS[o>>8&15]+HEX_CHARS[o>>4&15]+HEX_CHARS[15&o]+HEX_CHARS[n>>28&15]+HEX_CHARS[n>>24&15]+HEX_CHARS[n>>20&15]+HEX_CHARS[n>>16&15]+HEX_CHARS[n>>12&15]+HEX_CHARS[n>>8&15]+HEX_CHARS[n>>4&15]+HEX_CHARS[15&n]},Sha1.prototype.toString=Sha1.prototype.hex,Sha1.prototype.digest=function(){this.finalize();var t=this.h0,e=this.h1,r=this.h2,o=this.h3,n=this.h4;return[t>>24&255,t>>16&255,t>>8&255,255&t,e>>24&255,e>>16&255,e>>8&255,255&e,r>>24&255,r>>16&255,r>>8&255,255&r,o>>24&255,o>>16&255,o>>8&255,255&o,n>>24&255,n>>16&255,n>>8&255,255&n]},Sha1.prototype.array=Sha1.prototype.digest,Sha1.prototype.arrayBuffer=function(){this.finalize();var t=new ArrayBuffer(20),e=new DataView(t);return e.setUint32(0,this.h0),e.setUint32(4,this.h1),e.setUint32(8,this.h2),e.setUint32(12,this.h3),e.setUint32(16,this.h4),t};var exports=createMethod();COMMON_JS?module.exports=exports:(root.sha1=exports,AMD&&(__WEBPACK_AMD_DEFINE_RESULT__=function(){return exports}.call(exports,__webpack_require__,exports,module),void 0===__WEBPACK_AMD_DEFINE_RESULT__||(module.exports=__WEBPACK_AMD_DEFINE_RESULT__)))}()}).call(this,__webpack_require__(2),__webpack_require__(1))},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var o,n=function(){function t(t,e){for(var r=0;r<e.length;r++){var o=e[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,r,o){return r&&t(e.prototype,r),o&&t(e,o),e}}(),i=r(3),a=(o=i)&&o.__esModule?o:{default:o};var s=function(){function t(e){if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),"string"!=typeof e)throw new Error("Please pass string argument");if(e.length<=0)throw new Error("Please pass not blank string");this.identifier=e}return n(t,[{key:"toSvg",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:128,e=this._generateDigits(),r=this._generateIcon(e);return'<svg style="background-color: #'+this._generateColor(e)+"; height: "+t+"px; width: "+t+'px">\n <image xlink:href="https://ssl.gstatic.com/docs/common/profile/'+r+'_lg.png" style="height: '+t+"px; width: "+t+'px"></image>\n </svg>'}},{key:"_generateDigits",value:function(){return parseInt((0,a.default)(this.identifier).slice(-3),16)}},{key:"_generateIcon",value:function(t){return["alligator","anteater","armadillo","auroch","badger","bat","beaver","buffalo","camel","capybara","chameleon","cheetah","chinchilla","chipmunk","chupacabra","cormorant","coyote","crow","dingo","dolphin","duck","elephant","ferret","fox","giraffe","gopher","grizzly","hippo","hyena","ibex","iguana","jackal","kangaroo","koala","kraken","lemur","leopard","liger","llama","manatee","mink","monkey","moose","narwhal","orangutan","otter","panda","penguin","platypus","python","quagga","rabbit","raccoon","rhino","sheep","shrew","skunk","squirrel","tiger","turtle","walrus","wolf","wolverine","wombat"][t%64]}},{key:"_generateColor",value:function(t){return["721acb","841acb","931acb","a51acb","b41acb","c51acb","cb1abf","cb1ab1","cb1a9f","cb1a8d","cb1a7e","cb1a6c","cb1a5e","cb1a4c","cb1a3a","cb1a2b","cb1a1a","cb2b1a","cb3a1a","cb4c1a","cb5e1a","cb6c1a","cb7e1a","cb8d1a","cb9f1a","cbb11a","cbbf1a","c5cb1a","b4cb1a","a5cb1a","93cb1a","84cb1a","72cb1a","61cb1a","52cb1a","40cb1a","31cb1a","1fcb1a","1acb25","1acb34","1acb46","1acb58","1acb67","1acb78","1acb87","1acb99","1acbab","1acbb9","1acbcb","1ab9cb","1aabcb","1a99cb","1a87cb","1a78cb","1a67cb","1a58cb","1a46cb","1a34cb","1a25cb","1f1acb","311acb","401acb","521acb","611acb"][Math.floor(t/64)]}}]),t}();e.default=s,t.exports=e.default},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var o,n=r(4),i=(o=n)&&o.__esModule?o:{default:o};e.default=function(t){return new i.default(t)},t.exports=e.default}])});