-
Notifications
You must be signed in to change notification settings - Fork 13
/
receptacle.js
1 lines (1 loc) · 3.95 KB
/
receptacle.js
1
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.receptacle=e()}}(function(){return function(){function e(t,i,s){function r(o,a){if(!i[o]){if(!t[o]){var u="function"==typeof require&&require;if(!a&&u)return u(o,!0);if(n)return n(o,!0);var h=new Error("Cannot find module '"+o+"'");throw h.code="MODULE_NOT_FOUND",h}var f=i[o]={exports:{}};t[o][0].call(f.exports,function(e){return r(t[o][1][e]||e)},f,f.exports,e,t,i,s)}return i[o].exports}for(var n="function"==typeof require&&require,o=0;o<s.length;o++)r(s[o]);return r}return e}()({1:[function(e,t){"use strict";function i(){return(1e9*Math.random()>>>0)+o++}function s(e){e=e||{},this.id=e.id||i(),this.max=e.max||1/0,this.items=e.items||[],this._lookup={},this.size=this.items.length,this.lastModified=new Date(e.lastModified||new Date);for(var t,s,r=this.items.length;r--;)t=this.items[r],s=new Date(t.expires)-new Date,this._lookup[t.key]=t,s>0?this.expire(t.key,s):s<=0&&this.delete(t.key)}t.exports=s;var r=e(2),n=s.prototype,o=new Date%1e9;n.has=function(e){return e in this._lookup},n.get=function(e){if(!this.has(e))return null;var t=this._lookup[e];return t.refresh&&this.expire(e,t.refresh),this.items.splice(this.items.indexOf(t),1),this.items.push(t),t.value},n.meta=function(e){if(!this.has(e))return null;var t=this._lookup[e];return"meta"in t?t.meta:null},n.set=function(e,t,i){var s=this._lookup[e],r=this._lookup[e]={key:e,value:t};return this.lastModified=new Date,s?(clearTimeout(s.timeout),this.items.splice(this.items.indexOf(s),1,r)):(this.size>=this.max&&this.delete(this.items[0].key),this.items.push(r),this.size++),i&&("ttl"in i&&this.expire(e,i.ttl),"meta"in i&&(r.meta=i.meta),i.refresh&&(r.refresh=i.ttl)),this},n.delete=function(e){var t=this._lookup[e];return!!t&&(this.lastModified=new Date,this.items.splice(this.items.indexOf(t),1),clearTimeout(t.timeout),delete this._lookup[e],this.size--,this)},n.expire=function(e,t){var i=t||0,s=this._lookup[e];if(!s)return this;if("string"==typeof i&&(i=r(t)),"number"!=typeof i)throw new TypeError("Expiration time must be a string or number.");return clearTimeout(s.timeout),s.timeout=setTimeout(this.delete.bind(this,s.key),i),s.expires=Number(new Date)+i,this},n.clear=function(){for(var e=this.items.length;e--;)this.delete(this.items[e].key);return this},n.toJSON=function(){for(var e,t=new Array(this.items.length),i=t.length;i--;)e=this.items[i],t[i]={key:e.key,meta:e.meta,value:e.value,expires:e.expires,refresh:e.refresh};return{id:this.id,max:isFinite(this.max)?this.max:void 0,lastModified:this.lastModified,items:t}}},{2:2}],2:[function(e,t){function i(e){if(e=String(e),!(e.length>1e4)){var t=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(e);if(t){var i=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return i*f;case"days":case"day":case"d":return i*h;case"hours":case"hour":case"hrs":case"hr":case"h":return i*u;case"minutes":case"minute":case"mins":case"min":case"m":return i*a;case"seconds":case"second":case"secs":case"sec":case"s":return i*o;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return i;default:return}}}}function s(e){return e>=h?Math.round(e/h)+"d":e>=u?Math.round(e/u)+"h":e>=a?Math.round(e/a)+"m":e>=o?Math.round(e/o)+"s":e+"ms"}function r(e){return n(e,h,"day")||n(e,u,"hour")||n(e,a,"minute")||n(e,o,"second")||e+" ms"}function n(e,t,i){if(!(e<t))return e<1.5*t?Math.floor(e/t)+" "+i:Math.ceil(e/t)+" "+i+"s"}var o=1e3,a=60*o,u=60*a,h=24*u,f=365.25*h;t.exports=function(e,t){t=t||{};var n=typeof e;if("string"===n&&e.length>0)return i(e);if("number"===n&&!1===isNaN(e))return t.long?r(e):s(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},{}]},{},[1])(1)});