{"version":3,"file":"fcs-parser.min.js","sources":["../node_modules/iobuffer/lib-esm/text-encoding-polyfill.js","../node_modules/iobuffer/lib-esm/utf8.browser.js","../node_modules/iobuffer/lib-esm/IOBuffer.js","../src/index.js"],"sourcesContent":["\"use strict\";\r\n/*\r\n * Copyright 2017 Sam Thorogood. All rights reserved.\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\r\n * use this file except in compliance with the License. You may obtain a copy of\r\n * the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\r\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\r\n * License for the specific language governing permissions and limitations under\r\n * the License.\r\n */\r\n(function (scope) {\r\n 'use strict';\r\n // fail early\r\n if (scope['TextEncoder'] && scope['TextDecoder']) {\r\n return false;\r\n }\r\n /**\r\n * @constructor\r\n * @param {string=} utfLabel\r\n */\r\n function FastTextEncoder(utfLabel = 'utf-8') {\r\n if (utfLabel !== 'utf-8') {\r\n throw new RangeError(`Failed to construct 'TextEncoder': The encoding label provided ('${utfLabel}') is invalid.`);\r\n }\r\n }\r\n Object.defineProperty(FastTextEncoder.prototype, 'encoding', {\r\n value: 'utf-8',\r\n });\r\n /**\r\n * @param {string} string\r\n * @param {{stream: boolean}=} options\r\n * @return {!Uint8Array}\r\n */\r\n FastTextEncoder.prototype.encode = function (string, options = { stream: false }) {\r\n if (options.stream) {\r\n throw new Error(`Failed to encode: the 'stream' option is unsupported.`);\r\n }\r\n let pos = 0;\r\n const len = string.length;\r\n const out = [];\r\n let at = 0; // output position\r\n let tlen = Math.max(32, len + (len >> 1) + 7); // 1.5x size\r\n let target = new Uint8Array((tlen >> 3) << 3); // ... but at 8 byte offset\r\n while (pos < len) {\r\n let value = string.charCodeAt(pos++);\r\n if (value >= 0xd800 && value <= 0xdbff) {\r\n // high surrogate\r\n if (pos < len) {\r\n const extra = string.charCodeAt(pos);\r\n if ((extra & 0xfc00) === 0xdc00) {\r\n ++pos;\r\n value = ((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000;\r\n }\r\n }\r\n if (value >= 0xd800 && value <= 0xdbff) {\r\n continue; // drop lone surrogate\r\n }\r\n }\r\n // expand the buffer if we couldn't write 4 bytes\r\n if (at + 4 > target.length) {\r\n tlen += 8; // minimum extra\r\n tlen *= 1.0 + (pos / string.length) * 2; // take 2x the remaining\r\n tlen = (tlen >> 3) << 3; // 8 byte offset\r\n const update = new Uint8Array(tlen);\r\n update.set(target);\r\n target = update;\r\n }\r\n if ((value & 0xffffff80) === 0) {\r\n // 1-byte\r\n target[at++] = value; // ASCII\r\n continue;\r\n }\r\n else if ((value & 0xfffff800) === 0) {\r\n // 2-byte\r\n target[at++] = ((value >> 6) & 0x1f) | 0xc0;\r\n }\r\n else if ((value & 0xffff0000) === 0) {\r\n // 3-byte\r\n target[at++] = ((value >> 12) & 0x0f) | 0xe0;\r\n target[at++] = ((value >> 6) & 0x3f) | 0x80;\r\n }\r\n else if ((value & 0xffe00000) === 0) {\r\n // 4-byte\r\n target[at++] = ((value >> 18) & 0x07) | 0xf0;\r\n target[at++] = ((value >> 12) & 0x3f) | 0x80;\r\n target[at++] = ((value >> 6) & 0x3f) | 0x80;\r\n }\r\n else {\r\n // FIXME: do we care\r\n continue;\r\n }\r\n target[at++] = (value & 0x3f) | 0x80;\r\n }\r\n return target.slice(0, at);\r\n };\r\n /**\r\n * @constructor\r\n * @param {string=} utfLabel\r\n * @param {{fatal: boolean}=} options\r\n */\r\n function FastTextDecoder(utfLabel = 'utf-8', options = { fatal: false }) {\r\n if (utfLabel !== 'utf-8') {\r\n throw new RangeError(`Failed to construct 'TextDecoder': The encoding label provided ('${utfLabel}') is invalid.`);\r\n }\r\n if (options.fatal) {\r\n throw new Error(`Failed to construct 'TextDecoder': the 'fatal' option is unsupported.`);\r\n }\r\n }\r\n Object.defineProperty(FastTextDecoder.prototype, 'encoding', {\r\n value: 'utf-8',\r\n });\r\n Object.defineProperty(FastTextDecoder.prototype, 'fatal', { value: false });\r\n Object.defineProperty(FastTextDecoder.prototype, 'ignoreBOM', {\r\n value: false,\r\n });\r\n /**\r\n * @param {(!ArrayBuffer|!ArrayBufferView)} buffer\r\n * @param {{stream: boolean}=} options\r\n */\r\n FastTextDecoder.prototype.decode = function (buffer, options = { stream: false }) {\r\n if (options['stream']) {\r\n throw new Error(`Failed to decode: the 'stream' option is unsupported.`);\r\n }\r\n const bytes = new Uint8Array(buffer);\r\n let pos = 0;\r\n const len = bytes.length;\r\n const out = [];\r\n while (pos < len) {\r\n const byte1 = bytes[pos++];\r\n if (byte1 === 0) {\r\n break; // NULL\r\n }\r\n if ((byte1 & 0x80) === 0) {\r\n // 1-byte\r\n out.push(byte1);\r\n }\r\n else if ((byte1 & 0xe0) === 0xc0) {\r\n // 2-byte\r\n const byte2 = bytes[pos++] & 0x3f;\r\n out.push(((byte1 & 0x1f) << 6) | byte2);\r\n }\r\n else if ((byte1 & 0xf0) === 0xe0) {\r\n const byte2 = bytes[pos++] & 0x3f;\r\n const byte3 = bytes[pos++] & 0x3f;\r\n out.push(((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3);\r\n }\r\n else if ((byte1 & 0xf8) === 0xf0) {\r\n const byte2 = bytes[pos++] & 0x3f;\r\n const byte3 = bytes[pos++] & 0x3f;\r\n const byte4 = bytes[pos++] & 0x3f;\r\n // this can be > 0xffff, so possibly generate surrogates\r\n let codepoint = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;\r\n if (codepoint > 0xffff) {\r\n // codepoint &= ~0x10000;\r\n codepoint -= 0x10000;\r\n out.push(((codepoint >>> 10) & 0x3ff) | 0xd800);\r\n codepoint = 0xdc00 | (codepoint & 0x3ff);\r\n }\r\n out.push(codepoint);\r\n }\r\n else {\r\n // FIXME: we're ignoring this\r\n }\r\n }\r\n return String.fromCharCode.apply(null, out);\r\n };\r\n scope['TextEncoder'] = FastTextEncoder;\r\n scope['TextDecoder'] = FastTextDecoder;\r\n})(typeof window !== 'undefined'\r\n ? window\r\n : typeof self !== 'undefined'\r\n ? self\r\n : this);\r\n//# sourceMappingURL=text-encoding-polyfill.js.map","import './text-encoding-polyfill';\r\nconst decoder = new TextDecoder('utf-8');\r\nexport function decode(bytes) {\r\n return decoder.decode(bytes);\r\n}\r\nconst encoder = new TextEncoder();\r\nexport function encode(str) {\r\n return encoder.encode(str);\r\n}\r\n//# sourceMappingURL=utf8.browser.js.map","import { decode, encode } from './utf8';\r\nconst defaultByteLength = 1024 * 8;\r\nexport class IOBuffer {\r\n /**\r\n * @param data - The data to construct the IOBuffer with.\r\n * If data is a number, it will be the new buffer's length
\r\n * If data is `undefined`, the buffer will be initialized with a default length of 8Kb
\r\n * If data is an ArrayBuffer, SharedArrayBuffer, an ArrayBufferView (Typed Array), an IOBuffer instance,\r\n * or a Node.js Buffer, a view will be created over the underlying ArrayBuffer.\r\n * @param options\r\n */\r\n constructor(data = defaultByteLength, options = {}) {\r\n let dataIsGiven = false;\r\n if (typeof data === 'number') {\r\n data = new ArrayBuffer(data);\r\n }\r\n else {\r\n dataIsGiven = true;\r\n this.lastWrittenByte = data.byteLength;\r\n }\r\n const offset = options.offset ? options.offset >>> 0 : 0;\r\n const byteLength = data.byteLength - offset;\r\n let dvOffset = offset;\r\n if (ArrayBuffer.isView(data) || data instanceof IOBuffer) {\r\n if (data.byteLength !== data.buffer.byteLength) {\r\n dvOffset = data.byteOffset + offset;\r\n }\r\n data = data.buffer;\r\n }\r\n if (dataIsGiven) {\r\n this.lastWrittenByte = byteLength;\r\n }\r\n else {\r\n this.lastWrittenByte = 0;\r\n }\r\n this.buffer = data;\r\n this.length = byteLength;\r\n this.byteLength = byteLength;\r\n this.byteOffset = dvOffset;\r\n this.offset = 0;\r\n this.littleEndian = true;\r\n this._data = new DataView(this.buffer, dvOffset, byteLength);\r\n this._mark = 0;\r\n this._marks = [];\r\n }\r\n /**\r\n * Checks if the memory allocated to the buffer is sufficient to store more\r\n * bytes after the offset.\r\n * @param byteLength - The needed memory in bytes.\r\n * @returns `true` if there is sufficient space and `false` otherwise.\r\n */\r\n available(byteLength = 1) {\r\n return this.offset + byteLength <= this.length;\r\n }\r\n /**\r\n * Check if little-endian mode is used for reading and writing multi-byte\r\n * values.\r\n * @returns `true` if little-endian mode is used, `false` otherwise.\r\n */\r\n isLittleEndian() {\r\n return this.littleEndian;\r\n }\r\n /**\r\n * Set little-endian mode for reading and writing multi-byte values.\r\n */\r\n setLittleEndian() {\r\n this.littleEndian = true;\r\n return this;\r\n }\r\n /**\r\n * Check if big-endian mode is used for reading and writing multi-byte values.\r\n * @returns `true` if big-endian mode is used, `false` otherwise.\r\n */\r\n isBigEndian() {\r\n return !this.littleEndian;\r\n }\r\n /**\r\n * Switches to big-endian mode for reading and writing multi-byte values.\r\n */\r\n setBigEndian() {\r\n this.littleEndian = false;\r\n return this;\r\n }\r\n /**\r\n * Move the pointer n bytes forward.\r\n * @param n - Number of bytes to skip.\r\n */\r\n skip(n = 1) {\r\n this.offset += n;\r\n return this;\r\n }\r\n /**\r\n * Move the pointer to the given offset.\r\n * @param offset\r\n */\r\n seek(offset) {\r\n this.offset = offset;\r\n return this;\r\n }\r\n /**\r\n * Store the current pointer offset.\r\n * @see {@link IOBuffer#reset}\r\n */\r\n mark() {\r\n this._mark = this.offset;\r\n return this;\r\n }\r\n /**\r\n * Move the pointer back to the last pointer offset set by mark.\r\n * @see {@link IOBuffer#mark}\r\n */\r\n reset() {\r\n this.offset = this._mark;\r\n return this;\r\n }\r\n /**\r\n * Push the current pointer offset to the mark stack.\r\n * @see {@link IOBuffer#popMark}\r\n */\r\n pushMark() {\r\n this._marks.push(this.offset);\r\n return this;\r\n }\r\n /**\r\n * Pop the last pointer offset from the mark stack, and set the current\r\n * pointer offset to the popped value.\r\n * @see {@link IOBuffer#pushMark}\r\n */\r\n popMark() {\r\n const offset = this._marks.pop();\r\n if (offset === undefined) {\r\n throw new Error('Mark stack empty');\r\n }\r\n this.seek(offset);\r\n return this;\r\n }\r\n /**\r\n * Move the pointer offset back to 0.\r\n */\r\n rewind() {\r\n this.offset = 0;\r\n return this;\r\n }\r\n /**\r\n * Make sure the buffer has sufficient memory to write a given byteLength at\r\n * the current pointer offset.\r\n * If the buffer's memory is insufficient, this method will create a new\r\n * buffer (a copy) with a length that is twice (byteLength + current offset).\r\n * @param byteLength\r\n */\r\n ensureAvailable(byteLength = 1) {\r\n if (!this.available(byteLength)) {\r\n const lengthNeeded = this.offset + byteLength;\r\n const newLength = lengthNeeded * 2;\r\n const newArray = new Uint8Array(newLength);\r\n newArray.set(new Uint8Array(this.buffer));\r\n this.buffer = newArray.buffer;\r\n this.length = this.byteLength = newLength;\r\n this._data = new DataView(this.buffer);\r\n }\r\n return this;\r\n }\r\n /**\r\n * Read a byte and return false if the byte's value is 0, or true otherwise.\r\n * Moves pointer forward by one byte.\r\n */\r\n readBoolean() {\r\n return this.readUint8() !== 0;\r\n }\r\n /**\r\n * Read a signed 8-bit integer and move pointer forward by 1 byte.\r\n */\r\n readInt8() {\r\n return this._data.getInt8(this.offset++);\r\n }\r\n /**\r\n * Read an unsigned 8-bit integer and move pointer forward by 1 byte.\r\n */\r\n readUint8() {\r\n return this._data.getUint8(this.offset++);\r\n }\r\n /**\r\n * Alias for {@link IOBuffer#readUint8}.\r\n */\r\n readByte() {\r\n return this.readUint8();\r\n }\r\n /**\r\n * Read `n` bytes and move pointer forward by `n` bytes.\r\n */\r\n readBytes(n = 1) {\r\n const bytes = new Uint8Array(n);\r\n for (let i = 0; i < n; i++) {\r\n bytes[i] = this.readByte();\r\n }\r\n return bytes;\r\n }\r\n /**\r\n * Read a 16-bit signed integer and move pointer forward by 2 bytes.\r\n */\r\n readInt16() {\r\n const value = this._data.getInt16(this.offset, this.littleEndian);\r\n this.offset += 2;\r\n return value;\r\n }\r\n /**\r\n * Read a 16-bit unsigned integer and move pointer forward by 2 bytes.\r\n */\r\n readUint16() {\r\n const value = this._data.getUint16(this.offset, this.littleEndian);\r\n this.offset += 2;\r\n return value;\r\n }\r\n /**\r\n * Read a 32-bit signed integer and move pointer forward by 4 bytes.\r\n */\r\n readInt32() {\r\n const value = this._data.getInt32(this.offset, this.littleEndian);\r\n this.offset += 4;\r\n return value;\r\n }\r\n /**\r\n * Read a 32-bit unsigned integer and move pointer forward by 4 bytes.\r\n */\r\n readUint32() {\r\n const value = this._data.getUint32(this.offset, this.littleEndian);\r\n this.offset += 4;\r\n return value;\r\n }\r\n /**\r\n * Read a 32-bit floating number and move pointer forward by 4 bytes.\r\n */\r\n readFloat32() {\r\n const value = this._data.getFloat32(this.offset, this.littleEndian);\r\n this.offset += 4;\r\n return value;\r\n }\r\n /**\r\n * Read a 64-bit floating number and move pointer forward by 8 bytes.\r\n */\r\n readFloat64() {\r\n const value = this._data.getFloat64(this.offset, this.littleEndian);\r\n this.offset += 8;\r\n return value;\r\n }\r\n /**\r\n * Read a 1-byte ASCII character and move pointer forward by 1 byte.\r\n */\r\n readChar() {\r\n return String.fromCharCode(this.readInt8());\r\n }\r\n /**\r\n * Read `n` 1-byte ASCII characters and move pointer forward by `n` bytes.\r\n */\r\n readChars(n = 1) {\r\n let result = '';\r\n for (let i = 0; i < n; i++) {\r\n result += this.readChar();\r\n }\r\n return result;\r\n }\r\n /**\r\n * Read the next `n` bytes, return a UTF-8 decoded string and move pointer\r\n * forward by `n` bytes.\r\n */\r\n readUtf8(n = 1) {\r\n return decode(this.readBytes(n));\r\n }\r\n /**\r\n * Write 0xff if the passed value is truthy, 0x00 otherwise and move pointer\r\n * forward by 1 byte.\r\n */\r\n writeBoolean(value) {\r\n this.writeUint8(value ? 0xff : 0x00);\r\n return this;\r\n }\r\n /**\r\n * Write `value` as an 8-bit signed integer and move pointer forward by 1 byte.\r\n */\r\n writeInt8(value) {\r\n this.ensureAvailable(1);\r\n this._data.setInt8(this.offset++, value);\r\n this._updateLastWrittenByte();\r\n return this;\r\n }\r\n /**\r\n * Write `value` as an 8-bit unsigned integer and move pointer forward by 1\r\n * byte.\r\n */\r\n writeUint8(value) {\r\n this.ensureAvailable(1);\r\n this._data.setUint8(this.offset++, value);\r\n this._updateLastWrittenByte();\r\n return this;\r\n }\r\n /**\r\n * An alias for {@link IOBuffer#writeUint8}.\r\n */\r\n writeByte(value) {\r\n return this.writeUint8(value);\r\n }\r\n /**\r\n * Write all elements of `bytes` as uint8 values and move pointer forward by\r\n * `bytes.length` bytes.\r\n */\r\n writeBytes(bytes) {\r\n this.ensureAvailable(bytes.length);\r\n for (let i = 0; i < bytes.length; i++) {\r\n this._data.setUint8(this.offset++, bytes[i]);\r\n }\r\n this._updateLastWrittenByte();\r\n return this;\r\n }\r\n /**\r\n * Write `value` as a 16-bit signed integer and move pointer forward by 2\r\n * bytes.\r\n */\r\n writeInt16(value) {\r\n this.ensureAvailable(2);\r\n this._data.setInt16(this.offset, value, this.littleEndian);\r\n this.offset += 2;\r\n this._updateLastWrittenByte();\r\n return this;\r\n }\r\n /**\r\n * Write `value` as a 16-bit unsigned integer and move pointer forward by 2\r\n * bytes.\r\n */\r\n writeUint16(value) {\r\n this.ensureAvailable(2);\r\n this._data.setUint16(this.offset, value, this.littleEndian);\r\n this.offset += 2;\r\n this._updateLastWrittenByte();\r\n return this;\r\n }\r\n /**\r\n * Write `value` as a 32-bit signed integer and move pointer forward by 4\r\n * bytes.\r\n */\r\n writeInt32(value) {\r\n this.ensureAvailable(4);\r\n this._data.setInt32(this.offset, value, this.littleEndian);\r\n this.offset += 4;\r\n this._updateLastWrittenByte();\r\n return this;\r\n }\r\n /**\r\n * Write `value` as a 32-bit unsigned integer and move pointer forward by 4\r\n * bytes.\r\n */\r\n writeUint32(value) {\r\n this.ensureAvailable(4);\r\n this._data.setUint32(this.offset, value, this.littleEndian);\r\n this.offset += 4;\r\n this._updateLastWrittenByte();\r\n return this;\r\n }\r\n /**\r\n * Write `value` as a 32-bit floating number and move pointer forward by 4\r\n * bytes.\r\n */\r\n writeFloat32(value) {\r\n this.ensureAvailable(4);\r\n this._data.setFloat32(this.offset, value, this.littleEndian);\r\n this.offset += 4;\r\n this._updateLastWrittenByte();\r\n return this;\r\n }\r\n /**\r\n * Write `value` as a 64-bit floating number and move pointer forward by 8\r\n * bytes.\r\n */\r\n writeFloat64(value) {\r\n this.ensureAvailable(8);\r\n this._data.setFloat64(this.offset, value, this.littleEndian);\r\n this.offset += 8;\r\n this._updateLastWrittenByte();\r\n return this;\r\n }\r\n /**\r\n * Write the charCode of `str`'s first character as an 8-bit unsigned integer\r\n * and move pointer forward by 1 byte.\r\n */\r\n writeChar(str) {\r\n return this.writeUint8(str.charCodeAt(0));\r\n }\r\n /**\r\n * Write the charCodes of all `str`'s characters as 8-bit unsigned integers\r\n * and move pointer forward by `str.length` bytes.\r\n */\r\n writeChars(str) {\r\n for (let i = 0; i < str.length; i++) {\r\n this.writeUint8(str.charCodeAt(i));\r\n }\r\n return this;\r\n }\r\n /**\r\n * UTF-8 encode and write `str` to the current pointer offset and move pointer\r\n * forward according to the encoded length.\r\n */\r\n writeUtf8(str) {\r\n return this.writeBytes(encode(str));\r\n }\r\n /**\r\n * Export a Uint8Array view of the internal buffer.\r\n * The view starts at the byte offset and its length\r\n * is calculated to stop at the last written byte or the original length.\r\n */\r\n toArray() {\r\n return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte);\r\n }\r\n /**\r\n * Update the last written byte offset\r\n * @private\r\n */\r\n _updateLastWrittenByte() {\r\n if (this.offset > this.lastWrittenByte) {\r\n this.lastWrittenByte = this.offset;\r\n }\r\n }\r\n}\r\n//# sourceMappingURL=IOBuffer.js.map","import { IOBuffer } from 'iobuffer';\n\n/**\n * Parse the FCS data contained in the file.\n * @param {buffer} file - File with the FCS data.\n * @return {Object} [Object.text] Metadata of the experiment.\n * @return {Array} [Object.parameters] Data of the parameters.\n * @return {Array} [Object.data] Data of each event.\n */\n\nexport function parseFCS(file, options = {}) {\n let { delimiter = undefined } = options;\n\n const buffer = new IOBuffer(file);\n const {\n model,\n textBegin,\n textEnd,\n dataBegin,\n dataEnd,\n analysisBegin,\n analysisEnd,\n } = getHeader(buffer);\n\n delimiter = delimiter === undefined ? getDelimiter(buffer) : delimiter;\n const textFile = buffer.readChars(textEnd - textBegin).split(delimiter);\n const textLack = buffer.offset - textEnd;\n let textSegment = {\n model: model,\n textBegin: textBegin,\n textEnd: textEnd,\n dataBegin: dataBegin,\n dataEnd: dataEnd,\n analysisBegin: analysisBegin,\n analysisEnd: analysisEnd,\n };\n\n for (let i = 0; i < textFile.length / 2 - 1; i++) {\n textSegment[textFile[i * 2]] = textFile[i * 2 + 1];\n }\n\n textSegment.dataBegin = Number.isNaN(dataBegin)\n ? parseInt(textSegment.$BEGINDATA, 10)\n : dataBegin;\n\n textSegment.dataEnd = Number.isNaN(dataEnd)\n ? parseInt(textSegment.$ENDDATA, 10)\n : dataEnd;\n\n const endianness = textSegment.$BYTEORD;\n\n if (endianness === '1,2,3,4') {\n buffer.setLittleEndian();\n } else if (endianness === '4,3,2,1') {\n buffer.setBigEndian();\n } else {\n throw new RangeError(`Unrecognized ${endianness} endianness`);\n }\n\n const numberOfEvents = parseInt(textSegment.$TOT, 10);\n const parametersByEvent = parseInt(textSegment.$PAR, 10);\n\n buffer.skip(dataBegin - textEnd - textLack);\n let dataSegment = [];\n const dataType = textSegment.$DATATYPE;\n if (dataType === 'I') {\n for (let i = 0; i < numberOfEvents; i++) {\n let event = new Float64Array(parametersByEvent);\n for (let j = 0; j < parametersByEvent; j++) {\n event[j] = buffer.readUint16();\n }\n dataSegment[i] = event;\n }\n } else if (dataType === 'F') {\n for (let i = 0; i < numberOfEvents; i++) {\n let event = new Float64Array(parametersByEvent);\n for (let j = 0; j < parametersByEvent; j++) {\n event[j] = buffer.readFloat32();\n }\n dataSegment[i] = event;\n }\n } else if (dataType === 'D') {\n for (let i = 0; i < numberOfEvents; i++) {\n let event = new Float64Array(parametersByEvent);\n for (let j = 0; j < parametersByEvent; j++) {\n event[j] = buffer.readFloat64();\n }\n dataSegment[i] = event;\n }\n } else {\n throw new RangeError(`Not supported $DATATYPE ${dataType}`);\n }\n\n return {\n data: dataSegment,\n text: textSegment,\n parameters: getParameters(textSegment),\n };\n}\n\nfunction getHeader(buffer) {\n const model = buffer.readChars(6);\n const textBegin = parseInt(buffer.readChars(12), 10);\n const textEnd = parseInt(buffer.readChars(8), 10);\n const dataBegin = parseInt(buffer.readChars(8), 10);\n const dataEnd = parseInt(buffer.readChars(8), 10);\n const analysisBegin = parseInt(buffer.readChars(8), 10);\n const analysisEnd = parseInt(buffer.readChars(8), 10);\n\n return {\n model,\n textBegin,\n textEnd,\n dataBegin,\n dataEnd,\n analysisBegin,\n analysisEnd,\n };\n}\n\nfunction getParameters(metadata) {\n const entries = Object.entries(metadata);\n const keys = entries.filter(\n (item) => (item[0][1] === 'P') & !Number.isNaN(parseInt(item[0][2], 10)),\n );\n const regex = /[a-zA-Z]+|[0-9]+(?:\\.[0-9]+|)/g;\n const parametersData = Math.max(\n ...keys.map((item) => item[0].match(regex)[1]),\n );\n let parameters = [];\n for (let i = 1; i < parametersData + 1; i++) {\n const chanelKeys = keys.filter(\n (item) => parseInt(item[0].match(regex)[1], 10) === i,\n );\n let parameter = {};\n for (let j = 0; j < chanelKeys.length; j++) {\n parameter[chanelKeys[j][0]] = chanelKeys[j][1];\n }\n parameters.push(parameter);\n }\n return parameters;\n}\n\nfunction getDelimiter(buffer) {\n let delimiter = buffer.readChar().split(' ');\n while (delimiter[1] !== undefined) {\n delimiter = buffer.readChar().split(' ');\n }\n return delimiter;\n}\n"],"names":["scope","FastTextEncoder","utfLabel","RangeError","FastTextDecoder","options","fatal","Error","Object","defineProperty","prototype","value","encode","string","stream","pos","len","length","at","tlen","Math","max","target","Uint8Array","charCodeAt","extra","update","set","slice","decode","buffer","bytes","out","byte1","push","byte2","byte3","codepoint","String","fromCharCode","apply","window","self","this","decoder","TextDecoder","encoder","TextEncoder","IOBuffer","[object Object]","data","dataIsGiven","ArrayBuffer","lastWrittenByte","byteLength","offset","dvOffset","isView","byteOffset","littleEndian","_data","DataView","_mark","_marks","n","pop","undefined","seek","available","newLength","newArray","readUint8","getInt8","getUint8","i","readByte","getInt16","getUint16","getInt32","getUint32","getFloat32","getFloat64","readInt8","result","readChar","readBytes","writeUint8","ensureAvailable","setInt8","_updateLastWrittenByte","setUint8","setInt16","setUint16","setInt32","setUint32","setFloat32","setFloat64","str","writeBytes","getParameters","metadata","keys","entries","filter","item","Number","isNaN","parseInt","regex","parametersData","map","match","parameters","chanelKeys","parameter","j","file","delimiter","model","textBegin","textEnd","dataBegin","dataEnd","analysisBegin","analysisEnd","readChars","getHeader","split","getDelimiter","textFile","textLack","textSegment","$BEGINDATA","$ENDDATA","endianness","$BYTEORD","setLittleEndian","setBigEndian","numberOfEvents","$TOT","parametersByEvent","$PAR","skip","dataSegment","dataType","$DATATYPE","event","Float64Array","readUint16","readFloat32","readFloat64","text"],"mappings":"kPAgBA,SAAUA,MAIJA,EAAK,aAAmBA,EAAK,mBACxB,WAOAC,EAAgBC,EAAW,YACjB,UAAbA,QACI,IAAIC,WACR,oEAAoED,4BAyFjEE,EAAgBF,EAAW,QAASG,EAAU,CAAEC,OAAO,OAC7C,UAAbJ,QACI,IAAIC,WACR,oEAAoED,sBAGpEG,EAAQC,YACJ,IAAIC,MACR,yEA5FNC,OAAOC,eAAeR,EAAgBS,UAAW,WAAY,CAC3DC,MAAO,UAQTV,EAAgBS,UAAUE,OAAS,SACjCC,EACAR,EAAU,CAAES,QAAQ,OAEhBT,EAAQS,aACJ,IAAIP,MAAM,6DAGdQ,EAAM,QACJC,EAAMH,EAAOI,WAGfC,EAAK,EACLC,EAAOC,KAAKC,IAAI,GAAIL,GAAOA,GAAO,GAAK,GACvCM,EAAS,IAAIC,WAAYJ,GAAQ,GAAM,QAEpCJ,EAAMC,GAAK,KACZL,EAAQE,EAAOW,WAAWT,QAC1BJ,GAAS,OAAUA,GAAS,MAAQ,IAElCI,E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