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

mf-from-google-sheet

Package Overview
Dependencies
Maintainers
0
Versions
94
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mf-from-google-sheet - npm Package Compare versions

Comparing version 3.0.7 to 3.1.0

lib/index.d.ts

217

lib/index.js

@@ -1,130 +0,101 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var mfGenerator = require('mf-generator');
var mfParser = require('mf-parser');
var Papa = require('papaparse');
var crossFetch = require('cross-fetch');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var Papa__default = /*#__PURE__*/_interopDefaultLegacy(Papa);
var crossFetch__default = /*#__PURE__*/_interopDefaultLegacy(crossFetch);
async function fetchText(url) {
const result = await crossFetch__default["default"](url);
if (result.status !== 200) {
throw new Error(String(result.status));
}
return result.text();
}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.mfFromGoogleSheet = mfFromGoogleSheet;
const mf_generator_1 = require("mf-generator");
const mf_parser_1 = require("mf-parser");
const papaparse_1 = __importDefault(require("papaparse"));
const fetchText_js_1 = require("./util/fetchText.js");
async function mfFromGoogleSheet(url, options = {}) {
let { urlReferences } = options;
if (urlReferences) {
let results = await Promise.all([fetchText(url), fetchText(urlReferences)]);
return parse(results[0], results[1]);
} else {
let result = await fetchText(url);
return parse(result);
}
async function parse(tsv, tsvReferences) {
let parsed = Papa__default["default"].parse(tsv, {
delimiter: '\t',
header: true,
});
let fields = parsed.meta.fields;
let infoFields = fields.filter(
(a) =>
!['mf', 'modif', 'ESI', 'MALDI', 'positive', 'negative'].includes(a),
);
let formulas = parsed.data;
let references = {};
if (tsvReferences) {
let referencesArray = Papa__default["default"].parse(tsvReferences, {
delimiter: '\t',
header: true,
}).data;
referencesArray.forEach((r) => {
references[r.label] = r;
});
let { urlReferences } = options;
if (urlReferences) {
let results = await Promise.all([(0, fetchText_js_1.fetchText)(url), (0, fetchText_js_1.fetchText)(urlReferences)]);
return parse(results[0], results[1]);
}
let results = [];
for (let formula of formulas) {
if (tsvReferences) {
// we add references
let refs = formula.references.split(/[ ,]+/);
formula.references = [];
for (let ref of refs) {
formula.references.push(references[ref]);
else {
let result = await (0, fetchText_js_1.fetchText)(url);
return parse(result);
}
async function parse(tsv, tsvReferences) {
let parsed = papaparse_1.default.parse(tsv, {
delimiter: '\t',
header: true,
});
let fields = parsed.meta.fields;
let infoFields = fields.filter((a) => !['mf', 'modif', 'ESI', 'MALDI', 'positive', 'negative'].includes(a));
let formulas = parsed.data;
let references = {};
if (tsvReferences) {
let referencesArray = papaparse_1.default.parse(tsvReferences, {
delimiter: '\t',
header: true,
}).data;
referencesArray.forEach((r) => {
references[r.label] = r;
});
}
}
// we need to calculate all the possibilities
try {
let mfs = await mfGenerator.generateMFs([formula.mf], {
ionizations: formula.modif,
let results = [];
for (let formula of formulas) {
if (tsvReferences) {
// we add references
let refs = formula.references.split(/[ ,]+/);
formula.references = [];
for (let ref of refs) {
formula.references.push(references[ref]);
}
}
// we need to calculate all the possibilities
try {
let mfs = await (0, mf_generator_1.generateMFs)([formula.mf], {
ionizations: formula.modif,
});
for (let mf of mfs) {
mf.info = {};
for (let infoField of infoFields) {
mf.info[infoField] = formula[infoField];
}
if (!formula.ESI &&
!formula.MALDI &&
!formula.positive &&
!formula.negative) {
mf.filter = {
ESI: true,
MALDI: true,
positive: true,
negative: true,
};
}
else {
mf.filter = {
ESI: formula.ESI === 'X',
MALDI: formula.MALDI === 'X',
positive: formula.positive === 'X',
negative: formula.negative === 'X',
};
}
mf.mf = new mf_parser_1.MF(mf.mf).toMF();
results.push(mf);
}
}
catch (e) {
// eslint-disable-next-line no-console
console.warn('Non parsable molecular formula: ', formula.mf, formula.modif, e.toString());
}
}
results = results.filter((a) => {
return a.ms.em !== 0;
});
for (let mf of mfs) {
mf.info = {};
for (let infoField of infoFields) {
mf.info[infoField] = formula[infoField];
}
if (
!formula.ESI &&
!formula.MALDI &&
!formula.positive &&
!formula.negative
) {
mf.filter = {
ESI: true,
MALDI: true,
positive: true,
negative: true,
};
} else {
mf.filter = {
ESI: formula.ESI === 'X',
MALDI: formula.MALDI === 'X',
positive: formula.positive === 'X',
negative: formula.negative === 'X',
};
}
mf.mf = new mfParser.MF(mf.mf).toMF();
results.push(mf);
results.sort((a, b) => {
return a.ms.em - b.ms.em;
});
let uniqueResults = [results[0]];
for (let i = 1; i < results.length; i++) {
if (results[i - 1].ms.em !== results[i].ms.em) {
uniqueResults.push(results[i]);
}
}
} catch (e) {
// eslint-disable-next-line no-console
console.warn(
'Non parsable molecular formula: ',
formula.mf,
formula.modif,
e.toString(),
);
}
return uniqueResults;
}
results = results.filter((a) => {
return a.ms.em !== 0;
});
results.sort((a, b) => {
return a.ms.em - b.ms.em;
});
let uniqueResults = [results[0]];
for (let i = 1; i < results.length; i++) {
if (results[i - 1].ms.em !== results[i].ms.em) {
uniqueResults.push(results[i]);
}
}
return uniqueResults;
}
}
exports.mfFromGoogleSheet = mfFromGoogleSheet;
{
"name": "mf-from-google-sheet",
"version": "3.0.7",
"version": "3.1.0",
"description": "Retrieve and format molecular formula from google sheet",

@@ -24,8 +24,8 @@ "main": "lib/index.js",

"cross-fetch": "^4.0.0",
"mf-generator": "^3.2.1",
"mf-parser": "^3.1.1",
"mf-utilities": "^3.1.1",
"mf-generator": "^3.3.0",
"mf-parser": "^3.2.0",
"mf-utilities": "^3.2.0",
"papaparse": "^5.4.1"
},
"gitHead": "b9f99ec6f05ce6b0034d35f4ae0452ae653f90c2"
"gitHead": "28dae91d3b42556a23097ee08acfe4061f276ed0"
}
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