jcampconverter
Advanced tools
Comparing version 8.2.1 to 8.2.2
# Changelog | ||
### [8.2.2](https://www.github.com/cheminfo/jcampconverter/compare/v8.2.1...v8.2.2) (2021-11-05) | ||
### Bug Fixes | ||
* replace parseFloat by Number ([e65c194](https://www.github.com/cheminfo/jcampconverter/commit/e65c19483e8c429d73e540614e7e020cdd660e0b)) | ||
### [8.2.1](https://www.github.com/cheminfo/jcampconverter/compare/v8.2.0...v8.2.1) (2021-09-30) | ||
@@ -4,0 +11,0 @@ |
@@ -15,4 +15,5 @@ 'use strict'; | ||
/** | ||
* Parse the jcamp to extract the structure as a tree | ||
* @param {string|ArrayBuffer jcamp | ||
* Parse the jcamp to extract the structure as a tree. | ||
* | ||
* @param {string|ArrayBuffer|Uint8Array} jcamp | ||
* @param {object} [options={}] | ||
@@ -128,3 +129,3 @@ * @param {boolean} [options.flatten=false] | ||
for (let j = 0; j < existingGCMSFields.length; j++) { | ||
chromatogram.series[existingGCMSFields[j]].data[i] = parseFloat( | ||
chromatogram.series[existingGCMSFields[j]].data[i] = Number( | ||
spectrum[existingGCMSFields[j]], | ||
@@ -151,3 +152,3 @@ ); | ||
for (let i = 0; i < stringArray.length; i++) { | ||
floatArray.push(parseFloat(stringArray[i])); | ||
floatArray.push(Number(stringArray[i])); | ||
} | ||
@@ -365,5 +366,5 @@ return floatArray; | ||
for (let j = 0; j < values.length; j = j + 2) { | ||
// takes around 40% of the time to add and parse the 2 values nearly exclusively because of parseFloat | ||
currentData.x.push(parseFloat(values[j]) * spectrum.xFactor); | ||
currentData.y.push(parseFloat(values[j + 1]) * spectrum.yFactor); | ||
// takes around 40% of the time to add and parse the 2 values nearly exclusively because of Number | ||
currentData.x.push(Number(values[j]) * spectrum.xFactor); | ||
currentData.y.push(Number(values[j + 1]) * spectrum.yFactor); | ||
} | ||
@@ -394,5 +395,3 @@ } else { | ||
// todo should try to find a xFactor (y, ...) | ||
currentData[variables[j % numberOfVariables]].push( | ||
parseFloat(values[j]), | ||
); | ||
currentData[variables[j % numberOfVariables]].push(Number(values[j])); | ||
} | ||
@@ -417,4 +416,4 @@ } else { | ||
values = lines[i].trim().replace(removeSymbolRegExp, '').split(','); | ||
currentData.x.push(parseFloat(values[0])); | ||
currentData.y.push(parseFloat(values[1])); | ||
currentData.x.push(Number(values[0])); | ||
currentData.y.push(Number(values[1])); | ||
} | ||
@@ -923,16 +922,18 @@ } | ||
/** | ||
* Parse a jcamp. | ||
* | ||
* @param {string|ArrayBuffer} jcamp | ||
* @param {string|ArrayBuffer|Uint8Array} jcamp | ||
* @param {object} [options] | ||
* @param {number} [options.keepRecordsRegExp=/^$/] By default we don't keep meta information | ||
* @param {number} [options.canonicDataLabels=true] Canonize the Labels (uppercase without symbol) | ||
* @param {number} [options.canonicMetadataLabels=false] Canonize the metadata Labels (uppercase without symbol) | ||
* @param {number} [options.dynamicTyping=false] Convert numbers to Number | ||
* @param {number} [options.withoutXY=false] Remove the XY data | ||
* @param {number} [options.chromatogram=false] Special post-processing for GC / HPLC / MS | ||
* @param {number} [options.keepSpectra=false] Force to keep the spectra in case of 2D | ||
* @param {number} [options.noContour=false] Don't calculate countour in case of 2D | ||
* @param {number} [options.nbContourLevels=7] Number of positive / negative contour levels to calculate | ||
* @param {number} [options.noiseMultiplier=5] Define for 2D the level as 5 times the median as default | ||
* @param {number} [options.profiling=false] Add profiling information | ||
* @param {number} [options.keepRecordsRegExp=/^$/] - By default we don't keep meta information. | ||
* @param {number} [options.canonicDataLabels=true] - Canonize the Labels (uppercase without symbol). | ||
* @param {number} [options.canonicMetadataLabels=false] - Canonize the metadata Labels (uppercase without symbol). | ||
* @param {number} [options.dynamicTyping=false] - Convert numbers to Number. | ||
* @param {number} [options.withoutXY=false] - Remove the XY data. | ||
* @param {number} [options.chromatogram=false] - Special post-processing for GC / HPLC / MS. | ||
* @param {number} [options.keepSpectra=false] - Force to keep the spectra in case of 2D. | ||
* @param {number} [options.noContour=false] - Don't calculate countour in case of 2D. | ||
* @param {number} [options.nbContourLevels=7] - Number of positive / negative contour levels to calculate. | ||
* @param {number} [options.noiseMultiplier=5] - Define for 2D the level as 5 times the median as default. | ||
* @param {number} [options.profiling=false] - Add profiling information. | ||
* @returns {object} | ||
*/ | ||
@@ -1074,25 +1075,25 @@ | ||
} else if (canonicDataLabel === 'FIRSTX') { | ||
spectrum.firstX = parseFloat(dataValue); | ||
spectrum.firstX = Number(dataValue); | ||
} else if (canonicDataLabel === 'LASTX') { | ||
spectrum.lastX = parseFloat(dataValue); | ||
spectrum.lastX = Number(dataValue); | ||
} else if (canonicDataLabel === 'FIRSTY') { | ||
spectrum.firstY = parseFloat(dataValue); | ||
spectrum.firstY = Number(dataValue); | ||
} else if (canonicDataLabel === 'LASTY') { | ||
spectrum.lastY = parseFloat(dataValue); | ||
spectrum.lastY = Number(dataValue); | ||
} else if (canonicDataLabel === 'NPOINTS') { | ||
spectrum.nbPoints = parseFloat(dataValue); | ||
spectrum.nbPoints = Number(dataValue); | ||
} else if (canonicDataLabel === 'XFACTOR') { | ||
spectrum.xFactor = parseFloat(dataValue); | ||
spectrum.xFactor = Number(dataValue); | ||
} else if (canonicDataLabel === 'YFACTOR') { | ||
spectrum.yFactor = parseFloat(dataValue); | ||
spectrum.yFactor = Number(dataValue); | ||
} else if (canonicDataLabel === 'MAXX') { | ||
spectrum.maxX = parseFloat(dataValue); | ||
spectrum.maxX = Number(dataValue); | ||
} else if (canonicDataLabel === 'MINX') { | ||
spectrum.minX = parseFloat(dataValue); | ||
spectrum.minX = Number(dataValue); | ||
} else if (canonicDataLabel === 'MAXY') { | ||
spectrum.maxY = parseFloat(dataValue); | ||
spectrum.maxY = Number(dataValue); | ||
} else if (canonicDataLabel === 'MINY') { | ||
spectrum.minY = parseFloat(dataValue); | ||
spectrum.minY = Number(dataValue); | ||
} else if (canonicDataLabel === 'DELTAX') { | ||
spectrum.deltaX = parseFloat(dataValue); | ||
spectrum.deltaX = Number(dataValue); | ||
} else if ( | ||
@@ -1103,3 +1104,3 @@ canonicDataLabel === '.OBSERVEFREQUENCY' || | ||
if (!spectrum.observeFrequency) { | ||
spectrum.observeFrequency = parseFloat(dataValue); | ||
spectrum.observeFrequency = Number(dataValue); | ||
} | ||
@@ -1114,3 +1115,3 @@ } else if (canonicDataLabel === '.OBSERVENUCLEUS') { | ||
if (!spectrum.shiftOffsetVal) { | ||
spectrum.shiftOffsetVal = parseFloat(dataValue); | ||
spectrum.shiftOffsetVal = Number(dataValue); | ||
} | ||
@@ -1157,6 +1158,6 @@ } else if (canonicDataLabel === '$REFERENCEPOINT') ; else if (canonicDataLabel === 'VARNAME') { | ||
spectrum.page = dataValue.trim(); | ||
spectrum.pageValue = parseFloat(dataValue.replace(/^.*=/, '')); | ||
spectrum.pageValue = Number(dataValue.replace(/^.*=/, '')); | ||
spectrum.pageSymbol = spectrum.page.replace(/[=].*/, ''); | ||
} else if (canonicDataLabel === 'RETENTIONTIME') { | ||
spectrum.pageValue = parseFloat(dataValue); | ||
spectrum.pageValue = Number(dataValue); | ||
} else if (isMSField(canonicDataLabel)) { | ||
@@ -1163,0 +1164,0 @@ spectrum[convertMSFieldToLabel(canonicDataLabel)] = dataValue; |
{ | ||
"name": "jcampconverter", | ||
"version": "8.2.1", | ||
"version": "8.2.2", | ||
"description": "Parse and convert JCAMP data", | ||
@@ -22,4 +22,7 @@ "main": "lib/index.js", | ||
"eslint-fix": "npm run eslint -- --fix", | ||
"jscpd": "jscpd -l 10 -i \"**/__tests__/**\" -t 1 src", | ||
"prepack": "rollup -c", | ||
"test": "npm run test-coverage && npm run eslint", | ||
"prettier": "prettier --check src", | ||
"prettier-write": "prettier --write src", | ||
"test": "npm run test-coverage && npm run eslint && npm run prettier", | ||
"test-coverage": "jest --coverage", | ||
@@ -49,16 +52,14 @@ "test-only": "jest", | ||
"devDependencies": { | ||
"@babel/plugin-transform-modules-commonjs": "^7.15.4", | ||
"@babel/plugin-transform-modules-commonjs": "^7.16.0", | ||
"@types/jest": "^27.0.2", | ||
"benchmark": "^2.1.4", | ||
"cheminfo-build": "^1.1.11", | ||
"eslint": "^7.32.0", | ||
"eslint-config-cheminfo": "^5.5.0", | ||
"eslint-plugin-import": "^2.24.2", | ||
"eslint-plugin-jest": "^24.5.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"eslint": "^8.1.0", | ||
"eslint-config-cheminfo": "^7.2.0", | ||
"esm": "^3.2.25", | ||
"jest": "^27.2.4", | ||
"jest-matcher-deep-close-to": "^3.0.0", | ||
"jest": "^27.3.1", | ||
"jest-matcher-deep-close-to": "^3.0.2", | ||
"jscpd": "^3.3.26", | ||
"prettier": "^2.4.1", | ||
"rollup": "^2.57.0" | ||
"rollup": "^2.59.0" | ||
}, | ||
@@ -69,4 +70,4 @@ "dependencies": { | ||
"ml-array-median": "^1.1.5", | ||
"nmr-processing": "^3.0.2" | ||
"nmr-processing": "^3.4.0" | ||
} | ||
} |
@@ -32,3 +32,3 @@ const GC_MS_FIELDS = ['TIC', '.RIC', 'SCANNUMBER']; | ||
for (let j = 0; j < existingGCMSFields.length; j++) { | ||
chromatogram.series[existingGCMSFields[j]].data[i] = parseFloat( | ||
chromatogram.series[existingGCMSFields[j]].data[i] = Number( | ||
spectrum[existingGCMSFields[j]], | ||
@@ -35,0 +35,0 @@ ); |
@@ -34,19 +34,21 @@ import { parseString } from 'dynamic-typing'; | ||
/** | ||
* Parse a jcamp. | ||
* | ||
* @param {string|ArrayBuffer} jcamp | ||
* @param {string|ArrayBuffer|Uint8Array} jcamp | ||
* @param {object} [options] | ||
* @param {number} [options.keepRecordsRegExp=/^$/] By default we don't keep meta information | ||
* @param {number} [options.canonicDataLabels=true] Canonize the Labels (uppercase without symbol) | ||
* @param {number} [options.canonicMetadataLabels=false] Canonize the metadata Labels (uppercase without symbol) | ||
* @param {number} [options.dynamicTyping=false] Convert numbers to Number | ||
* @param {number} [options.withoutXY=false] Remove the XY data | ||
* @param {number} [options.chromatogram=false] Special post-processing for GC / HPLC / MS | ||
* @param {number} [options.keepSpectra=false] Force to keep the spectra in case of 2D | ||
* @param {number} [options.noContour=false] Don't calculate countour in case of 2D | ||
* @param {number} [options.nbContourLevels=7] Number of positive / negative contour levels to calculate | ||
* @param {number} [options.noiseMultiplier=5] Define for 2D the level as 5 times the median as default | ||
* @param {number} [options.profiling=false] Add profiling information | ||
* @param {number} [options.keepRecordsRegExp=/^$/] - By default we don't keep meta information. | ||
* @param {number} [options.canonicDataLabels=true] - Canonize the Labels (uppercase without symbol). | ||
* @param {number} [options.canonicMetadataLabels=false] - Canonize the metadata Labels (uppercase without symbol). | ||
* @param {number} [options.dynamicTyping=false] - Convert numbers to Number. | ||
* @param {number} [options.withoutXY=false] - Remove the XY data. | ||
* @param {number} [options.chromatogram=false] - Special post-processing for GC / HPLC / MS. | ||
* @param {number} [options.keepSpectra=false] - Force to keep the spectra in case of 2D. | ||
* @param {number} [options.noContour=false] - Don't calculate countour in case of 2D. | ||
* @param {number} [options.nbContourLevels=7] - Number of positive / negative contour levels to calculate. | ||
* @param {number} [options.noiseMultiplier=5] - Define for 2D the level as 5 times the median as default. | ||
* @param {number} [options.profiling=false] - Add profiling information. | ||
* @returns {object} | ||
*/ | ||
export default function convert(jcamp, options = {}) { | ||
export function convert(jcamp, options = {}) { | ||
jcamp = ensureString(jcamp); | ||
@@ -185,25 +187,25 @@ options = { ...defaultOptions, ...options }; | ||
} else if (canonicDataLabel === 'FIRSTX') { | ||
spectrum.firstX = parseFloat(dataValue); | ||
spectrum.firstX = Number(dataValue); | ||
} else if (canonicDataLabel === 'LASTX') { | ||
spectrum.lastX = parseFloat(dataValue); | ||
spectrum.lastX = Number(dataValue); | ||
} else if (canonicDataLabel === 'FIRSTY') { | ||
spectrum.firstY = parseFloat(dataValue); | ||
spectrum.firstY = Number(dataValue); | ||
} else if (canonicDataLabel === 'LASTY') { | ||
spectrum.lastY = parseFloat(dataValue); | ||
spectrum.lastY = Number(dataValue); | ||
} else if (canonicDataLabel === 'NPOINTS') { | ||
spectrum.nbPoints = parseFloat(dataValue); | ||
spectrum.nbPoints = Number(dataValue); | ||
} else if (canonicDataLabel === 'XFACTOR') { | ||
spectrum.xFactor = parseFloat(dataValue); | ||
spectrum.xFactor = Number(dataValue); | ||
} else if (canonicDataLabel === 'YFACTOR') { | ||
spectrum.yFactor = parseFloat(dataValue); | ||
spectrum.yFactor = Number(dataValue); | ||
} else if (canonicDataLabel === 'MAXX') { | ||
spectrum.maxX = parseFloat(dataValue); | ||
spectrum.maxX = Number(dataValue); | ||
} else if (canonicDataLabel === 'MINX') { | ||
spectrum.minX = parseFloat(dataValue); | ||
spectrum.minX = Number(dataValue); | ||
} else if (canonicDataLabel === 'MAXY') { | ||
spectrum.maxY = parseFloat(dataValue); | ||
spectrum.maxY = Number(dataValue); | ||
} else if (canonicDataLabel === 'MINY') { | ||
spectrum.minY = parseFloat(dataValue); | ||
spectrum.minY = Number(dataValue); | ||
} else if (canonicDataLabel === 'DELTAX') { | ||
spectrum.deltaX = parseFloat(dataValue); | ||
spectrum.deltaX = Number(dataValue); | ||
} else if ( | ||
@@ -214,3 +216,3 @@ canonicDataLabel === '.OBSERVEFREQUENCY' || | ||
if (!spectrum.observeFrequency) { | ||
spectrum.observeFrequency = parseFloat(dataValue); | ||
spectrum.observeFrequency = Number(dataValue); | ||
} | ||
@@ -225,3 +227,3 @@ } else if (canonicDataLabel === '.OBSERVENUCLEUS') { | ||
if (!spectrum.shiftOffsetVal) { | ||
spectrum.shiftOffsetVal = parseFloat(dataValue); | ||
spectrum.shiftOffsetVal = Number(dataValue); | ||
} | ||
@@ -234,3 +236,3 @@ } else if (canonicDataLabel === '$REFERENCEPOINT') { | ||
// currentEntry.shiftOffsetNum = parseInt(parts[2].trim()); | ||
// spectrum.shiftOffsetVal = parseFloat(parts[3].trim()); | ||
// spectrum.shiftOffsetVal = Number(parts[3].trim()); | ||
} else if (canonicDataLabel === 'VARNAME') { | ||
@@ -276,6 +278,6 @@ currentEntry.ntuples.varname = dataValue.split(ntuplesSeparatorRegExp); | ||
spectrum.page = dataValue.trim(); | ||
spectrum.pageValue = parseFloat(dataValue.replace(/^.*=/, '')); | ||
spectrum.pageValue = Number(dataValue.replace(/^.*=/, '')); | ||
spectrum.pageSymbol = spectrum.page.replace(/[=].*/, ''); | ||
} else if (canonicDataLabel === 'RETENTIONTIME') { | ||
spectrum.pageValue = parseFloat(dataValue); | ||
spectrum.pageValue = Number(dataValue); | ||
} else if (isMSField(canonicDataLabel)) { | ||
@@ -282,0 +284,0 @@ spectrum[convertMSFieldToLabel(canonicDataLabel)] = dataValue; |
export default function convertToFloatArray(stringArray) { | ||
let floatArray = []; | ||
for (let i = 0; i < stringArray.length; i++) { | ||
floatArray.push(parseFloat(stringArray[i])); | ||
floatArray.push(Number(stringArray[i])); | ||
} | ||
return floatArray; | ||
} |
import { ensureString } from 'ensure-string'; | ||
/** | ||
* Parse the jcamp to extract the structure as a tree | ||
* @param {string|ArrayBuffer jcamp | ||
* Parse the jcamp to extract the structure as a tree. | ||
* | ||
* @param {string|ArrayBuffer|Uint8Array} jcamp | ||
* @param {object} [options={}] | ||
@@ -10,3 +11,3 @@ * @param {boolean} [options.flatten=false] | ||
*/ | ||
export default function createTree(jcamp, options = {}) { | ||
export function createTree(jcamp, options = {}) { | ||
jcamp = ensureString(jcamp); | ||
@@ -13,0 +14,0 @@ const { flatten = false } = options; |
@@ -1,2 +0,2 @@ | ||
export { default as createTree } from './createTree'; | ||
export { default as convert } from './convert'; | ||
export { createTree } from './createTree'; | ||
export { convert } from './convert'; |
@@ -35,5 +35,5 @@ const removeCommentRegExp = /\$\$.*/; | ||
for (let j = 0; j < values.length; j = j + 2) { | ||
// takes around 40% of the time to add and parse the 2 values nearly exclusively because of parseFloat | ||
currentData.x.push(parseFloat(values[j]) * spectrum.xFactor); | ||
currentData.y.push(parseFloat(values[j + 1]) * spectrum.yFactor); | ||
// takes around 40% of the time to add and parse the 2 values nearly exclusively because of Number | ||
currentData.x.push(Number(values[j]) * spectrum.xFactor); | ||
currentData.y.push(Number(values[j + 1]) * spectrum.yFactor); | ||
} | ||
@@ -64,5 +64,3 @@ } else { | ||
// todo should try to find a xFactor (y, ...) | ||
currentData[variables[j % numberOfVariables]].push( | ||
parseFloat(values[j]), | ||
); | ||
currentData[variables[j % numberOfVariables]].push(Number(values[j])); | ||
} | ||
@@ -69,0 +67,0 @@ } else { |
@@ -13,5 +13,5 @@ export default function parseXYA(spectrum, value) { | ||
values = lines[i].trim().replace(removeSymbolRegExp, '').split(','); | ||
currentData.x.push(parseFloat(values[0])); | ||
currentData.y.push(parseFloat(values[1])); | ||
currentData.x.push(Number(values[0])); | ||
currentData.y.push(Number(values[1])); | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
97422
12
2240
Updatednmr-processing@^3.4.0