Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cast tag value to string before call replace #48

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/NmrRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
let dataSplited = nmredataTags[tag].split('\n');
dataSplited.forEach((e) => {
let content = e.replace(/;.*/g, '').replace(/\r/g, '');
let comment = e.match(';') ? e.replace(/.*;+(.*)/g, '$1') : '';

Check warning on line 152 in src/NmrRecord.js

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Capture group '(.*)' should be converted to a named or non-capturing group
if (content.length === 0) {
// may be a head comment. is it always true?
if (!tagData.headComment) tagData.headComment = []; // should this be array for several head comments?
Expand All @@ -170,20 +170,18 @@
*/

export const getNMReDataTags = (sdf) => {
let sdfFile = checkSdf(sdf);
let version = parseFloat(sdfFile.molecules[0].NMREDATA_VERSION);

let nmredataTags = {};
const sdfFile = checkSdf(sdf);
const version = parseFloat(sdfFile.molecules[0].NMREDATA_VERSION);
const nmredataTags = {};
for (let tag of sdfFile.labels) {
if (tag.toLowerCase().match('nmredata')) {
if (!sdfFile.molecules[0][tag]) continue;
let key = tag.replace(/NMREDATA_/, '');
let data =
version > 1
? sdfFile.molecules[0][tag].replace(/\n*/g, '')
: sdfFile.molecules[0][tag];
data = String(data).replace(/\\\n*/g, '\n');
nmredataTags[key] = data;
if (!sdfFile.molecules[0]?.[tag]) continue;

const key = tag.replace(/NMREDATA_/, '');
let value = String(sdfFile.molecules[0][tag]);
value = version > 1 ? value.replace(/\n*/g, '') : value;
value = value.replace(/\\\n*/g, '\n');
nmredataTags[key] = value;
}
}
return nmredataTags;
Expand Down
Loading