{"version":3,"file":"well-plate.min.js","sources":["../lib-es6/utils.js","../lib-es6/index.js"],"sourcesContent":["export function getRange(start, size) {\n    const result = [];\n    for (let i = 0; i < size; i++) {\n        result[i] = start + i;\n    }\n    return result;\n}\n","import { getRange } from './utils';\n/**\n * The format of a well position.\n */\nexport var PositionFormat;\n(function (PositionFormat) {\n    /**\n     * Sequential. When this format is used, the position code will starts with 1 and will be incremented columns first.\n     */\n    PositionFormat[PositionFormat[\"Sequential\"] = 0] = \"Sequential\";\n    /**\n     * A letter + a number. When this format is used, the position will be represented\n     * as a string with one letter + one number, representing the row and column position. For example B3 is for second row, 3rd column.\n     */\n    PositionFormat[PositionFormat[\"LetterNumber\"] = 1] = \"LetterNumber\";\n})(PositionFormat || (PositionFormat = {}));\n/**\n * WellPlate - class representing a well plate\n */\nexport class WellPlate {\n    constructor(arg1, columns) {\n        if (typeof arg1 === 'string') {\n            const reg = /^(\\d+)x(\\d+)$/;\n            const m = reg.exec(arg1);\n            if (m === null) {\n                throw new Error('invalid well plate type, type must be formatted as <number>x<number>');\n            }\n            this.rows = +m[1];\n            this.columns = +m[2];\n        }\n        else {\n            this.rows = arg1;\n            this.columns = columns || 0;\n        }\n        this.size = this.rows * this.columns;\n        if (this.columns === 9 && this.rows === 9) {\n            this.positionFormat = PositionFormat.Sequential;\n        }\n        else {\n            this.positionFormat = PositionFormat.LetterNumber;\n        }\n    }\n    /**\n     * Get the code for a specific position on the well.\n     *\n     * Some wells will return a code compose of a letter and a number\n     * Other will will simply return the position\n     * @param arg1 - The index position of the well, starting with 0, or the position of the well, see [[Position]]\n     * @returns The code of the well position. The format depends on the PositionFormat, see [[wellCodeFormat]]\n     */\n    getPositionCode(arg1) {\n        if (typeof arg1 === 'number') {\n            this._checkIndex(arg1);\n            if (this.positionFormat === PositionFormat.Sequential) {\n                return String(arg1 + 1);\n            }\n            else {\n                const position = this._getPositionFromIndex(arg1);\n                return this._letterNumberCodeFromPosition(position);\n            }\n        }\n        else {\n            this._checkPosition(arg1);\n            if (this.positionFormat === PositionFormat.Sequential) {\n                return this._sequentialCodeFromPosition(arg1);\n            }\n            else {\n                return this._letterNumberCodeFromPosition(arg1);\n            }\n        }\n    }\n    /**\n     * Get a range of well position codes\n     * @param startIndex The index where the range starts\n     * @param size The number of sequential positions to include in the range.\n     */\n    getPositionCodeRange(start, size) {\n        const startIndex = typeof start === 'number' ? start : this._getIndexFromCode(start);\n        const endIndex = startIndex + size - 1;\n        this._checkIndex(startIndex);\n        this._checkIndex(endIndex);\n        return getRange(startIndex, size).map(this.getPositionCode.bind(this));\n    }\n    getIndex(position) {\n        if (typeof position === 'string') {\n            return this.getIndex(this.getPosition(position));\n        }\n        return position.row * this.columns + position.column;\n    }\n    /**\n     * Get the well position given a formatted well position code.\n     * @param wellCode The position code.\n     */\n    getPosition(wellCode) {\n        const reg = /^([A-Z])(\\d+)$/;\n        const m = reg.exec(wellCode);\n        if (m === null) {\n            if (this.positionFormat !== PositionFormat.Sequential) {\n                this._formatError();\n            }\n            const wellIndex = +wellCode - 1;\n            if (Number.isNaN(wellIndex)) {\n                this._formatError();\n            }\n            this._checkIndex(wellIndex);\n            return this._getPositionFromIndex(wellIndex);\n        }\n        if (this.positionFormat !== PositionFormat.LetterNumber) {\n            this._formatError();\n        }\n        const position = {\n            row: m[1].charCodeAt(0) - 'A'.charCodeAt(0),\n            column: +m[2] - 1\n        };\n        this._checkPosition(position);\n        return position;\n    }\n    _getPositionFromIndex(index) {\n        return {\n            row: Math.floor(index / this.columns),\n            column: index % this.columns\n        };\n    }\n    _getIndexFromCode(wellCode) {\n        return this.getIndex(this.getPosition(wellCode));\n    }\n    _formatError() {\n        switch (this.positionFormat) {\n            case PositionFormat.LetterNumber: {\n                throw new Error('invalid well code format. Must be a letter followed by a number');\n            }\n            case PositionFormat.Sequential: {\n                throw new Error('invalid well code format. Must be a number');\n            }\n        }\n    }\n    _checkIndex(index) {\n        if (index < 0 || index >= this.size) {\n            throw new RangeError('well index is out of range');\n        }\n    }\n    _checkPosition(position) {\n        if (position.row < 0 ||\n            position.row >= this.rows ||\n            position.column < 0 ||\n            position.column >= this.columns) {\n            throw new RangeError('well position is out of range');\n        }\n    }\n    _sequentialCodeFromPosition(position) {\n        return String(position.row * this.rows + position.column + 1);\n    }\n    _letterNumberCodeFromPosition(position) {\n        const startCharCode = 'A'.charCodeAt(0);\n        const letter = String.fromCharCode(startCharCode + position.row);\n        return letter + (position.column + 1);\n    }\n}\n"],"names":["getRange","start","size","result","i","PositionFormat","constructor","arg1","columns","reg","m","exec","Error","rows","positionFormat","Sequential","LetterNumber","getPositionCode","_checkPosition","_sequentialCodeFromPosition","_letterNumberCodeFromPosition","_checkIndex","position","_getPositionFromIndex","getPositionCodeRange","startIndex","_getIndexFromCode","map","bind","getIndex","getPosition","row","column","wellCode","_formatError","wellIndex","Number","isNaN","charCodeAt","index","Math","floor","RangeError","letter","String","fromCharCode","startCharCode"],"mappings":"6LAAO,QAASA,CAAAA,CAAT,CAAkBC,CAAlB,CAAyBC,CAAzB,CAA+B,MAC5BC,CAAAA,CAAM,CAAG,OACV,GAAIC,CAAAA,CAAC,CAAG,EAAGA,CAAC,CAAGF,EAAME,CAAC,GACvBD,CAAM,CAACC,CAAD,CAAND,CAAYF,CAAK,CAAGG,CAApBD,OAEGA,CAAAA,GCAV,SAAUE,CAAV,CAA0B,CAIvBA,CAAc,CAACA,CAAc,WAAdA,CAA+B,CAAhC,CAAdA,CAAmD,YAJ5B,CASvBA,CAAc,CAACA,CAAc,aAAdA,CAAiC,CAAlC,CAAdA,CAAqD,cATzD,GAUGA,gBAAAA,GAAmBA,gBAAAA,CAAiB,EAApCA,eAII,KAAgB,CACnBC,WAAW,CAACC,CAAD,CAAOC,CAAP,CAAgB,IACH,QAAhB,QAAOD,CAAAA,EAAmB,MACpBE,CAAAA,CAAG,CAAG,eADc,CAEpBC,CAAC,CAAGD,CAAG,CAACE,IAAJF,CAASF,CAATE,CAFgB,IAGhB,IAANC,GAAAA,OACM,IAAIE,CA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