/*! * isomorphic-mongo-objectid - v1.0.9 * Pure JavaScript implementation of mongodb ObjectId for the browser and server * https://github.com/john-doherty/isomorphic-mongo-objectid * @author John Doherty * @license MIT */ !function(){"use strict";var t=0,e=Math.floor(32767*Math.random()),i=Math.floor(16777216*Math.random());if("undefined"!=typeof window){var n=window.localStorage,r=parseInt(n.mongoMachineId,10);r>=0&&r<=16777215&&(i=Math.floor(n.mongoMachineId)),n.mongoMachineId=i}function s(){var n=arguments;if(!(this instanceof s))return n.length>0?new s(n[0],n[1],n[2],n[3]):new s;"object"==typeof n[0]?(this.timestamp=n[0].timestamp,this.machine=n[0].machine,this.pid=n[0].pid,this.increment=n[0].increment):"string"==typeof n[0]&&24===n[0].length?(this.timestamp=Number("0x"+n[0].substr(0,8)),this.machine=Number("0x"+n[0].substr(8,6)),this.pid=Number("0x"+n[0].substr(14,4)),this.increment=Number("0x"+n[0].substr(18,6))):4===n.length&&null!==n[0]?(this.timestamp=n[0],this.machine=n[1],this.pid=n[2],this.increment=n[3]):(this.timestamp=Math.floor((new Date).valueOf()/1e3),this.machine=i,this.pid=e,this.increment=t++,t>16777215&&(t=0))}s.prototype.getDate=function(){return new Date(1e3*this.timestamp)},s.prototype.toArray=function(){var t,e=this.toString(),i=[];for(t=0;t<12;t++)i[t]=parseInt(e.slice(2*t,2*t+2),16);return i},s.prototype.toString=function(){var t=this.timestamp.toString(16),e=this.machine.toString(16),i=this.pid.toString(16),n=this.increment.toString(16);return["00000000".substr(0,8-t.length)+t,"000000".substr(0,6-e.length)+e,"0000".substr(0,4-i.length)+i,"000000".substr(0,6-n.length)+n].join("")},"undefined"!=typeof module?module.exports=s:window.ObjectID=s}();