mf-generator
Advanced tools
Comparing version 0.8.0 to 0.9.1
{ | ||
"name": "mf-generator", | ||
"version": "0.8.0", | ||
"version": "0.9.1", | ||
"description": "", | ||
@@ -21,9 +21,9 @@ "main": "src/index.js", | ||
"dependencies": { | ||
"chemical-elements": "^0.7.0", | ||
"mf-finder": "^0.8.0", | ||
"mf-matcher": "^0.8.0", | ||
"mf-parser": "^0.8.0", | ||
"mf-utilities": "^0.8.0", | ||
"chemical-elements": "^0.9.1", | ||
"mf-finder": "^0.9.1", | ||
"mf-matcher": "^0.9.1", | ||
"mf-parser": "^0.9.1", | ||
"mf-utilities": "^0.9.1", | ||
"sum-object-keys": "^1.0.2" | ||
} | ||
} |
@@ -5,3 +5,3 @@ 'use strict'; | ||
test('generateMFs from array of array with comment', function() { | ||
test('generateMFs from array of array with comment', function () { | ||
var mfsArray = [['C', 'H$YY'], [], [''], ['Cl', 'Br$XX']]; | ||
@@ -14,9 +14,9 @@ var result = generateMFs(mfsArray); | ||
test('generateMFs from array of string with empty', function() { | ||
test('generateMFs from array of string with empty', function () { | ||
var mfsArray = ['C,H,', 'Cl,Br']; | ||
var result = generateMFs(mfsArray).map(entry => entry.mf); | ||
expect(result).toEqual(['Cl', 'HCl', 'CCl', 'Br', 'HBr', 'CBr']); | ||
var result = generateMFs(mfsArray).map((entry) => entry.mf); | ||
expect(result).toStrictEqual(['Cl', 'HCl', 'CCl', 'Br', 'HBr', 'CBr']); | ||
}); | ||
test('generateMFs from array of string with comment', function() { | ||
test('generateMFs from array of string with comment', function () { | ||
var mfsArray = ['C.H.O', '+,++', ['Cl', 'Br$XX']]; | ||
@@ -28,28 +28,24 @@ var result = generateMFs(mfsArray).sort((a, b) => a.em - b.em); | ||
test( | ||
'generateMFs from array of string with some range and non range', | ||
function() { | ||
var mfsArray = ['CN0-2']; | ||
var result = generateMFs(mfsArray); | ||
expect(result[0].mf).toBe('C'); | ||
expect(result[1].mf).toBe('CN'); | ||
expect(result[2].mf).toBe('CN2'); | ||
expect(result).toHaveLength(3); | ||
}); | ||
test('generateMFs from array of string with some range and non range', function () { | ||
var mfsArray = ['CN0-2']; | ||
var result = generateMFs(mfsArray); | ||
expect(result[0].mf).toBe('C'); | ||
expect(result[1].mf).toBe('CN'); | ||
expect(result[2].mf).toBe('CN2'); | ||
expect(result).toHaveLength(3); | ||
}); | ||
test( | ||
'From array of string with some range and non range CN0-2O00-1K', | ||
function() { | ||
var mfsArray = ['CN0-2O00-1K']; | ||
var result = generateMFs(mfsArray); | ||
expect(result[0].mf).toBe('CK'); | ||
expect(result[1].mf).toBe('CKN'); | ||
expect(result[2].mf).toBe('CKO'); | ||
expect(result[3].mf).toBe('CKN2'); | ||
expect(result[4].mf).toBe('CKNO'); | ||
expect(result[5].mf).toBe('CKN2O'); | ||
expect(result).toHaveLength(6); | ||
}); | ||
test('From array of string with some range and non range CN0-2O00-1K', function () { | ||
var mfsArray = ['CN0-2O00-1K']; | ||
var result = generateMFs(mfsArray); | ||
expect(result[0].mf).toBe('CK'); | ||
expect(result[1].mf).toBe('CKN'); | ||
expect(result[2].mf).toBe('CKO'); | ||
expect(result[3].mf).toBe('CKN2'); | ||
expect(result[4].mf).toBe('CKNO'); | ||
expect(result[5].mf).toBe('CKN2O'); | ||
expect(result).toHaveLength(6); | ||
}); | ||
test('From array of string with some range and non range NaK0-2', function() { | ||
test('From array of string with some range and non range NaK0-2', function () { | ||
var mfsArray = ['NaK0-2']; | ||
@@ -63,19 +59,17 @@ var result = generateMFs(mfsArray); | ||
test( | ||
'From array of string with some range and non range C(Me(N2))0-2(CH3)0-1K', | ||
function() { | ||
var mfsArray = ['C(Me(N2))0-2(CH3)0-1K']; | ||
var result = generateMFs(mfsArray, {canonizeMF: false, uniqueMFs: false}); | ||
expect(result[0].mf).toBe('CK'); | ||
expect(result[1].mf).toBe('C(CH3)K'); | ||
expect(result[2].mf).toBe('C(Me(N2))K'); | ||
expect(result[3].mf).toBe('C(Me(N2))(CH3)K'); | ||
expect(result[4].mf).toBe('C(Me(N2))2K'); | ||
expect(result[5].mf).toBe('C(Me(N2))2(CH3)K'); | ||
expect(result).toHaveLength(6); | ||
}); | ||
test('From array of string with some range and non range C(Me(N2))0-2(CH3)0-1K', function () { | ||
var mfsArray = ['C(Me(N2))0-2(CH3)0-1K']; | ||
var result = generateMFs(mfsArray, { canonizeMF: false, uniqueMFs: false }); | ||
expect(result[0].mf).toBe('CK'); | ||
expect(result[1].mf).toBe('C(CH3)K'); | ||
expect(result[2].mf).toBe('C(Me(N2))K'); | ||
expect(result[3].mf).toBe('C(Me(N2))(CH3)K'); | ||
expect(result[4].mf).toBe('C(Me(N2))2K'); | ||
expect(result[5].mf).toBe('C(Me(N2))2(CH3)K'); | ||
expect(result).toHaveLength(6); | ||
}); | ||
test('From array of string with some range', function() { | ||
test('From array of string with some range', function () { | ||
var mfsArray = ['C1-3N0-2Cl0-0BrO1-1.C2-3H3-4', ['C', 'O']]; | ||
var result = generateMFs(mfsArray, {canonizeMF: true}); | ||
var result = generateMFs(mfsArray, { canonizeMF: true }); | ||
expect(result[0].mf).toBe('C3H3'); | ||
@@ -85,3 +79,3 @@ expect(result).toHaveLength(26); | ||
test('From array of string chem em and msem', function() { | ||
test('From array of string chem em and msem', function () { | ||
var mfsArray = ['C0-2.O', ['+', '(-)', '++', '(--)']]; | ||
@@ -95,3 +89,3 @@ | ||
test('From array of string to large array', function() { | ||
test('From array of string to large array', function () { | ||
var mfsArray = ['C0-100', 'O0-100']; | ||
@@ -102,34 +96,37 @@ var result = generateMFs(mfsArray); | ||
test('From array of string to large array and filter', function() { | ||
test('From array of string to large array and filter', function () { | ||
var mfsArray = ['C0-100', 'O0-100']; | ||
var result = generateMFs(mfsArray, {filter: {minEM: 0.1, maxEM: 13}}); | ||
var result = generateMFs(mfsArray, { filter: { minEM: 0.1, maxEM: 13 } }); | ||
expect(result).toHaveLength(1); | ||
}); | ||
test('From array of string to large array and filter unsaturation', function() { | ||
test('From array of string to large array and filter unsaturation', function () { | ||
var mfsArray = ['C0-100', 'H0-100']; | ||
var result = | ||
generateMFs(mfsArray, {filter: {unsaturation: {min: 0, max: 1}}}); | ||
var result = generateMFs(mfsArray, { | ||
filter: { unsaturation: { min: 0, max: 1 } } | ||
}); | ||
expect(result).toHaveLength(151); | ||
}); | ||
test( | ||
'From array of string to large array and filter unsaturation min/max and integer unsaturation', | ||
function() { | ||
var mfsArray = ['C0-100', 'H0-100']; | ||
var result = generateMFs( | ||
mfsArray, | ||
{filter: {unsaturation: {min: 0, max: 1, onlyInteger: true}}}); | ||
expect(result).toHaveLength(101); | ||
}); | ||
test('From array of string to large array and filter unsaturation min/max and integer unsaturation', function () { | ||
var mfsArray = ['C0-100', 'H0-100']; | ||
var result = generateMFs(mfsArray, { | ||
filter: { unsaturation: { min: 0, max: 1, onlyInteger: true } } | ||
}); | ||
expect(result).toHaveLength(101); | ||
}); | ||
test('Combine with ionizations', function() { | ||
var result = generateMFs(['C1-2'], {ionizations: 'H+,Na+,H++'}); | ||
expect(result.map(a => a.ms.em).sort((a, b) => a - b)).toEqual([ | ||
6.50336393620593, 12.503363936205929, 13.00727645232093, 25.00727645232093, | ||
34.989220702090925, 46.989220702090925 | ||
test('Combine with ionizations', function () { | ||
var result = generateMFs(['C1-2'], { ionizations: 'H+,Na+,H++' }); | ||
expect(result.map((a) => a.ms.em).sort((a, b) => a - b)).toStrictEqual([ | ||
6.50336393620593, | ||
12.503363936205929, | ||
13.00727645232093, | ||
25.00727645232093, | ||
34.989220702090925, | ||
46.989220702090925 | ||
]); | ||
}); | ||
test('Strange comments', function() { | ||
test('Strange comments', function () { | ||
var mfsArray = ['C$1>10', 'O$D2>20']; | ||
@@ -141,14 +138,14 @@ var result = generateMFs(mfsArray); | ||
test('Check info', function() { | ||
test('Check info', function () { | ||
var mfsArray = ['C', '', 'C5(C)2']; | ||
var result = generateMFs(mfsArray, {canonizeMF: true})[0]; | ||
expect(result).toEqual({ | ||
var result = generateMFs(mfsArray, { canonizeMF: true })[0]; | ||
expect(result).toStrictEqual({ | ||
mf: 'C8', | ||
em: 96, | ||
ms: {em: 0, charge: 0, ionization: ''}, | ||
ms: { em: 0, charge: 0, ionization: '' }, | ||
mw: 96.08588717388199, | ||
charge: 0, | ||
ionization: {mf: '', charge: 0, em: 0}, | ||
ionization: { mf: '', charge: 0, em: 0 }, | ||
parts: ['C', undefined, 'C5(C)2'], | ||
atoms: {C: 8}, | ||
atoms: { C: 8 }, | ||
unsaturation: 9 | ||
@@ -158,5 +155,5 @@ }); | ||
test('generateMFs from array of array with negative ionisation', function() { | ||
test('generateMFs from array of array with negative ionisation', function () { | ||
var mfsArray = ['H2', ['Cl', 'Br']]; | ||
var result = generateMFs(mfsArray, {ionizations: '(H+)-2'}); | ||
var result = generateMFs(mfsArray, { ionizations: '(H+)-2' }); | ||
expect(result[0].ms.em).toBe(17.484974920909067); | ||
@@ -167,8 +164,11 @@ expect(result[1].ms.em).toBe(39.45971737990907); | ||
test('generateMFs from array of array with negative ionisation', function() { | ||
test('generateMFs from array with charge and range', function () { | ||
var mfsArray = ['(H+)2-3']; | ||
var result = generateMFs(mfsArray, {ionizations: '(H+)-2,Na+'}); | ||
expect(result.map(a => a.ms.em).sort((a, b) => a - b)).toEqual([ | ||
0, 1.0072764523209299, 6.50276251476343, 8.334591202244264 | ||
var result = generateMFs(mfsArray, { ionizations: '(H+)-2,Na+' }); | ||
expect(result.map((a) => a.ms.em).sort((a, b) => a - b)).toStrictEqual([ | ||
0, | ||
1.0072764523209299, | ||
6.50276251476343, | ||
8.334591202244264 | ||
]); | ||
}); |
@@ -42,4 +42,5 @@ 'use strict'; | ||
if (!Array.isArray(keys)) | ||
if (!Array.isArray(keys)) { | ||
throw new Error('You need to specify an array of strings or arrays'); | ||
} | ||
@@ -104,6 +105,6 @@ // we allow String delimited by ". , or ;" instead of an array | ||
var uniqueMFsObject = {}; | ||
results.forEach(r => { | ||
results.forEach((r) => { | ||
uniqueMFsObject[r.mf + r.ionization.mf] = r; | ||
}); | ||
results = Object.keys(uniqueMFsObject).map(k => uniqueMFsObject[k]); | ||
results = Object.keys(uniqueMFsObject).map((k) => uniqueMFsObject[k]); | ||
} | ||
@@ -176,4 +177,6 @@ results.sort((a, b) => a.em - b.em); | ||
let match = matcher(result, filter); | ||
if (!match) return; | ||
result.ms = match; | ||
result.ms = match.ms; | ||
result.ionization = match.ionization; | ||
result.parts = []; | ||
@@ -198,3 +201,2 @@ result.mf = ''; | ||
} | ||
if (comments.length > 0) { | ||
@@ -209,3 +211,3 @@ result.comment = comments.join(' '); | ||
var results = []; | ||
var parts = string.split(/([0-9]+-[0-9]+)/).filter(v => v); // remove empty parts | ||
var parts = string.split(/([0-9]+-[0-9]+)/).filter((v) => v); // remove empty parts | ||
let position = -1; | ||
@@ -212,0 +214,0 @@ var mfs = []; |
418
16688
+ Addedatom-sorter@0.9.1(transitive)
+ Addedchemical-elements@0.9.1(transitive)
+ Addedchemical-groups@0.9.1(transitive)
+ Addedmf-finder@0.9.1(transitive)
+ Addedmf-matcher@0.9.1(transitive)
+ Addedmf-parser@0.9.1(transitive)
+ Addedmf-utilities@0.9.1(transitive)
- Removedatom-sorter@0.8.0(transitive)
- Removedchemical-elements@0.7.0(transitive)
- Removedchemical-groups@0.8.0(transitive)
- Removedmf-finder@0.8.0(transitive)
- Removedmf-matcher@0.8.0(transitive)
- Removedmf-parser@0.8.0(transitive)
- Removedmf-utilities@0.8.0(transitive)
Updatedchemical-elements@^0.9.1
Updatedmf-finder@^0.9.1
Updatedmf-matcher@^0.9.1
Updatedmf-parser@^0.9.1
Updatedmf-utilities@^0.9.1