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

mf-parser

Package Overview
Dependencies
Maintainers
6
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mf-parser - npm Package Compare versions

Comparing version 0.5.0 to 0.5.1

src/__tests__/getIsotopesInfo.js

4

package.json
{
"name": "mf-parser",
"version": "0.5.0",
"version": "0.5.1",
"description": "",

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

"atom-sorter": "^0.5.0",
"chemical-elements": "^0.5.0"
"chemical-elements": "^0.5.1"
}
}

@@ -31,4 +31,9 @@ # mf-parser

## Unsaturation
Unsaturation is based on Pretsch
http://pubs.acs.org/doi/pdf/10.1021/ci000135o
## License

@@ -35,0 +40,0 @@

@@ -5,2 +5,34 @@ 'use strict';

test('MF of C', () => {
var mf = new MF('C');
var parts = mf.toParts();
expect(parts).toEqual(
[[
{ kind: 'atom', value: 'C', multiplier: 1 },
]]
);
var newMF = mf.toMF();
expect(newMF).toBe('C');
mf.canonize();
let html = mf.toHtml();
expect(html).toBe('C');
let info = mf.getInfo();
expect(info).toEqual({
monoisotopicMass: 12,
mass: 12.010735896735248,
charge: 0,
unsaturation: 2,
mf: 'C',
atoms: {
C: 1
}
});
});
test('MF of Et3N.HCl', () => {

@@ -27,3 +59,3 @@ var mf = new MF('Et3N.HCl');

expect(html).toBe('C<sub>6</sub>H<sub>15</sub>N<sub>1</sub> • H<sub>1</sub>Cl<sub>1</sub>');
expect(html).toBe('C<sub>6</sub>H<sub>15</sub>N•HCl');

@@ -135,3 +167,3 @@ let info = mf.getInfo();

mf: 'O4S(-2)',
unsaturation: 2,
unsaturation: 4,
atoms: { O: 4, S: 1 } }

@@ -141,2 +173,13 @@ );

test('test unsaturation with charges', () => {
expect((new MF('CH4')).getInfo().unsaturation).toBe(0);
expect((new MF('C10H22O')).getInfo().unsaturation).toBe(0);
expect((new MF('H+')).getInfo().unsaturation).toBe(0);
expect((new MF('CO3(--)')).getInfo().unsaturation).toBe(3);
expect((new MF('HO(-)')).getInfo().unsaturation).toBe(1);
expect((new MF('F(-)')).getInfo().unsaturation).toBe(1);
expect((new MF('Na+')).getInfo().unsaturation).toBe(0);
expect((new MF('NH4+')).getInfo().unsaturation).toBe(-1);
});
test('MF of NC[13C][15N]2NN2', () => {

@@ -143,0 +186,0 @@ var mf = new MF('NC[13C][15N]2NN2');

@@ -13,3 +13,8 @@ 'use strict';

'[13C]': [{ kind: 'isotope', value: { atom: 'C', isotope: 13 } }],
'[2H]': [{ kind: 'isotope', value: { atom: 'H', isotope: 2 } }],
'C+': [{ kind: 'atom', value: 'C' }, { kind: 'charge', value: 1 }],
'C-': [{ kind: 'atom', value: 'C' }, { kind: 'charge', value: -1 }],
'C-H': [{ kind: 'atom', value: 'C' }, { kind: 'charge', value: -1 }, { kind: 'atom', value: 'H' }],
'C++': [{ kind: 'atom', value: 'C' }, { kind: 'charge', value: 2 }],
'C--': [{ kind: 'atom', value: 'C' }, { kind: 'charge', value: -2 }],
'C2+': [{ kind: 'atom', value: 'C' }, { kind: 'multiplier', value: 2 }, { kind: 'charge', value: 1 }],

@@ -20,2 +25,3 @@ 'C(2+)': [{ kind: 'atom', value: 'C' }, { kind: 'charge', value: 2 }],

'C(2-)': [{ kind: 'atom', value: 'C' }, { kind: 'charge', value: -2 }],
'C(-2)': [{ kind: 'atom', value: 'C' }, { kind: 'charge', value: -2 }],
'C(--)': [{ kind: 'atom', value: 'C' }, { kind: 'charge', value: -2 }],

@@ -26,3 +32,2 @@ '(H+)': [{ kind: 'openingParenthesis', value: '(' }, { kind: 'atom', value: 'H' }, { kind: 'charge', value: 1 }, { kind: 'closingParenthesis', value: ')' }],

'C(-1)2(-3)3': [{ kind: 'atom', value: 'C' }, { kind: 'charge', value: -1 }, { kind: 'multiplier', value: 2 }, { kind: 'charge', value: -3 }, { kind: 'multiplier', value: 3 }],
'C(-2)': [{ kind: 'atom', value: 'C' }, { kind: 'charge', value: -2 }],
'C(H-2)': [{ kind: 'atom', value: 'C' }, { kind: 'openingParenthesis', value: '(' }, { kind: 'atom', value: 'H' }, { kind: 'multiplier', value: -2 }, { kind: 'closingParenthesis', value: ')' }],

@@ -29,0 +34,0 @@ 'H.Cl': [{ kind: 'atom', value: 'H' }, { kind: 'salt', value: '.' }, { kind: 'atom', value: 'Cl' }],

@@ -9,2 +9,3 @@ 'use strict';

const getInfo = require('./util/getInfo');
const getIsotopesInfo = require('./util/getIsotopesInfo');
const partsToMF = require('./util/partsToMF');

@@ -52,2 +53,13 @@ const partsToDisplay = require('./util/partsToDisplay');

/**
* Returns an array with each atom and isotopic composition
*/
getIsotopesInfo(options = {}) {
if (!this.cache.isotopesInfo) {
this.toParts();
this.cache.isotopesInfo = getIsotopesInfo(this.cache.parts, options);
}
return this.cache.isotopesInfo;
}
/**
* Get a canonized MF

@@ -54,0 +66,0 @@ */

@@ -17,3 +17,3 @@ 'use strict';

class MFParser {
parse(mf) {
parse(mf = '') {
this.mf = mf;

@@ -89,2 +89,5 @@ this.i = 0;

this.result.push({ kind: Kind.CHARGE, value: charge });
} else if (char === '-') { // charge not in parenthesis
let charge = this.getNonParenthesisCharge(ascii);
this.result.push({ kind: Kind.CHARGE, value: charge });
} else if (char === '$') { // it is a comment after

@@ -91,0 +94,0 @@ this.result.push({ kind: Kind.COMMENT, value: this.mf.substring(this.i + 1) });

@@ -11,14 +11,4 @@ 'use strict';

const isotopes = {};
Object.keys(elements).forEach((key) => {
let e = elements[key];
const isotopes = require('./getIsotopesObject');
e.monoisotopicMass = getMonoisotopicMass(e);
e.isotopes.forEach((i) => {
isotopes[i.nominal + key] = {
abundance: i.abundance,
mass: i.mass
};
});
});

@@ -103,3 +93,5 @@ /**

currentPart.charge = line.value;
unsaturation += line.value;
if (validUnsaturation) {
unsaturation -= line.value;
}
break;

@@ -158,12 +150,1 @@ default:

function getMonoisotopicMass(element) {
var monoisotopicMass;
var maxAbundance = 0;
for (let isotope of element.isotopes) {
if (isotope.abundance > maxAbundance) {
maxAbundance = isotope.abundance;
monoisotopicMass = isotope.mass;
}
}
return monoisotopicMass;
}

@@ -11,3 +11,3 @@ 'use strict';

module.exports = function partToMF(part) {
module.exports = function partToAtoms(part) {
var atoms = {};

@@ -14,0 +14,0 @@ for (let line of part) {

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

case Kind.MULTIPLIER:
result = {
kind: Format.SUBSCRIPT,
value: String(line.value)
};
results.push(result);
if (line.value !== 1) {
result = {
kind: Format.SUBSCRIPT,
value: String(line.value)
};
results.push(result);
}
break;

@@ -25,0 +27,0 @@ case Kind.MULTIPLIER_RANGE:

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