UNPKG

1.6 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":["default","bufferShiftEvent","records","length","shift","bufferWasFull","emit","limit","push","log","RingBuffer"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;IAEMU;;;AACJ,sBAAYH,KAAZ,EAAmB;AAAA;;AAAA;;AAEjB,UAAKL,OAAL,GAAe,EAAf;AACA,UAAKK,KAAL,GAAaA,KAAb;AACA,UAAKF,aAAL,GAAqB,KAArB;AAJiB;AAKlB;;;;0BAEKI;AACT,WAAKP,OAAL,CAAaM,IAAb,CAAkBC,GAAlB;AACA,UAAI,KAAKP,OAAL,CAAaC,MAAb,GAAsB,KAAKI,KAA/B,EAAsC;AACpC,aAAKL,OAAL,CAAaE,KAAb;;AAEA,YAAI,CAAC,KAAKC,aAAV,EAAyB;AACvB,eAAKC,IAAL,CAAU,cAAV;AACA,eAAKD,aAAL,GAAqB,IAArB;AACD;AACD,eAAO,KAAP;AACD;AACD,aAAO,IAAP;AACD;;;2BAEM;AACL,WAAKA,aAAL,GAAqB,KAArB;AACA,aAAO,KAAKH,OAAL,CAAaE,KAAb,EAAP;AACD;;;8BAES;AACR,aAAO,KAAKF,OAAL,CAAaC,MAAb,KAAwB,CAA/B;AACD;;;;;AAGH,IAAMF,mBAAmB,cAAzB;;QAGkBD;QACA"}
\No newline at end of file