jcampconverter
Advanced tools
Comparing version 3.0.4 to 4.0.0
{ | ||
"name": "jcampconverter", | ||
"version": "3.0.4", | ||
"version": "4.0.0", | ||
"description": "Parse and convert JCAMP data", | ||
@@ -40,8 +40,10 @@ "main": "./src/index.js", | ||
"cheminfo-tools": "^1.23.3", | ||
"eslint": "^5.16.0", | ||
"eslint-config-cheminfo": "^1.20.1", | ||
"eslint-plugin-import": "^2.18.0", | ||
"eslint-plugin-jest": "^22.7.1", | ||
"jest": "^24.8.0" | ||
"eslint": "^6.6.0", | ||
"eslint-config-cheminfo": "^2.0.4", | ||
"eslint-plugin-import": "^2.18.2", | ||
"eslint-plugin-jest": "^23.0.4", | ||
"eslint-plugin-prettier": "^3.1.1", | ||
"jest": "^24.9.0", | ||
"prettier": "^1.19.1" | ||
} | ||
} |
@@ -40,3 +40,5 @@ # JCAMP converter | ||
* chromatogram - use the new GC/MS data format output (default: false) | ||
* canonicDataLabels - canonize data labels (uppercase) (default: true). | ||
2D NMR options: | ||
@@ -43,0 +45,0 @@ * noContour - if true, the contour levels will not be generated. Instead the raw data will be available in `result.minMax.z` (default: false) |
396
src/index.js
@@ -9,3 +9,3 @@ 'use strict'; | ||
function convertToFloatArray(stringArray) { | ||
var floatArray = []; | ||
let floatArray = []; | ||
for (let i = 0; i < stringArray.length; i++) { | ||
@@ -21,2 +21,3 @@ floatArray.push(parseFloat(stringArray[i])); | ||
keepRecordsRegExp: /^$/, | ||
canonicDataLabels: true, | ||
xy: false, | ||
@@ -29,3 +30,3 @@ withoutXY: false, | ||
noiseMultiplier: 5, | ||
profiling: false | ||
profiling: false, | ||
}; | ||
@@ -36,17 +37,17 @@ | ||
var wantXY = !options.withoutXY; | ||
let wantXY = !options.withoutXY; | ||
var start = Date.now(); | ||
let start = Date.now(); | ||
var ntuples = {}; | ||
var ldr, dataLabel, dataValue, ldrs; | ||
var position, endLine, infos; | ||
let ntuples = {}; | ||
let ldr, dataValue, ldrs; | ||
let position, endLine, infos; | ||
var result = {}; | ||
let result = {}; | ||
result.profiling = options.profiling ? [] : false; | ||
result.logs = []; | ||
var spectra = []; | ||
let spectra = []; | ||
result.spectra = spectra; | ||
result.info = {}; | ||
var spectrum = new Spectrum(); | ||
let spectrum = new Spectrum(); | ||
@@ -60,3 +61,3 @@ if (!(typeof jcamp === 'string')) { | ||
action: 'Before split to LDRS', | ||
time: Date.now() - start | ||
time: Date.now() - start, | ||
}); | ||
@@ -70,3 +71,3 @@ } | ||
action: 'Split to LDRS', | ||
time: Date.now() - start | ||
time: Date.now() - start, | ||
}); | ||
@@ -78,2 +79,3 @@ } | ||
for (let i = 0; i < ldrs.length; i++) { | ||
let dataLabel; | ||
ldr = ldrs[i]; | ||
@@ -89,10 +91,10 @@ // This is a new LDR | ||
} | ||
dataLabel = dataLabel.replace(/[_ -]/g, '').toUpperCase(); | ||
let canonicDataLabel = dataLabel.replace(/[_ -]/g, '').toUpperCase(); | ||
if (dataLabel === 'DATATABLE') { | ||
if (canonicDataLabel === 'DATATABLE') { | ||
endLine = dataValue.indexOf('\n'); | ||
if (endLine === -1) endLine = dataValue.indexOf('\r'); | ||
if (endLine > 0) { | ||
var xIndex = -1; | ||
var yIndex = -1; | ||
let xIndex = -1; | ||
let yIndex = -1; | ||
// ##DATA TABLE= (X++(I..I)), XYDATA | ||
@@ -103,9 +105,9 @@ // We need to find the variables | ||
if (infos[0].indexOf('++') > 0) { | ||
var firstVariable = infos[0].replace( | ||
let firstVariable = infos[0].replace( | ||
/.*\(([a-zA-Z0-9]+)\+\+.*/, | ||
'$1' | ||
'$1', | ||
); | ||
var secondVariable = infos[0].replace( | ||
let secondVariable = infos[0].replace( | ||
/.*\.\.([a-zA-Z0-9]+).*/, | ||
'$1' | ||
'$1', | ||
); | ||
@@ -156,3 +158,3 @@ xIndex = ntuples.symbol.indexOf(firstVariable); | ||
if (infos[1] && infos[1].indexOf('PEAKS') > -1) { | ||
dataLabel = 'PEAKTABLE'; | ||
canonicDataLabel = 'PEAKTABLE'; | ||
} else if ( | ||
@@ -162,3 +164,3 @@ infos[1] && | ||
) { | ||
dataLabel = 'XYDATA'; | ||
canonicDataLabel = 'XYDATA'; | ||
spectrum.deltaX = | ||
@@ -170,3 +172,3 @@ (spectrum.lastX - spectrum.firstX) / (spectrum.nbPoints - 1); | ||
if (dataLabel === 'XYDATA') { | ||
if (canonicDataLabel === 'XYDATA') { | ||
if (wantXY) { | ||
@@ -189,3 +191,3 @@ prepareSpectrum(result, spectrum); | ||
continue; | ||
} else if (dataLabel === 'PEAKTABLE') { | ||
} else if (canonicDataLabel === 'PEAKTABLE') { | ||
if (wantXY) { | ||
@@ -199,3 +201,3 @@ prepareSpectrum(result, spectrum); | ||
} | ||
if (dataLabel === 'PEAKASSIGNMENTS') { | ||
if (canonicDataLabel === 'PEAKASSIGNMENTS') { | ||
if (wantXY) { | ||
@@ -212,5 +214,5 @@ if (dataValue.match(/.*(XYA).*/)) { | ||
if (dataLabel === 'TITLE') { | ||
if (canonicDataLabel === 'TITLE') { | ||
spectrum.title = dataValue; | ||
} else if (dataLabel === 'DATATYPE') { | ||
} else if (canonicDataLabel === 'DATATYPE') { | ||
spectrum.dataType = dataValue; | ||
@@ -220,47 +222,50 @@ if (dataValue.indexOf('nD') > -1) { | ||
} | ||
} else if (dataLabel === 'NTUPLES') { | ||
} else if (canonicDataLabel === 'NTUPLES') { | ||
if (dataValue.indexOf('nD') > -1) { | ||
result.twoD = true; | ||
} | ||
} else if (dataLabel === 'XUNITS') { | ||
} else if (canonicDataLabel === 'XUNITS') { | ||
spectrum.xUnit = dataValue; | ||
} else if (dataLabel === 'YUNITS') { | ||
} else if (canonicDataLabel === 'YUNITS') { | ||
spectrum.yUnit = dataValue; | ||
} else if (dataLabel === 'FIRSTX') { | ||
} else if (canonicDataLabel === 'FIRSTX') { | ||
spectrum.firstX = parseFloat(dataValue); | ||
} else if (dataLabel === 'LASTX') { | ||
} else if (canonicDataLabel === 'LASTX') { | ||
spectrum.lastX = parseFloat(dataValue); | ||
} else if (dataLabel === 'FIRSTY') { | ||
} else if (canonicDataLabel === 'FIRSTY') { | ||
spectrum.firstY = parseFloat(dataValue); | ||
} else if (dataLabel === 'LASTY') { | ||
} else if (canonicDataLabel === 'LASTY') { | ||
spectrum.lastY = parseFloat(dataValue); | ||
} else if (dataLabel === 'NPOINTS') { | ||
} else if (canonicDataLabel === 'NPOINTS') { | ||
spectrum.nbPoints = parseFloat(dataValue); | ||
} else if (dataLabel === 'XFACTOR') { | ||
} else if (canonicDataLabel === 'XFACTOR') { | ||
spectrum.xFactor = parseFloat(dataValue); | ||
} else if (dataLabel === 'YFACTOR') { | ||
} else if (canonicDataLabel === 'YFACTOR') { | ||
spectrum.yFactor = parseFloat(dataValue); | ||
} else if (dataLabel === 'MAXX') { | ||
} else if (canonicDataLabel === 'MAXX') { | ||
spectrum.maxX = parseFloat(dataValue); | ||
} else if (dataLabel === 'MINX') { | ||
} else if (canonicDataLabel === 'MINX') { | ||
spectrum.minX = parseFloat(dataValue); | ||
} else if (dataLabel === 'MAXY') { | ||
} else if (canonicDataLabel === 'MAXY') { | ||
spectrum.maxY = parseFloat(dataValue); | ||
} else if (dataLabel === 'MINY') { | ||
} else if (canonicDataLabel === 'MINY') { | ||
spectrum.minY = parseFloat(dataValue); | ||
} else if (dataLabel === 'DELTAX') { | ||
} else if (canonicDataLabel === 'DELTAX') { | ||
spectrum.deltaX = parseFloat(dataValue); | ||
} else if (dataLabel === '.OBSERVEFREQUENCY' || dataLabel === '$SFO1') { | ||
} else if ( | ||
canonicDataLabel === '.OBSERVEFREQUENCY' || | ||
canonicDataLabel === '$SFO1' | ||
) { | ||
if (!spectrum.observeFrequency) { | ||
spectrum.observeFrequency = parseFloat(dataValue); | ||
} | ||
} else if (dataLabel === '.OBSERVENUCLEUS') { | ||
} else if (canonicDataLabel === '.OBSERVENUCLEUS') { | ||
if (!spectrum.xType) { | ||
result.xType = dataValue.replace(/[^a-zA-Z0-9]/g, ''); | ||
} | ||
} else if (dataLabel === '$SFO2') { | ||
} else if (canonicDataLabel === '$SFO2') { | ||
if (!result.indirectFrequency) { | ||
result.indirectFrequency = parseFloat(dataValue); | ||
} | ||
} else if (dataLabel === '$OFFSET') { | ||
} else if (canonicDataLabel === '$OFFSET') { | ||
// OFFSET for Bruker spectra | ||
@@ -271,41 +276,41 @@ result.shiftOffsetNum = 0; | ||
} | ||
} else if (dataLabel === '$REFERENCEPOINT') { | ||
} else if (canonicDataLabel === '$REFERENCEPOINT') { | ||
// OFFSET for Varian spectra | ||
// if we activate this part it does not work for ACD specmanager | ||
// } else if (dataLabel=='.SHIFTREFERENCE') { // OFFSET FOR Bruker Spectra | ||
// } else if (canonicDataLabel=='.SHIFTREFERENCE') { // OFFSET FOR Bruker Spectra | ||
// var parts = dataValue.split(/ *, */); | ||
// result.shiftOffsetNum = parseInt(parts[2].trim()); | ||
// spectrum.shiftOffsetVal = parseFloat(parts[3].trim()); | ||
} else if (dataLabel === 'VARNAME') { | ||
} else if (canonicDataLabel === 'VARNAME') { | ||
ntuples.varname = dataValue.split(ntuplesSeparator); | ||
} else if (dataLabel === 'SYMBOL') { | ||
} else if (canonicDataLabel === 'SYMBOL') { | ||
ntuples.symbol = dataValue.split(ntuplesSeparator); | ||
} else if (dataLabel === 'VARTYPE') { | ||
} else if (canonicDataLabel === 'VARTYPE') { | ||
ntuples.vartype = dataValue.split(ntuplesSeparator); | ||
} else if (dataLabel === 'VARFORM') { | ||
} else if (canonicDataLabel === 'VARFORM') { | ||
ntuples.varform = dataValue.split(ntuplesSeparator); | ||
} else if (dataLabel === 'VARDIM') { | ||
} else if (canonicDataLabel === 'VARDIM') { | ||
ntuples.vardim = convertToFloatArray(dataValue.split(ntuplesSeparator)); | ||
} else if (dataLabel === 'UNITS') { | ||
} else if (canonicDataLabel === 'UNITS') { | ||
ntuples.units = dataValue.split(ntuplesSeparator); | ||
} else if (dataLabel === 'FACTOR') { | ||
} else if (canonicDataLabel === 'FACTOR') { | ||
ntuples.factor = convertToFloatArray(dataValue.split(ntuplesSeparator)); | ||
} else if (dataLabel === 'FIRST') { | ||
} else if (canonicDataLabel === 'FIRST') { | ||
ntuples.first = convertToFloatArray(dataValue.split(ntuplesSeparator)); | ||
} else if (dataLabel === 'LAST') { | ||
} else if (canonicDataLabel === 'LAST') { | ||
ntuples.last = convertToFloatArray(dataValue.split(ntuplesSeparator)); | ||
} else if (dataLabel === 'MIN') { | ||
} else if (canonicDataLabel === 'MIN') { | ||
ntuples.min = convertToFloatArray(dataValue.split(ntuplesSeparator)); | ||
} else if (dataLabel === 'MAX') { | ||
} else if (canonicDataLabel === 'MAX') { | ||
ntuples.max = convertToFloatArray(dataValue.split(ntuplesSeparator)); | ||
} else if (dataLabel === '.NUCLEUS') { | ||
} else if (canonicDataLabel === '.NUCLEUS') { | ||
if (result.twoD) { | ||
result.yType = dataValue.split(ntuplesSeparator)[0]; | ||
} | ||
} else if (dataLabel === 'PAGE') { | ||
} else if (canonicDataLabel === 'PAGE') { | ||
spectrum.page = dataValue.trim(); | ||
spectrum.pageValue = parseFloat(dataValue.replace(/^.*=/, '')); | ||
spectrum.pageSymbol = spectrum.page.replace(/[=].*/, ''); | ||
var pageSymbolIndex = ntuples.symbol.indexOf(spectrum.pageSymbol); | ||
var unit = ''; | ||
let pageSymbolIndex = ntuples.symbol.indexOf(spectrum.pageSymbol); | ||
let unit = ''; | ||
if (ntuples.units && ntuples.units[pageSymbolIndex]) { | ||
@@ -317,17 +322,18 @@ unit = ntuples.units[pageSymbolIndex]; | ||
} | ||
} else if (dataLabel === 'RETENTIONTIME') { | ||
} else if (canonicDataLabel === 'RETENTIONTIME') { | ||
spectrum.pageValue = parseFloat(dataValue); | ||
} else if (isMSField(dataLabel)) { | ||
spectrum[convertMSFieldToLabel(dataLabel)] = dataValue; | ||
} else if (dataLabel === 'SAMPLEDESCRIPTION') { | ||
} else if (isMSField(canonicDataLabel)) { | ||
spectrum[convertMSFieldToLabel(canonicDataLabel)] = dataValue; | ||
} else if (canonicDataLabel === 'SAMPLEDESCRIPTION') { | ||
spectrum.sampleDescription = dataValue; | ||
} | ||
if (dataLabel.match(options.keepRecordsRegExp)) { | ||
if (result.info[dataLabel]) { | ||
if (!Array.isArray(result.info[dataLabel])) { | ||
result.info[dataLabel] = [result.info[dataLabel]]; | ||
if (canonicDataLabel.match(options.keepRecordsRegExp)) { | ||
let label = options.canonicDataLabels ? canonicDataLabel : dataLabel; | ||
if (result.info[label]) { | ||
if (!Array.isArray(result.info[label])) { | ||
result.info[label] = [result.info[label]]; | ||
} | ||
result.info[dataLabel].push(dataValue.trim()); | ||
result.info[label].push(dataValue.trim()); | ||
} else { | ||
result.info[dataLabel] = dataValue.trim(); | ||
result.info[label] = dataValue.trim(); | ||
} | ||
@@ -340,3 +346,3 @@ } | ||
action: 'Finished parsing', | ||
time: Date.now() - start | ||
time: Date.now() - start, | ||
}); | ||
@@ -346,7 +352,7 @@ } | ||
if (Object.keys(ntuples).length > 0) { | ||
var newNtuples = []; | ||
var keys = Object.keys(ntuples); | ||
let newNtuples = []; | ||
let keys = Object.keys(ntuples); | ||
for (let i = 0; i < keys.length; i++) { | ||
var key = keys[i]; | ||
var values = ntuples[key]; | ||
let key = keys[i]; | ||
let values = ntuples[key]; | ||
for (let j = 0; j < values.length; j++) { | ||
@@ -365,3 +371,3 @@ if (!newNtuples[j]) newNtuples[j] = {}; | ||
action: 'Finished countour plot calculation', | ||
time: Date.now() - start | ||
time: Date.now() - start, | ||
}); | ||
@@ -385,8 +391,8 @@ } | ||
for (let j = 0; j < spectrum.data.length; j++) { | ||
var data = spectrum.data[j]; | ||
var newData = { | ||
let data = spectrum.data[j]; | ||
let newData = { | ||
x: new Array(data.length / 2), | ||
y: new Array(data.length / 2) | ||
y: new Array(data.length / 2), | ||
}; | ||
for (var k = 0; k < data.length; k = k + 2) { | ||
for (let k = 0; k < data.length; k = k + 2) { | ||
newData.x[k / 2] = data[k]; | ||
@@ -412,3 +418,3 @@ newData.y[k / 2] = data[k + 1]; | ||
action: 'Finished chromatogram calculation', | ||
time: Date.now() - start | ||
time: Date.now() - start, | ||
}); | ||
@@ -421,3 +427,3 @@ } | ||
action: 'Total time', | ||
time: Date.now() - start | ||
time: Date.now() - start, | ||
}); | ||
@@ -433,10 +439,10 @@ } | ||
function isMSField(dataLabel) { | ||
return GC_MS_FIELDS.indexOf(dataLabel) !== -1; | ||
function isMSField(canonicDataLabel) { | ||
return GC_MS_FIELDS.indexOf(canonicDataLabel) !== -1; | ||
} | ||
function complexChromatogram(result) { | ||
var spectra = result.spectra; | ||
var length = spectra.length; | ||
var chromatogram = { | ||
let spectra = result.spectra; | ||
let length = spectra.length; | ||
let chromatogram = { | ||
times: new Array(length), | ||
@@ -446,10 +452,10 @@ series: { | ||
dimension: 2, | ||
data: new Array(length) | ||
} | ||
} | ||
data: new Array(length), | ||
}, | ||
}, | ||
}; | ||
var existingGCMSFields = []; | ||
let existingGCMSFields = []; | ||
for (let i = 0; i < GC_MS_FIELDS.length; i++) { | ||
var label = convertMSFieldToLabel(GC_MS_FIELDS[i]); | ||
let label = convertMSFieldToLabel(GC_MS_FIELDS[i]); | ||
if (spectra[0][label]) { | ||
@@ -459,3 +465,3 @@ existingGCMSFields.push(label); | ||
dimension: 1, | ||
data: new Array(length) | ||
data: new Array(length), | ||
}; | ||
@@ -466,7 +472,7 @@ } | ||
for (let i = 0; i < length; i++) { | ||
var spectrum = spectra[i]; | ||
let spectrum = spectra[i]; | ||
chromatogram.times[i] = spectrum.pageValue; | ||
for (let j = 0; j < existingGCMSFields.length; j++) { | ||
chromatogram.series[existingGCMSFields[j]].data[i] = parseFloat( | ||
spectrum[existingGCMSFields[j]] | ||
spectrum[existingGCMSFields[j]], | ||
); | ||
@@ -477,3 +483,3 @@ } | ||
spectrum.data[0].x, | ||
spectrum.data[0].y | ||
spectrum.data[0].y, | ||
]; | ||
@@ -486,3 +492,3 @@ } | ||
function simpleChromatogram(result) { | ||
var data = result.spectra[0].data[0]; | ||
let data = result.spectra[0].data[0]; | ||
result.chromatogram = { | ||
@@ -493,5 +499,5 @@ times: data.x.slice(), | ||
dimension: 1, | ||
data: data.y.slice() | ||
} | ||
} | ||
data: data.y.slice(), | ||
}, | ||
}, | ||
}; | ||
@@ -513,3 +519,3 @@ } | ||
if (spectrum.shiftOffsetVal) { | ||
var shift = spectrum.firstX - spectrum.shiftOffsetVal; | ||
let shift = spectrum.firstX - spectrum.shiftOffsetVal; | ||
spectrum.firstX = spectrum.firstX - shift; | ||
@@ -522,3 +528,3 @@ spectrum.lastX = spectrum.lastX - shift; | ||
data = data.sort(compareNumbers); | ||
var l = data.length; | ||
let l = data.length; | ||
return data[Math.floor(l / 2)]; | ||
@@ -532,12 +538,12 @@ } | ||
function convertTo3DZ(spectra) { | ||
var minZ = spectra[0].data[0][0]; | ||
var maxZ = minZ; | ||
var ySize = spectra.length; | ||
var xSize = spectra[0].data[0].length / 2; | ||
var z = new Array(ySize); | ||
let minZ = spectra[0].data[0][0]; | ||
let maxZ = minZ; | ||
let ySize = spectra.length; | ||
let xSize = spectra[0].data[0].length / 2; | ||
let z = new Array(ySize); | ||
for (let i = 0; i < ySize; i++) { | ||
z[i] = new Array(xSize); | ||
var xVector = spectra[i].data[0]; | ||
let xVector = spectra[i].data[0]; | ||
for (let j = 0; j < xSize; j++) { | ||
var value = xVector[j * 2 + 1]; | ||
let value = xVector[j * 2 + 1]; | ||
z[i][j] = value; | ||
@@ -573,3 +579,3 @@ if (value < minZ) minZ = value; | ||
maxZ: maxZ, | ||
noise: getMedian(z[0].map(Math.abs)) | ||
noise: getMedian(z[0].map(Math.abs)), | ||
}; | ||
@@ -579,3 +585,3 @@ } | ||
function add2D(result, options) { | ||
var zData = convertTo3DZ(result.spectra); | ||
let zData = convertTo3DZ(result.spectra); | ||
if (!options.noContour) { | ||
@@ -589,18 +595,18 @@ result.contourLines = generateContourLines(zData, options); | ||
function generateContourLines(zData, options) { | ||
var noise = zData.noise; | ||
var z = zData.z; | ||
var povarHeight0, povarHeight1, povarHeight2, povarHeight3; | ||
var isOver0, isOver1, isOver2, isOver3; | ||
var nbSubSpectra = z.length; | ||
var nbPovars = z[0].length; | ||
var pAx, pAy, pBx, pBy; | ||
let noise = zData.noise; | ||
let z = zData.z; | ||
let povarHeight0, povarHeight1, povarHeight2, povarHeight3; | ||
let isOver0, isOver1, isOver2, isOver3; | ||
let nbSubSpectra = z.length; | ||
let nbPovars = z[0].length; | ||
let pAx, pAy, pBx, pBy; | ||
var x0 = zData.minX; | ||
var xN = zData.maxX; | ||
var dx = (xN - x0) / (nbPovars - 1); | ||
var y0 = zData.minY; | ||
var yN = zData.maxY; | ||
var dy = (yN - y0) / (nbSubSpectra - 1); | ||
var minZ = zData.minZ; | ||
var maxZ = zData.maxZ; | ||
let x0 = zData.minX; | ||
let xN = zData.maxX; | ||
let dx = (xN - x0) / (nbPovars - 1); | ||
let y0 = zData.minY; | ||
let yN = zData.maxY; | ||
let dy = (yN - y0) / (nbSubSpectra - 1); | ||
let minZ = zData.minZ; | ||
let maxZ = zData.maxZ; | ||
@@ -618,11 +624,11 @@ // System.out.prvarln('y0 '+y0+' yN '+yN); | ||
var iter = options.nbContourLevels * 2; | ||
var contourLevels = new Array(iter); | ||
var lineZValue; | ||
for (var level = 0; level < iter; level++) { | ||
let iter = options.nbContourLevels * 2; | ||
let contourLevels = new Array(iter); | ||
let lineZValue; | ||
for (let level = 0; level < iter; level++) { | ||
// multiply by 2 for positif and negatif | ||
var contourLevel = {}; | ||
let contourLevel = {}; | ||
contourLevels[level] = contourLevel; | ||
var side = level % 2; | ||
var factor = | ||
let side = level % 2; | ||
let factor = | ||
(maxZ - options.noiseMultiplier * noise) * | ||
@@ -635,3 +641,3 @@ Math.exp((level >> 1) - options.nbContourLevels); | ||
} | ||
var lines = []; | ||
let lines = []; | ||
contourLevel.zValue = lineZValue; | ||
@@ -642,6 +648,6 @@ contourLevel.lines = lines; | ||
for (var iSubSpectra = 0; iSubSpectra < nbSubSpectra - 1; iSubSpectra++) { | ||
var subSpectra = z[iSubSpectra]; | ||
var subSpectraAfter = z[iSubSpectra + 1]; | ||
for (var povar = 0; povar < nbPovars - 1; povar++) { | ||
for (let iSubSpectra = 0; iSubSpectra < nbSubSpectra - 1; iSubSpectra++) { | ||
let subSpectra = z[iSubSpectra]; | ||
let subSpectraAfter = z[iSubSpectra + 1]; | ||
for (let povar = 0; povar < nbPovars - 1; povar++) { | ||
povarHeight0 = subSpectra[povar]; | ||
@@ -756,3 +762,3 @@ povarHeight1 = subSpectra[povar + 1]; | ||
maxY: zData.maxY, | ||
segments: contourLevels | ||
segments: contourLevels, | ||
}; | ||
@@ -766,17 +772,17 @@ } | ||
var yFactor = spectrum.yFactor; | ||
var deltaX = spectrum.deltaX; | ||
let yFactor = spectrum.yFactor; | ||
let deltaX = spectrum.deltaX; | ||
spectrum.isXYdata = true; | ||
// TODO to be improved using 2 array {x:[], y:[]} | ||
var currentData = []; | ||
let currentData = []; | ||
spectrum.data = [currentData]; | ||
var currentX = spectrum.firstX; | ||
var currentY = spectrum.firstY; | ||
let currentX = spectrum.firstX; | ||
let currentY = spectrum.firstY; | ||
// we skip the first line | ||
// | ||
var endLine = false; | ||
var ascii; | ||
let endLine = false; | ||
let ascii; | ||
let i = 0; | ||
@@ -793,14 +799,14 @@ for (; i < value.length; i++) { | ||
// we proceed taking the i after the first line | ||
var newLine = true; | ||
var isDifference = false; | ||
var isLastDifference = false; | ||
var lastDifference = 0; | ||
var isDuplicate = false; | ||
var inComment = false; | ||
var currentValue = 0; // can be a difference or a duplicate | ||
var lastValue = 0; // must be the real last value | ||
var isNegative = false; | ||
var inValue = false; | ||
var skipFirstValue = false; | ||
var decimalPosition = 0; | ||
let newLine = true; | ||
let isDifference = false; | ||
let isLastDifference = false; | ||
let lastDifference = 0; | ||
let isDuplicate = false; | ||
let inComment = false; | ||
let currentValue = 0; // can be a difference or a duplicate | ||
let lastValue = 0; // must be the real last value | ||
let isNegative = false; | ||
let inValue = false; | ||
let skipFirstValue = false; | ||
let decimalPosition = 0; | ||
for (; i <= value.length; i++) { | ||
@@ -853,4 +859,4 @@ if (i === value.length) ascii = 13; | ||
} | ||
var duplicate = isDuplicate ? currentValue - 1 : 1; | ||
for (var j = 0; j < duplicate; j++) { | ||
let duplicate = isDuplicate ? currentValue - 1 : 1; | ||
for (let j = 0; j < duplicate; j++) { | ||
if (isLastDifference) { | ||
@@ -918,3 +924,3 @@ currentY += lastDifference; | ||
// check if after there is a number, decimal or comma | ||
var ascii2 = value.charCodeAt(i + 1); | ||
let ascii2 = value.charCodeAt(i + 1); | ||
if ( | ||
@@ -941,10 +947,10 @@ (ascii2 >= 48 && ascii2 <= 57) || | ||
function parseXYA(spectrum, value) { | ||
var removeSymbolRegExp = /(\(+|\)+|<+|>+|\s+)/g; | ||
let removeSymbolRegExp = /(\(+|\)+|<+|>+|\s+)/g; | ||
spectrum.isXYAdata = true; | ||
var values; | ||
var currentData = []; | ||
let values; | ||
let currentData = []; | ||
spectrum.data = [currentData]; | ||
var lines = value.split(/,? *,?[;\r\n]+ */); | ||
let lines = value.split(/,? *,?[;\r\n]+ */); | ||
@@ -962,12 +968,12 @@ for (let i = 1; i < lines.length; i++) { | ||
function parsePeakTable(spectrum, value, result) { | ||
var removeCommentRegExp = /\$\$.*/; | ||
var peakTableSplitRegExp = /[,\t ]+/; | ||
let removeCommentRegExp = /\$\$.*/; | ||
let peakTableSplitRegExp = /[,\t ]+/; | ||
spectrum.isPeaktable = true; | ||
var values; | ||
var currentData = []; | ||
let values; | ||
let currentData = []; | ||
spectrum.data = [currentData]; | ||
// counts for around 20% of the time | ||
var lines = value.split(/,? *,?[;\r\n]+ */); | ||
let lines = value.split(/,? *,?[;\r\n]+ */); | ||
@@ -994,3 +1000,3 @@ for (let i = 1; i < lines.length; i++) { | ||
var convert = getConverter(); | ||
let convert = getConverter(); | ||
@@ -1009,4 +1015,4 @@ function JcampConverter(input, options, useWorker) { | ||
var stamps = {}; | ||
var worker; | ||
let stamps = {}; | ||
let worker; | ||
@@ -1017,4 +1023,4 @@ function postToWorker(input, options) { | ||
} | ||
return new Promise(function (resolve) { | ||
var stamp = `${Date.now()}${Math.random()}`; | ||
return new Promise(function(resolve) { | ||
let stamp = `${Date.now()}${Math.random()}`; | ||
stamps[stamp] = resolve; | ||
@@ -1025,4 +1031,4 @@ worker.postMessage( | ||
input: input, | ||
options: options | ||
}) | ||
options: options, | ||
}), | ||
); | ||
@@ -1033,13 +1039,15 @@ }); | ||
function createWorker() { | ||
var workerURL = URL.createObjectURL( | ||
let workerURL = URL.createObjectURL( | ||
new Blob( | ||
[`var getConverter =${getConverter.toString()};var convert = getConverter(); onmessage = function (event) { var data = JSON.parse(event.data); postMessage(JSON.stringify({stamp: data.stamp, output: convert(data.input, data.options)})); };`], | ||
{ type: 'application/javascript' } | ||
) | ||
[ | ||
`var getConverter =${getConverter.toString()};var convert = getConverter(); onmessage = function (event) { var data = JSON.parse(event.data); postMessage(JSON.stringify({stamp: data.stamp, output: convert(data.input, data.options)})); };`, | ||
], | ||
{ type: 'application/javascript' }, | ||
), | ||
); | ||
worker = new Worker(workerURL); | ||
URL.revokeObjectURL(workerURL); | ||
worker.addEventListener('message', function (event) { | ||
var data = JSON.parse(event.data); | ||
var stamp = data.stamp; | ||
worker.addEventListener('message', function(event) { | ||
let data = JSON.parse(event.data); | ||
let stamp = data.stamp; | ||
if (stamps[stamp]) { | ||
@@ -1066,3 +1074,3 @@ stamps[stamp](data.output); | ||
for (var i = 0; i < lines.length; i++) { | ||
for (let i = 0; i < lines.length; i++) { | ||
let line = lines[i]; | ||
@@ -1087,3 +1095,3 @@ let labelLine = spaces ? line.replace(/ /g, '') : line; | ||
jcamp: `${line}\n`, | ||
children: [] | ||
children: [], | ||
}); | ||
@@ -1094,3 +1102,3 @@ current = stack[stack.length - 1]; | ||
current.jcamp += `${line}\n`; | ||
var finished = stack.pop(); | ||
let finished = stack.pop(); | ||
if (stack.length !== 0) { | ||
@@ -1105,6 +1113,6 @@ current = stack[stack.length - 1]; | ||
current.jcamp += `${line}\n`; | ||
var match = labelLine.match(/^##(.*?)=(.+)/); | ||
let match = labelLine.match(/^##(.*?)=(.+)/); | ||
if (match) { | ||
var dataLabel = match[1].replace(/[ _-]/g, '').toUpperCase(); | ||
if (dataLabel === 'DATATYPE') { | ||
let canonicDataLabel = match[1].replace(/[ _-]/g, '').toUpperCase(); | ||
if (canonicDataLabel === 'DATATYPE') { | ||
current.dataType = match[2].trim(); | ||
@@ -1131,3 +1139,3 @@ } | ||
convert: JcampConverter, | ||
createTree: createTree | ||
createTree: createTree, | ||
}; |
44818
1003
99
9