Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jcampconverter

Package Overview
Dependencies
Maintainers
6
Versions
98
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jcampconverter - npm Package Compare versions

Comparing version 2.10.0 to 2.10.2

4

History.md

@@ -0,1 +1,5 @@

## [2.10.2](https://github.com/cheminfo-js/jcampconverter/compare/v2.10.1...v2.10.2) (2018-11-23)
<a name="2.9.1"></a>

@@ -2,0 +6,0 @@ ## [2.9.1](https://github.com/cheminfo-js/jcampconverter/compare/v2.9.0...v2.9.1) (2017-10-19)

4

package.json
{
"name": "jcampconverter",
"version": "2.10.0",
"version": "2.10.2",
"description": "Parse and convert JCAMP data",

@@ -39,3 +39,3 @@ "main": "./src/index.js",

"benchmark": "^2.1.4",
"cheminfo-tools": "^1.20.2",
"cheminfo-tools": "^1.22.4",
"codecov": "^2.3.1",

@@ -42,0 +42,0 @@ "eslint": "^4.19.1",

@@ -95,4 +95,10 @@ 'use strict';

if (infos[0].indexOf('++') > 0) {
var firstVariable = infos[0].replace(/.*\(([a-zA-Z0-9]+)\+\+.*/, '$1');
var secondVariable = infos[0].replace(/.*\.\.([a-zA-Z0-9]+).*/, '$1');
var firstVariable = infos[0].replace(
/.*\(([a-zA-Z0-9]+)\+\+.*/,
'$1'
);
var secondVariable = infos[0].replace(
/.*\.\.([a-zA-Z0-9]+).*/,
'$1'
);
xIndex = ntuples.symbol.indexOf(firstVariable);

@@ -106,8 +112,16 @@ yIndex = ntuples.symbol.indexOf(secondVariable);

if (ntuples.first) {
if (ntuples.first.length > xIndex) spectrum.firstX = ntuples.first[xIndex];
if (ntuples.first.length > yIndex) spectrum.firstY = ntuples.first[yIndex];
if (ntuples.first.length > xIndex) {
spectrum.firstX = ntuples.first[xIndex];
}
if (ntuples.first.length > yIndex) {
spectrum.firstY = ntuples.first[yIndex];
}
}
if (ntuples.last) {
if (ntuples.last.length > xIndex) spectrum.lastX = ntuples.last[xIndex];
if (ntuples.last.length > yIndex) spectrum.lastY = ntuples.last[yIndex];
if (ntuples.last.length > xIndex) {
spectrum.lastX = ntuples.last[xIndex];
}
if (ntuples.last.length > yIndex) {
spectrum.lastY = ntuples.last[yIndex];
}
}

@@ -118,8 +132,16 @@ if (ntuples.vardim && ntuples.vardim.length > xIndex) {

if (ntuples.factor) {
if (ntuples.factor.length > xIndex) spectrum.xFactor = ntuples.factor[xIndex];
if (ntuples.factor.length > yIndex) spectrum.yFactor = ntuples.factor[yIndex];
if (ntuples.factor.length > xIndex) {
spectrum.xFactor = ntuples.factor[xIndex];
}
if (ntuples.factor.length > yIndex) {
spectrum.yFactor = ntuples.factor[yIndex];
}
}
if (ntuples.units) {
if (ntuples.units.length > xIndex) spectrum.xUnit = ntuples.units[xIndex];
if (ntuples.units.length > yIndex) spectrum.yUnit = ntuples.units[yIndex];
if (ntuples.units.length > xIndex) {
spectrum.xUnit = ntuples.units[xIndex];
}
if (ntuples.units.length > yIndex) {
spectrum.yUnit = ntuples.units[yIndex];
}
}

@@ -129,5 +151,9 @@ spectrum.datatable = infos[0];

dataLabel = 'PEAKTABLE';
} else if (infos[1] && (infos[1].indexOf('XYDATA') || infos[0].indexOf('++') > 0)) {
} else if (
infos[1] &&
(infos[1].indexOf('XYDATA') || infos[0].indexOf('++') > 0)
) {
dataLabel = 'XYDATA';
spectrum.deltaX = (spectrum.lastX - spectrum.firstX) / (spectrum.nbPoints - 1);
spectrum.deltaX =
(spectrum.lastX - spectrum.firstX) / (spectrum.nbPoints - 1);
}

@@ -143,3 +169,4 @@ }

if (!spectrum.deltaX) {
spectrum.deltaX = (spectrum.lastX - spectrum.firstX) / (spectrum.nbPoints - 1);
spectrum.deltaX =
(spectrum.lastX - spectrum.firstX) / (spectrum.nbPoints - 1);
}

@@ -164,3 +191,2 @@ fastParseXYData(spectrum, dataValue, result);

if (dataLabel === 'TITLE') {

@@ -198,13 +224,21 @@ spectrum.title = dataValue;

} else if (dataLabel === '.OBSERVEFREQUENCY' || dataLabel === '$SFO1') {
if (!spectrum.observeFrequency) spectrum.observeFrequency = parseFloat(dataValue);
if (!spectrum.observeFrequency) {
spectrum.observeFrequency = parseFloat(dataValue);
}
} else if (dataLabel === '.OBSERVENUCLEUS') {
if (!spectrum.xType) result.xType = dataValue.replace(/[^a-zA-Z0-9]/g, '');
if (!spectrum.xType) {
result.xType = dataValue.replace(/[^a-zA-Z0-9]/g, '');
}
} else if (dataLabel === '$SFO2') {
if (!result.indirectFrequency) result.indirectFrequency = parseFloat(dataValue);
} else if (dataLabel === '$OFFSET') { // OFFSET for Bruker spectra
if (!result.indirectFrequency) {
result.indirectFrequency = parseFloat(dataValue);
}
} else if (dataLabel === '$OFFSET') {
// OFFSET for Bruker spectra
result.shiftOffsetNum = 0;
if (!result.shiftOffsetVal) result.shiftOffsetVal = parseFloat(dataValue);
} else if (dataLabel === '$REFERENCEPOINT') { // OFFSET for Varian spectra
if (!result.shiftOffsetVal) {
result.shiftOffsetVal = parseFloat(dataValue);
}
} else if (dataLabel === '$REFERENCEPOINT') {
// OFFSET for Varian spectra
// if we activate this part it does not work for ACD specmanager

@@ -301,3 +335,4 @@ // } else if (dataLabel=='.SHIFTREFERENCE') { // OFFSET FOR Bruker Spectra

if (options.xy && wantXY) { // the spectraData should not be a oneD array but an object with x and y
if (options.xy && wantXY) {
// the spectraData should not be a oneD array but an object with x and y
if (spectra.length > 0) {

@@ -349,3 +384,2 @@ for (i = 0; i < spectra.length; i++) {

function convertMSFieldToLabel(value) {

@@ -389,6 +423,11 @@ return value.toLowerCase().replace(/[^a-z0-9]/g, '');

for (var j = 0; j < existingGCMSFields.length; j++) {
chromatogram.series[existingGCMSFields[j]].data[i] = parseFloat(spectrum[existingGCMSFields[j]]);
chromatogram.series[existingGCMSFields[j]].data[i] = parseFloat(
spectrum[existingGCMSFields[j]]
);
}
if (spectrum.data) {
chromatogram.series.ms.data[i] = [spectrum.data[0].x, spectrum.data[0].y];
chromatogram.series.ms.data[i] = [
spectrum.data[0].x,
spectrum.data[0].y
];
}

@@ -478,3 +517,2 @@ }

function generateContourLines(zData, options) {

@@ -512,11 +550,14 @@ var noise = zData.noise;

var lineZValue;
for (var level = 0; level < iter; level++) { // multiply by 2 for positif and negatif
for (var level = 0; level < iter; level++) {
// multiply by 2 for positif and negatif
var contourLevel = {};
contourLevels[level] = contourLevel;
var side = level % 2;
var factor = (maxZ - options.noiseMultiplier * noise) * Math.exp((level >> 1) - options.nbContourLevels);
var factor =
(maxZ - options.noiseMultiplier * noise) *
Math.exp((level >> 1) - options.nbContourLevels);
if (side === 0) {
lineZValue = factor + options.noiseMultiplier * noise;
} else {
lineZValue = (0 - factor) - options.noiseMultiplier * noise;
lineZValue = 0 - factor - options.noiseMultiplier * noise;
}

@@ -538,6 +579,6 @@ var lines = [];

isOver0 = (povarHeight0 > lineZValue);
isOver1 = (povarHeight1 > lineZValue);
isOver2 = (povarHeight2 > lineZValue);
isOver3 = (povarHeight3 > lineZValue);
isOver0 = povarHeight0 > lineZValue;
isOver1 = povarHeight1 > lineZValue;
isOver2 = povarHeight2 > lineZValue;
isOver3 = povarHeight3 > lineZValue;

@@ -548,6 +589,10 @@ // Example povar0 is over the plane and povar1 and

if (isOver0 !== isOver1 && isOver0 !== isOver2) {
pAx = povar + (lineZValue - povarHeight0) / (povarHeight1 - povarHeight0);
pAx =
povar +
(lineZValue - povarHeight0) / (povarHeight1 - povarHeight0);
pAy = iSubSpectra;
pBx = povar;
pBy = iSubSpectra + (lineZValue - povarHeight0) / (povarHeight2 - povarHeight0);
pBy =
iSubSpectra +
(lineZValue - povarHeight0) / (povarHeight2 - povarHeight0);
lines.push(pAx * dx + x0);

@@ -561,4 +606,10 @@ lines.push(pAy * dy + y0);

pAx = povar + 1;
pAy = iSubSpectra + 1 - (lineZValue - povarHeight3) / (povarHeight1 - povarHeight3);
pBx = povar + 1 - (lineZValue - povarHeight3) / (povarHeight2 - povarHeight3);
pAy =
iSubSpectra +
1 -
(lineZValue - povarHeight3) / (povarHeight1 - povarHeight3);
pBx =
povar +
1 -
(lineZValue - povarHeight3) / (povarHeight2 - povarHeight3);
pBy = iSubSpectra + 1;

@@ -572,6 +623,18 @@ lines.push(pAx * dx + x0);

if (isOver1 !== isOver2) {
pAx = (povar + 1 - (lineZValue - povarHeight1) / (povarHeight2 - povarHeight1)) * dx + x0;
pAy = (iSubSpectra + (lineZValue - povarHeight1) / (povarHeight2 - povarHeight1)) * dy + y0;
pAx =
(povar +
1 -
(lineZValue - povarHeight1) / (povarHeight2 - povarHeight1)) *
dx +
x0;
pAy =
(iSubSpectra +
(lineZValue - povarHeight1) / (povarHeight2 - povarHeight1)) *
dy +
y0;
if (isOver1 !== isOver0) {
pBx = povar + 1 - (lineZValue - povarHeight1) / (povarHeight0 - povarHeight1);
pBx =
povar +
1 -
(lineZValue - povarHeight1) / (povarHeight0 - povarHeight1);
pBy = iSubSpectra;

@@ -585,3 +648,6 @@ lines.push(pAx);

pBx = povar;
pBy = iSubSpectra + 1 - (lineZValue - povarHeight2) / (povarHeight0 - povarHeight2);
pBy =
iSubSpectra +
1 -
(lineZValue - povarHeight2) / (povarHeight0 - povarHeight2);
lines.push(pAx);

@@ -594,3 +660,5 @@ lines.push(pAy);

pBx = povar + 1;
pBy = iSubSpectra + (lineZValue - povarHeight1) / (povarHeight3 - povarHeight1);
pBy =
iSubSpectra +
(lineZValue - povarHeight1) / (povarHeight3 - povarHeight1);
lines.push(pAx);

@@ -602,3 +670,5 @@ lines.push(pAy);

if (isOver2 !== isOver3) {
pBx = povar + (lineZValue - povarHeight2) / (povarHeight3 - povarHeight2);
pBx =
povar +
(lineZValue - povarHeight2) / (povarHeight3 - povarHeight2);
pBy = iSubSpectra + 1;

@@ -632,3 +702,2 @@ lines.push(pAx);

spectrum.isXYdata = true;

@@ -639,3 +708,2 @@ // TODO to be improved using 2 array {x:[], y:[]}

var currentX = spectrum.firstX;

@@ -682,3 +750,4 @@ var currentY = spectrum.firstY;

// it is a number that is either new or we continue
if (ascii <= 57 && ascii >= 48) { // a number
if (ascii <= 57 && ascii >= 48) {
// a number
inValue = true;

@@ -691,3 +760,4 @@ if (decimalPosition > 0) {

}
} else if (ascii === 44 || ascii === 46) { // a "," or "."
} else if (ascii === 44 || ascii === 46) {
// a "," or "."
inValue = true;

@@ -710,3 +780,3 @@ decimalPosition++;

if (isDifference) {
lastDifference = isNegative ? (0 - currentValue) : currentValue;
lastDifference = isNegative ? 0 - currentValue : currentValue;
isLastDifference = true;

@@ -720,3 +790,3 @@ isDifference = false;

} else {
currentY = isNegative ? (0 - currentValue) : currentValue;
currentY = isNegative ? 0 - currentValue : currentValue;
}

@@ -737,9 +807,8 @@ currentData.push(currentX);

// positive SQZ digits @ A B C D E F G H I (ascii 64-73)
if ((ascii < 74) && (ascii > 63)) {
if (ascii < 74 && ascii > 63) {
inValue = true;
isLastDifference = false;
currentValue = ascii - 64;
} else
// negative SQZ digits a b c d e f g h i (ascii 97-105)
if ((ascii > 96) && (ascii < 106)) {
} else if (ascii > 96 && ascii < 106) {
// negative SQZ digits a b c d e f g h i (ascii 97-105)
inValue = true;

@@ -749,21 +818,18 @@ isLastDifference = false;

isNegative = true;
} else
// DUP digits S T U V W X Y Z s (ascii 83-90, 115)
if (ascii === 115) {
} else if (ascii === 115) {
// DUP digits S T U V W X Y Z s (ascii 83-90, 115)
inValue = true;
isDuplicate = true;
currentValue = 9;
} else if ((ascii > 82) && (ascii < 91)) {
} else if (ascii > 82 && ascii < 91) {
inValue = true;
isDuplicate = true;
currentValue = ascii - 82;
} else
// positive DIF digits % J K L M N O P Q R (ascii 37, 74-82)
if ((ascii > 73) && (ascii < 83)) {
} else if (ascii > 73 && ascii < 83) {
// positive DIF digits % J K L M N O P Q R (ascii 37, 74-82)
inValue = true;
isDifference = true;
currentValue = ascii - 73;
} else
// negative DIF digits j k l m n o p q r (ascii 106-114)
if ((ascii > 105) && (ascii < 115)) {
} else if (ascii > 105 && ascii < 115) {
// negative DIF digits j k l m n o p q r (ascii 106-114)
inValue = true;

@@ -773,10 +839,8 @@ isDifference = true;

isNegative = true;
} else
// $ sign, we need to check the next one
if (ascii === 36 && value.charCodeAt(i + 1) === 36) {
} else if (ascii === 36 && value.charCodeAt(i + 1) === 36) {
// $ sign, we need to check the next one
inValue = true;
inComment = true;
} else
// positive DIF digits % J K L M N O P Q R (ascii 37, 74-82)
if (ascii === 37) {
} else if (ascii === 37) {
// positive DIF digits % J K L M N O P Q R (ascii 37, 74-82)
inValue = true;

@@ -786,6 +850,11 @@ isDifference = true;

isNegative = false;
} else if (ascii === 45) { // a "-"
} else if (ascii === 45) {
// a "-"
// check if after there is a number, decimal or comma
var ascii2 = value.charCodeAt(i + 1);
if ((ascii2 >= 48 && ascii2 <= 57) || ascii2 === 44 || ascii2 === 46) {
if (
(ascii2 >= 48 && ascii2 <= 57) ||
ascii2 === 44 ||
ascii2 === 46
) {
inValue = true;

@@ -819,3 +888,6 @@ if (!newLine) isLastDifference = false;

for (i = 1, ii = lines.length; i < ii; i++) {
values = lines[i].trim().replace(removeCommentRegExp, '').split(peakTableSplitRegExp);
values = lines[i]
.trim()
.replace(removeCommentRegExp, '')
.split(peakTableSplitRegExp);
if (values.length % 2 === 0) {

@@ -833,3 +905,2 @@ for (j = 0, jj = values.length; j < jj; j = j + 2) {

return convert;

@@ -862,7 +933,9 @@ }

stamps[stamp] = resolve;
worker.postMessage(JSON.stringify({
stamp: stamp,
input: input,
options: options
}));
worker.postMessage(
JSON.stringify({
stamp: stamp,
input: input,
options: options
})
);
});

@@ -872,3 +945,8 @@ }

function createWorker() {
var 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 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' }
)
);
worker = new Worker(workerURL);

@@ -886,5 +964,3 @@ URL.revokeObjectURL(workerURL);

function createTree(jcamp, options = {}) {
const {
flatten = false
} = options;
const { flatten = false } = options;
if (typeof jcamp !== 'string') {

@@ -894,8 +970,9 @@ throw new TypeError('the JCAMP should be a string');

var lines = jcamp.split(/[\r\n]+/);
var flat = [];
var stack = [];
var result = [];
var current;
var ntupleLevel = 0;
let lines = jcamp.split(/[\r\n]+/);
let flat = [];
let stack = [];
let result = [];
let current;
let ntupleLevel = 0;
for (var i = 0; i < lines.length; i++) {

@@ -909,4 +986,12 @@ var line = lines[i];

if (line.substring(0, 7) === '##TITLE') {
let title = [line.substring(8).trim()];
for (let j = i + 1; j < lines.length; j++) {
if (lines[j].startsWith('##')) {
break;
} else {
title.push(lines[j].trim());
}
}
stack.push({
title: line.substring(8).trim(),
title: title.join('\n'),
jcamp: `${line}\n`,

@@ -943,3 +1028,5 @@ children: []

if (flatten) {
flat.forEach( (entry) => {entry.children=undefined;});
flat.forEach((entry) => {
entry.children = undefined;
});
return flat;

@@ -946,0 +1033,0 @@ } else {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc