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

mf-generator

Package Overview
Dependencies
Maintainers
2
Versions
94
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mf-generator - npm Package Compare versions

Comparing version 1.3.12 to 1.3.13

6

package.json
{
"name": "mf-generator",
"version": "1.3.12",
"version": "1.3.13",
"description": "",

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

"chemical-elements": "^1.2.0",
"mf-finder": "^1.2.0",
"mf-finder": "^1.2.1",
"mf-matcher": "^1.1.19",

@@ -29,3 +29,3 @@ "mf-parser": "^1.4.0",

},
"gitHead": "0ccc601b2ba051652963fad05479902943d7feaf"
"gitHead": "0b932f49c82fd9fb2ef0804c1430b1499426ef95"
}

@@ -6,5 +6,5 @@ 'use strict';

describe('generateMFs', () => {
it('from array of array with comment', () => {
it('from array of array with comment', async () => {
let mfsArray = [['C', 'H$YY'], [], [''], ['Cl', 'Br$XX']];
let result = generateMFs(mfsArray);
let result = await generateMFs(mfsArray);
expect(result[0].mf).toBe('HCl');

@@ -15,11 +15,13 @@ expect(result[0].comment).toBe('YY');

it('from array of string with empty', () => {
it('from array of string with empty', async () => {
let mfsArray = ['C,H,', 'Cl,Br'];
let result = generateMFs(mfsArray).map((entry) => entry.mf);
let result = (await generateMFs(mfsArray)).map((entry) => entry.mf);
expect(result).toStrictEqual(['Cl', 'HCl', 'CCl', 'Br', 'HBr', 'CBr']);
});
it('from array of string with comment', () => {
it('from array of string with comment', async () => {
let mfsArray = ['C.H.O', '+,++', ['Cl', 'Br$XX']];
let result = generateMFs(mfsArray).sort((a, b) => a.ms.em - b.ms.em);
let result = (await generateMFs(mfsArray)).sort(
(a, b) => a.ms.em - b.ms.em,
);
expect(result[0].mf).toBe('HCl(+2)');

@@ -29,5 +31,5 @@ expect(result).toHaveLength(12);

it('from array of string with some range and non range', () => {
it('from array of string with some range and non range', async () => {
let mfsArray = ['CN0-2'];
let result = generateMFs(mfsArray);
let result = await generateMFs(mfsArray);
expect(result[0].mf).toBe('C');

@@ -39,5 +41,5 @@ expect(result[1].mf).toBe('CN');

it('From array of string with some range and non range CN0-2O00-1K', () => {
it('From array of string with some range and non range CN0-2O00-1K', async () => {
let mfsArray = ['CN0-2O00-1K'];
let result = generateMFs(mfsArray);
let result = await generateMFs(mfsArray);
expect(result[0].mf).toBe('CK');

@@ -52,5 +54,5 @@ expect(result[1].mf).toBe('CKN');

it('From array of string with some range and non range NaK0-2', () => {
it('From array of string with some range and non range NaK0-2', async () => {
let mfsArray = ['NaK0-2'];
let result = generateMFs(mfsArray);
let result = await generateMFs(mfsArray);
expect(result[0].mf).toBe('Na');

@@ -62,5 +64,8 @@ expect(result[1].mf).toBe('KNa');

it('From array of string with some range and non range C(Me(N2))0-2(CH3)0-1K', () => {
it('From array of string with some range and non range C(Me(N2))0-2(CH3)0-1K', async () => {
let mfsArray = ['C(Me(N2))0-2(CH3)0-1K'];
let result = generateMFs(mfsArray, { canonizeMF: false, uniqueMFs: false });
let result = await generateMFs(mfsArray, {
canonizeMF: false,
uniqueMFs: false,
});
expect(result[0].mf).toBe('CK');

@@ -75,5 +80,5 @@ expect(result[1].mf).toBe('C(CH3)K');

it('From array of string with some range', () => {
it('From array of string with some range', async () => {
let mfsArray = ['C1-3N0-2Cl0-0BrO1-1.C2-3H3-4', ['C', 'O']];
let result = generateMFs(mfsArray, { canonizeMF: true });
let result = await generateMFs(mfsArray, { canonizeMF: true });
expect(result[0].mf).toBe('C3H3');

@@ -83,6 +88,6 @@ expect(result).toHaveLength(26);

it('From array of string chem em and msem', () => {
it('From array of string chem em and msem', async () => {
let mfsArray = ['C0-2.O', ['+', '(-)', '++', '(--)']];
let result = generateMFs(mfsArray);
let result = await generateMFs(mfsArray);
expect(result[0].mf).toMatch(/^(.*)$/);

@@ -93,15 +98,17 @@ expect(result[0].charge).not.toBe(0);

it('From array of string to large array', () => {
it('From array of string to large array', async () => {
let mfsArray = ['C0-100', 'O0-100'];
let result = generateMFs(mfsArray);
let result = await generateMFs(mfsArray);
expect(result).toHaveLength(101 * 101);
});
it('From array of string to large array and filter', () => {
it('From array of string to large array and filter', async () => {
let mfsArray = ['C0-100', 'O0-100'];
let result = generateMFs(mfsArray, { filter: { minEM: 0.1, maxEM: 13 } });
let result = await generateMFs(mfsArray, {
filter: { minEM: 0.1, maxEM: 13 },
});
expect(result).toHaveLength(1);
});
it('filterFct', () => {
it('filterFct', async () => {
let mfsArray = [

@@ -111,3 +118,3 @@ { name: 'C', value: 'C0-5' },

];
let result = generateMFs(mfsArray, {
let result = await generateMFs(mfsArray, {
ionizations: '++',

@@ -119,5 +126,5 @@ filterFct: 'C<D && (C+D)===3 && atoms.O>=2',

it('From array of string to large array and filter unsaturation', () => {
it('From array of string to large array and filter unsaturation', async () => {
let mfsArray = ['C0-100', 'H0-100'];
let result = generateMFs(mfsArray, {
let result = await generateMFs(mfsArray, {
filter: { unsaturation: { min: 0, max: 1 } },

@@ -128,5 +135,5 @@ });

it('Filter callback', () => {
it('Filter callback', async () => {
let mfsArray = ['C0-4', 'H0-4'];
let result = generateMFs(mfsArray, {
let result = await generateMFs(mfsArray, {
filter: {

@@ -142,5 +149,5 @@ callback: (entry) => {

it('From array of string to large array and filter unsaturation min/max and integer unsaturation', () => {
it('From array of string to large array and filter unsaturation min/max and integer unsaturation', async () => {
let mfsArray = ['C0-100', 'H0-100'];
let result = generateMFs(mfsArray, {
let result = await generateMFs(mfsArray, {
filter: { unsaturation: { min: 0, max: 1, onlyInteger: true } },

@@ -151,4 +158,4 @@ });

it('Combine with ionizations', () => {
let result = generateMFs(['C1-2'], { ionizations: 'H+,Na+,H++' });
it('Combine with ionizations', async () => {
let result = await generateMFs(['C1-2'], { ionizations: 'H+,Na+,H++' });
expect(result.map((a) => a.ms.em).sort((a, b) => a - b)).toStrictEqual([

@@ -160,5 +167,5 @@ 6.50336393620593, 12.503363936205929, 13.00727645232093,

it('Strange comments', () => {
it('Strange comments', async () => {
let mfsArray = ['C$1>10', 'O$D2>20'];
let result = generateMFs(mfsArray);
let result = await generateMFs(mfsArray);
expect(result[0].mf).toBe('CO');

@@ -168,5 +175,5 @@ expect(result[0].comment).toBe('1>10 D2>20');

it('Check info', () => {
it('Check info', async () => {
let mfsArray = ['C', '', 'C5(C)2'];
let result = generateMFs(mfsArray, { canonizeMF: true })[0];
let result = (await generateMFs(mfsArray, { canonizeMF: true }))[0];
expect(result).toMatchInlineSnapshot(`

@@ -201,5 +208,5 @@ Object {

it('from array of array with negative ionisation', () => {
it('from array of array with negative ionisation', async () => {
let mfsArray = ['H2', ['Cl', 'Br']];
let result = generateMFs(mfsArray, { ionizations: '(H+)-2' });
let result = await generateMFs(mfsArray, { ionizations: '(H+)-2' });
expect(result[0].ms.em).toBe(17.484974920909067);

@@ -210,5 +217,5 @@ expect(result[1].ms.em).toBe(39.45971737990907);

it('from array with charge and range', () => {
it('from array with charge and range', async () => {
let mfsArray = ['(H+)2-3'];
let result = generateMFs(mfsArray, { ionizations: '(H+)-2,Na+' });
let result = await generateMFs(mfsArray, { ionizations: '(H+)-2,Na+' });
expect(result.map((a) => a.ms.em).sort((a, b) => a - b)).toStrictEqual([

@@ -219,5 +226,5 @@ 0, 1.0072764523209299, 6.50276251476343, 8.334591202244264,

it('from array with target masses', () => {
it('from array with target masses', async () => {
let mfsArray = ['C1-100'];
let result = generateMFs(mfsArray, {
let result = await generateMFs(mfsArray, {
ionizations: '+,++',

@@ -233,5 +240,5 @@ filter: {

it('estimate', () => {
it('estimate', async () => {
let mfsArray = ['C1-100', 'Cl,Br,F1-8'];
let result = generateMFs(mfsArray, {
let result = await generateMFs(mfsArray, {
ionizations: '+,++',

@@ -248,5 +255,5 @@ estimate: true,

it('from array with charge and negative range', () => {
it('from array with charge and negative range', async () => {
let mfsArray = ['(H+)-2--4'];
let result = generateMFs(mfsArray);
let result = await generateMFs(mfsArray);
expect(result.map((a) => a.ms.em).sort((a, b) => a - b)).toStrictEqual([

@@ -257,3 +264,3 @@ -1.0072764523209299, -1.0072764523209299, -1.0072764523209299,

it('with links', () => {
it('with links', async () => {
const mfsArray = [

@@ -264,12 +271,26 @@ ['C#1', 'C#1C', 'C#2C'],

let result = generateMFs(mfsArray, { links: { filter: true } }).map(
let result = (await generateMFs(mfsArray, { links: { filter: true } })).map(
(item) => item.mf,
);
expect(result).toStrictEqual(['CH', 'CH2', 'C2H', 'C2H2']);
result = generateMFs(mfsArray, {
uniqueMFs: false,
links: { filter: true },
}).map((item) => item.mf);
result = (
await generateMFs(mfsArray, {
uniqueMFs: false,
links: { filter: true },
})
).map((item) => item.mf);
expect(result).toStrictEqual(['CH', 'CH2', 'C2H', 'C2H', 'C2H2']);
});
it('with onStep', async () => {
let mfsArray = ['C,H', 'Cl,Br'];
let counter = 0;
await generateMFs(mfsArray, {
onStep: () => {
counter++;
},
});
expect(counter).toBe(3);
});
});

@@ -18,5 +18,7 @@ 'use strict';

* @param {boolean} [options.estimate=false] - estimate the number of MF without filters
* @param {boolean} [canonizeMF=true] - Canonize molecular formula
* @param {boolean} [uniqueMFs=true] - Force canonization and make MF unique
* @param {string} [ionizations=''] - Comma separated list of ionizations (to charge the molecule)
* @param {boolean} [options.canonizeMF=true] - Canonize molecular formula
* @param {boolean} [options.uniqueMFs=true] - Force canonization and make MF unique
* @param {string} [options.ionizations=''] - Comma separated list of ionizations (to charge the molecule)
* @param {function} [options.onStep] - Callback to do after each step
* @param {object} [options.filter={}] - Minimal monoisotopic mass
* @param {number} [options.filter.minMass=0] - Minimal monoisotopic mass

@@ -35,4 +37,4 @@ * @param {number} [options.filter.maxMass=+Infinity] - Maximal monoisotopic mass

* @param {number} [options.filter.unsaturation.max=+Infinity] - Maximal unsaturation
* @param {number} [options.filter.unsaturation.onlyInteger=false] - Integer unsaturation
* @param {number} [options.filter.unsaturation.onlyNonInteger=false] - Non integer unsaturation
* @param {boolean} [options.filter.unsaturation.onlyInteger=false] - Integer unsaturation
* @param {boolean} [options.filter.unsaturation.onlyNonInteger=false] - Non integer unsaturation
* @param {object} [options.filter.atoms] - object of atom:{min, max}

@@ -43,9 +45,9 @@ * @param {function} [options.filter.callback] - a function to filter the MF

* @param {boolean} [options.links.filter] We filter all the MF that do not match the '*X'
* @returns {Array}
* @returns {Promise}
*/
module.exports = function generateMFs(keys, options = {}) {
module.exports = async function generateMFs(keys, options = {}) {
options = { ...options };
let { limit = 100000, uniqueMFs = true, estimate = false } = options;
let { limit = 100000, uniqueMFs = true, estimate = false, onStep } = options;

@@ -126,2 +128,3 @@ options.filterFctVariables = {};

if (currents[position] < sizes[position]) {
if (onStep) await onStep(evolution);
evolution++;

@@ -128,0 +131,0 @@ appendResult(results, currents, keys, options);

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