Skip to content

Commit

Permalink
fix: replaced split by indexOf for equal signs
Browse files Browse the repository at this point in the history
  • Loading branch information
opatiny committed Apr 1, 2020
1 parent 558f054 commit f6d7363
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ Array [
"CHARGE": "1+",
"EXACTMASS": "348.193674",
"FILENAME": "PMA_065444",
"INCHI": "InChI",
"INCHI": "InChI=1/C20H28O5/c1-9-5-13-12(15(9)22)6-11(8-21)7-14-16-18(3,4)20(16,25)17(23)10(2)19(13,14)24/h5,7,10,14-17,21-25H,6,8H2,1-4H3/t10-,14+,15+,16-,17-,19+,20-/m1/s1",
"INCHIKEY": "CECQLSSRZIBODZ-MFYSWCGQSA-N",
"IONMODE": "Positive",
"MOLECULAR_FORMULA": "C20H28O5",
"NAME": "UNPD159661",
"PEPMASS": "349.20095",
"SCANS": "1",
"SEQ": "*..*",
"SMILES": "CC1C(O)C2(O)C(C3C",
"SMILES": "CC1C(O)C2(O)C(C3C=C(CO)CC4=C(C=C(C)C4O)C13O)C2(C)C",
"UNPD_ID": "UNPD159661",
},
},
Expand Down
9 changes: 6 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import uniqueX from 'ml-arrayxy-uniquex';
/**
* parses MGF files into a JSON
* @param {string} rawData input data (MGF)
* @param {object} options recordTypes allows to filter the data entries based on their type
* @param {object} options recordTypes (default: '') allows to filter the data entries based on their type
* @returns {array<object>} parsed data
*/
export function parse(rawData, options = {}) {
Expand Down Expand Up @@ -36,8 +36,11 @@ export function parse(rawData, options = {}) {
continue;
} else if (line.includes('=')) {
// verify if line is part of the metadata
let lineArray = line.split('=');
entry.meta[lineArray[0]] = lineArray[1];
let equalPos = line.indexOf('=');
let key = line.substring(0, equalPos);
let value = line.substring(equalPos + 1);

entry.meta[key] = value;
} else if (line.substring(0, 3) === 'END') {
// detect end of an entry and push it to results
entry.data = sortX(ms);
Expand Down

0 comments on commit f6d7363

Please sign in to comment.