UNPKG

1.46 kBSource Map (JSON)View Raw
1{"version":3,"file":"ringbuffer.js","sources":["../src/ringbuffer.js"],"sourcesContent":["import { EventEmitter } from 'events';\n\nclass RingBuffer extends EventEmitter {\n constructor(limit) {\n super();\n this.records = [];\n this.limit = limit;\n this.bufferWasFull = false;\n }\n\n write(log) {\n this.records.push(log);\n if (this.records.length > this.limit) {\n this.records.shift();\n\n if (!this.bufferWasFull) {\n this.emit('buffer shift');\n this.bufferWasFull = true;\n }\n return false;\n }\n return true;\n }\n\n read() {\n this.bufferWasFull = false;\n return this.records.shift();\n }\n\n isEmpty() {\n return this.records.length === 0;\n }\n}\n\nconst bufferShiftEvent = 'buffer shift';\n\nexport {\n RingBuffer as default,\n bufferShiftEvent\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;IAEM;;;AACJ,sBAAY,KAAZ,EAAmB;AAAA;;AAAA;;AAEjB,UAAK,OAAL,GAAe,EAAf;AACA,UAAK,KAAL,GAAa,KAAb;AACA,UAAK,aAAL,GAAqB,KAArB;AAJiB;AAKlB;;;;0BAEK;AACT,WAAK,OAAL,CAAa,IAAb,CAAkB,GAAlB;AACA,UAAI,KAAK,OAAL,CAAa,MAAb,GAAsB,KAAK,KAA/B,EAAsC;AACpC,aAAK,OAAL,CAAa,KAAb;;AAEA,YAAI,CAAC,KAAK,aAAV,EAAyB;AACvB,eAAK,IAAL,CAAU,cAAV;AACA,eAAK,aAAL,GAAqB,IAArB;AACD;AACD,eAAO,KAAP;AACD;AACD,aAAO,IAAP;AACD;;;2BAEM;AACL,WAAK,aAAL,GAAqB,KAArB;AACA,aAAO,KAAK,OAAL,CAAa,KAAb,EAAP;AACD;;;8BAES;AACR,aAAO,KAAK,OAAL,CAAa,MAAb,KAAwB,CAA/B;AACD;;;;;AAGH,IAAM,mBAAmB,cAAzB;;QAGkB;QACA"}
\No newline at end of file