Skip to content

Commit 2cd7aa3

Browse files
committed
add check for autometadata
1 parent 37b67dd commit 2cd7aa3

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

dist/helpers/format.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,19 @@ const toPeakStr = peaks => {
6060
const str = arr.join('#');
6161
return str;
6262
};
63-
let fixedWavelength = null;
63+
let fixedWavelength = '';
6464
const extractFixedWavelength = source => {
6565
const jcamp = _jcampconverter.default.convert(source, {
6666
xy: true,
6767
keepRecordsRegExp: /(CSAUTOMETADATA)/
6868
});
69-
// eslint-disable-next-line prefer-destructuring
70-
fixedWavelength = jcamp.info.$CSAUTOMETADATA.match(/FIXEDWAVELENGTH=([\d.]+)/)[1];
69+
if ('$CSAUTOMETADATA' in jcamp.info) {
70+
const match = jcamp.info.$CSAUTOMETADATA.match(/FIXEDWAVELENGTH=([\d.]+)/);
71+
if (match !== null) {
72+
// eslint-disable-next-line prefer-destructuring
73+
fixedWavelength = match[1];
74+
}
75+
}
7176
return {
7277
fixedWavelength
7378
};
@@ -141,6 +146,10 @@ const spectraOps = {
141146
head: 'SIZE EXCLUSION CHROMATOGRAPHY',
142147
tail: '.'
143148
},
149+
[_list_layout.LIST_LAYOUT.EMISSIONS]: {
150+
head: 'EMISSION',
151+
tail: ' nm'
152+
},
144153
[_list_layout.LIST_LAYOUT.DLS_INTENSITY]: {
145154
head: 'DLS',
146155
tail: '.'
@@ -412,13 +421,13 @@ const peaksWrapper = function (layout, shift) {
412421
tail: ''
413422
};
414423
}
424+
const ops = spectraOps[layout];
415425
if (layout === _list_layout.LIST_LAYOUT.EMISSIONS) {
416426
return {
417-
head: `EMISSION: λex = ${fixedWavelength} nm, λem = `,
418-
tail: ' nm'
427+
head: `${ops.head}${solvTxt}: λex = ${fixedWavelength} nm; λem = `,
428+
tail: ops.tail
419429
};
420430
}
421-
const ops = spectraOps[layout];
422431
return {
423432
head: `${ops.head}${solvTxt} = `,
424433
tail: ops.tail

src/helpers/format.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const toPeakStr = (peaks) => {
5252
return str;
5353
};
5454

55-
let fixedWavelength = null;
55+
let fixedWavelength = '';
5656

5757
const extractFixedWavelength = (source) => {
5858
const jcamp = Jcampconverter.convert(
@@ -62,8 +62,13 @@ const extractFixedWavelength = (source) => {
6262
keepRecordsRegExp: /(CSAUTOMETADATA)/,
6363
},
6464
);
65-
// eslint-disable-next-line prefer-destructuring
66-
fixedWavelength = jcamp.info.$CSAUTOMETADATA.match(/FIXEDWAVELENGTH=([\d.]+)/)[1];
65+
if ('$CSAUTOMETADATA' in jcamp.info) {
66+
const match = jcamp.info.$CSAUTOMETADATA.match(/FIXEDWAVELENGTH=([\d.]+)/);
67+
if (match !== null) {
68+
// eslint-disable-next-line prefer-destructuring
69+
fixedWavelength = match[1];
70+
}
71+
}
6772

6873
return { fixedWavelength };
6974
};
@@ -86,6 +91,7 @@ const spectraOps = {
8691
[LIST_LAYOUT.CYCLIC_VOLTAMMETRY]: { head: 'CYCLIC VOLTAMMETRY', tail: '.' },
8792
[LIST_LAYOUT.CDS]: { head: 'CIRCULAR DICHROISM SPECTROSCOPY', tail: '.' },
8893
[LIST_LAYOUT.SEC]: { head: 'SIZE EXCLUSION CHROMATOGRAPHY', tail: '.' },
94+
[LIST_LAYOUT.EMISSIONS]: { head: 'EMISSION', tail: ' nm' },
8995
[LIST_LAYOUT.DLS_INTENSITY]: { head: 'DLS', tail: '.' },
9096
};
9197

@@ -340,10 +346,10 @@ const peaksWrapper = (layout, shift, atIndex = 0) => {
340346
return { head: '', tail: '' };
341347
}
342348

349+
const ops = spectraOps[layout];
343350
if (layout === LIST_LAYOUT.EMISSIONS) {
344-
return { head: `EMISSION: λex = ${fixedWavelength} nm, λem = `, tail: ' nm' };
351+
return { head: `${ops.head}${solvTxt}: λex = ${fixedWavelength} nm; λem = `, tail: ops.tail };
345352
}
346-
const ops = spectraOps[layout];
347353
return { head: `${ops.head}${solvTxt} = `, tail: ops.tail };
348354
};
349355

0 commit comments

Comments
 (0)