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.9.1 to 0.12.0

src/__tests__/ensureCase.test.js

12

package.json
{
"name": "mf-parser",
"version": "0.9.1",
"version": "0.12.0",
"description": "",

@@ -21,10 +21,10 @@ "main": "src/index.js",

"dependencies": {
"atom-sorter": "^0.9.1",
"chemical-elements": "^0.9.1",
"chemical-groups": "^0.9.1",
"mf-utilities": "^0.9.1"
"atom-sorter": "^0.12.0",
"chemical-elements": "^0.12.0",
"chemical-groups": "^0.12.0"
},
"devDependencies": {
"jest-matcher-deep-close-to": "^1.3.0"
}
},
"gitHead": "aa2e6571c5f7121dda616b7d6920b7a653a8f9c7"
}

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

var MF = require('../MF');
let MF = require('../MF');

@@ -13,3 +13,3 @@ test('getEA', () => {

[{ element: 'C', mass: 12.01, ratio: 1 }],
3
3,
);

@@ -27,3 +27,3 @@

[{ element: 'C', mass: 13.0033, ratio: 1 }],
3
3,
);

@@ -33,3 +33,3 @@

[{ element: 'C', mass: 125.016, ratio: 1 }],
3
3,
);

@@ -40,6 +40,6 @@

{ element: 'C', mass: 24.02147, ratio: 0.7988 },
{ element: 'H', mass: 6.0476, ratio: 0.20112 }
{ element: 'H', mass: 6.0476, ratio: 0.20112 },
],
3
3,
);
});
'use strict';
var MFParser = require('../index');
let MFParser = require('../index');
test('parseToHtml', () => {
var result = MFParser.parseToHtml('SO4(--)');
expect(result).toBe('SO<span style="flex-direction: column;display: inline-flex;justify-content: center;text-align: left;vertical-align: middle;"><sup style="line-height: 1; font-size: 70%">-2</sup><sub style="line-height: 1; font-size: 70%">4</sub></span>');
let result = MFParser.parseToHtml('SO4(--)');
expect(result).toBe(
'SO<span style="flex-direction: column;display: inline-flex;justify-content: center;text-align: left;vertical-align: middle;"><sup style="line-height: 1; font-size: 70%">-2</sup><sub style="line-height: 1; font-size: 70%">4</sub></span>',
);
});
'use strict';
var MF = require('../MF');
let MF = require('../MF');
test('MF of C', () => {
var mf = new MF('C');
var parts = mf.toParts();
let mf = new MF('C');
let parts = mf.toParts();
expect(parts).toStrictEqual([[{ kind: 'atom', value: 'C', multiplier: 1 }]]);
var newMF = mf.toMF();
let newMF = mf.toMF();
expect(newMF).toBe('C');

@@ -27,3 +27,3 @@

mf: 'C',
atoms: { C: 1 }
atoms: { C: 1 },
});

@@ -33,6 +33,6 @@ });

test('MF of D', () => {
var mfD = new MF('D');
var infoD = mfD.getInfo();
var mf2H = new MF('[2H]');
var info2H = mf2H.getInfo();
let mfD = new MF('D');
let infoD = mfD.getInfo();
let mf2H = new MF('[2H]');
let info2H = mf2H.getInfo();
expect(infoD).toStrictEqual(info2H);

@@ -45,3 +45,3 @@ expect(infoD).toStrictEqual({

monoisotopicMass: 2.01410177812,
unsaturation: 0.5
unsaturation: 0.5,
});

@@ -51,4 +51,4 @@ });

test('MF of Et3N.HCl', () => {
var mf = new MF('Et3N.HCl');
var parts = mf.toParts();
let mf = new MF('Et3N.HCl');
let parts = mf.toParts();

@@ -59,11 +59,11 @@ expect(parts).toStrictEqual([

{ kind: 'atom', value: 'H', multiplier: 15 },
{ kind: 'atom', value: 'N', multiplier: 1 }
{ kind: 'atom', value: 'N', multiplier: 1 },
],
[
{ kind: 'atom', value: 'H', multiplier: 1 },
{ kind: 'atom', value: 'Cl', multiplier: 1 }
]
{ kind: 'atom', value: 'Cl', multiplier: 1 },
],
]);
var newMF = mf.toMF();
let newMF = mf.toMF();
expect(newMF).toBe('C6H15N . HCl');

@@ -85,3 +85,3 @@

unsaturation: 0,
atoms: { C: 6, H: 15, N: 1 }
atoms: { C: 6, H: 15, N: 1 },
},

@@ -94,4 +94,4 @@ {

unsaturation: 0,
atoms: { H: 1, Cl: 1 }
}
atoms: { H: 1, Cl: 1 },
},
],

@@ -101,9 +101,14 @@ monoisotopicMass: 137.09712720211002,

charge: 0,
mf: 'C6H15N.HCl'
mf: 'C6H15N.HCl',
});
});
test('MF of (ch3ch2)3n', () => {
let mf = new MF('(ch3ch2)3n', { ensureCase: true });
expect(mf.toMF()).toBe('C6H15N');
});
test('MF of (Me2CH)3N no expand', () => {
var mf = new MF('(Me2CH)3N');
var parts = mf.toParts({ expand: false });
let mf = new MF('(Me2CH)3N');
let parts = mf.toParts({ expand: false });

@@ -115,7 +120,7 @@ expect(parts).toStrictEqual([

{ kind: 'atom', value: 'Me', multiplier: 6 },
{ kind: 'atom', value: 'N', multiplier: 1 }
]
{ kind: 'atom', value: 'N', multiplier: 1 },
],
]);
var newMF = mf.toMF();
let newMF = mf.toMF();
expect(newMF).toBe('C3H3Me6N');

@@ -130,3 +135,3 @@

unsaturation: 0,
atoms: { C: 3, H: 3, Me: 6, N: 1 }
atoms: { C: 3, H: 3, Me: 6, N: 1 },
});

@@ -136,4 +141,4 @@ });

test('MF of (Me2CH)3N with expand', () => {
var mf = new MF('(Me2CH)3N');
var parts = mf.toParts({ expand: true });
let mf = new MF('(Me2CH)3N');
let parts = mf.toParts({ expand: true });

@@ -144,7 +149,7 @@ expect(parts).toStrictEqual([

{ kind: 'atom', value: 'H', multiplier: 21 },
{ kind: 'atom', value: 'N', multiplier: 1 }
]
{ kind: 'atom', value: 'N', multiplier: 1 },
],
]);
var newMF = mf.toMF();
let newMF = mf.toMF();
expect(newMF).toBe('C9H21N');

@@ -159,3 +164,3 @@

unsaturation: 0,
atoms: { C: 9, H: 21, N: 1 }
atoms: { C: 9, H: 21, N: 1 },
});

@@ -165,4 +170,4 @@ });

test('MF of (+)SO4(+)(-2)2', () => {
var mf = new MF('(+)SO4(+)(-2)2');
var parts = mf.toParts();
let mf = new MF('(+)SO4(+)(-2)2');
let parts = mf.toParts();

@@ -173,9 +178,12 @@ expect(parts).toStrictEqual([

{ kind: 'atom', value: 'S', multiplier: 1 },
{ kind: 'charge', value: -2 }
]
{ kind: 'charge', value: -2 },
],
]);
var newMF = mf.toMF();
let newMF = mf.toMF();
expect(newMF).toBe('O4S(-2)');
let neutralMF = mf.toNeutralMF();
expect(neutralMF).toBe('O4S');
let info = mf.getInfo({ customUnsaturations: { S: 4 } });

@@ -189,3 +197,3 @@ expect(info).toStrictEqual({

unsaturation: 4,
atoms: { O: 4, S: 1 }
atoms: { O: 4, S: 1 },
});

@@ -208,4 +216,4 @@ });

test('MF of NC[13C][15N]2NN2', () => {
var mf = new MF('NC[13C][15N]2NN2');
var parts = mf.toParts();
let mf = new MF('NC[13C][15N]2NN2');
let parts = mf.toParts();
expect(parts).toStrictEqual([

@@ -216,4 +224,4 @@ [

{ kind: 'atom', value: 'N', multiplier: 4 },
{ kind: 'isotope', value: { atom: 'N', isotope: 15 }, multiplier: 2 }
]
{ kind: 'isotope', value: { atom: 'N', isotope: 15 }, multiplier: 2 },
],
]);

@@ -228,6 +236,6 @@

unsaturation: 6,
atoms: { C: 2, N: 6 }
atoms: { C: 2, N: 6 },
});
var newMF = mf.toMF();
let newMF = mf.toMF();
expect(newMF).toBe('C[13C]N4[15N]2');

@@ -237,4 +245,4 @@ });

test('MF of DNA HODampDtmpDcmpDgmpH ', () => {
var mf = new MF('HODampDtmpDgmpDcmpH');
var info = mf.getInfo();
let mf = new MF('HODampDtmpDgmpDcmpH');
let info = mf.getInfo();
expect(info).toStrictEqual({

@@ -246,3 +254,3 @@ mass: 1253.8043977028433,

atoms: { C: 39, H: 51, N: 15, O: 25, P: 4 },
unsaturation: 24
unsaturation: 24,
});

@@ -252,4 +260,4 @@ });

test('MF of RNA HOAmpUmpH ', () => {
var mf = new MF('HOAmpUmpH');
var info = mf.getInfo();
let mf = new MF('HOAmpUmpH');
let info = mf.getInfo();
expect(info).toStrictEqual({

@@ -261,3 +269,3 @@ mass: 653.388021231099,

atoms: { C: 19, H: 25, N: 7, O: 15, P: 2 },
unsaturation: 12
unsaturation: 12,
});

@@ -267,4 +275,4 @@ });

test('MF of CC{50,50}H', () => {
var mf = new MF('HC{50,50}C');
var parts = mf.toParts();
let mf = new MF('HC{50,50}C');
let parts = mf.toParts();
expect(parts).toStrictEqual([

@@ -276,9 +284,9 @@ [

value: { atom: 'C', ratio: [50, 50] },
multiplier: 1
multiplier: 1,
},
{ kind: 'atom', value: 'H', multiplier: 1 }
]
{ kind: 'atom', value: 'H', multiplier: 1 },
],
]);
var newMF = mf.toMF();
let newMF = mf.toMF();
expect(newMF).toBe('CC{50,50}H');

@@ -293,3 +301,3 @@

unsaturation: 2.5,
atoms: { C: 2, H: 1 }
atoms: { C: 2, H: 1 },
});

@@ -299,5 +307,5 @@ });

test('MF of H(+)(H+)-1H', () => {
var mf = new MF('H(+)(H+)-1H');
let mf = new MF('H(+)(H+)-1H');
var newMF = mf.toMF();
let newMF = mf.toMF();
expect(newMF).toBe('H');

@@ -312,3 +320,3 @@

monoisotopicMass: 1.00782503223,
unsaturation: 0.5
unsaturation: 0.5,
});

@@ -318,6 +326,6 @@ });

test('MF of 2NH3 . 2HCl', () => {
var mf = new MF('2NH3 . 2HCl');
let mf = new MF('2NH3 . 2HCl');
var newMF = mf.toMF();
let newMF = mf.toMF();
expect(newMF).toBe('H6N2 . H2Cl2');
});

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

var tests = {
let tests = {
C10: [{ kind: 'atom', value: 'C' }, { kind: 'multiplier', value: 10 }],

@@ -11,3 +11,3 @@ 'C-1': [{ kind: 'atom', value: 'C' }, { kind: 'multiplier', value: -1 }],

{ kind: 'atom', value: 'C' },
{ kind: 'multiplierRange', value: { from: 1, to: 10 } }
{ kind: 'multiplierRange', value: { from: 1, to: 10 } },
],

@@ -22,3 +22,3 @@ '2H': [{ kind: 'preMultiplier', value: 2 }, { kind: 'atom', value: 'H' }],

{ kind: 'charge', value: -1 },
{ kind: 'atom', value: 'H' }
{ kind: 'atom', value: 'H' },
],

@@ -30,3 +30,3 @@ 'C++': [{ kind: 'atom', value: 'C' }, { kind: 'charge', value: 2 }],

{ kind: 'multiplier', value: 2 },
{ kind: 'charge', value: 1 }
{ kind: 'charge', value: 1 },
],

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

{ kind: 'charge', value: 1 },
{ kind: 'closingParenthesis', value: ')' }
{ kind: 'closingParenthesis', value: ')' },
],

@@ -50,3 +50,3 @@ C$ABC: [{ kind: 'atom', value: 'C' }, { kind: 'comment', value: 'ABC' }],

{ kind: 'charge', value: -1 },
{ kind: 'charge', value: -3 }
{ kind: 'charge', value: -3 },
],

@@ -58,3 +58,3 @@ 'C(-1)2(-3)3': [

{ kind: 'charge', value: -3 },
{ kind: 'multiplier', value: 3 }
{ kind: 'multiplier', value: 3 },
],

@@ -66,3 +66,3 @@ 'C(H-2)': [

{ kind: 'multiplier', value: -2 },
{ kind: 'closingParenthesis', value: ')' }
{ kind: 'closingParenthesis', value: ')' },
],

@@ -72,3 +72,3 @@ 'H.Cl': [

{ kind: 'salt', value: '.' },
{ kind: 'atom', value: 'Cl' }
{ kind: 'atom', value: 'Cl' },
],

@@ -83,3 +83,3 @@ 'H{1,1}': [{ kind: 'isotopeRatio', value: { atom: 'H', ratio: [1, 1] } }],

{ kind: 'atom', value: 'H' },
{ kind: 'multiplier', value: 20 }
{ kind: 'multiplier', value: 20 },
],

@@ -102,3 +102,3 @@ '(CH(CH3)2)3N.2HCl': [

{ kind: 'atom', value: 'H' },
{ kind: 'atom', value: 'Cl' }
{ kind: 'atom', value: 'Cl' },
],

@@ -112,3 +112,3 @@ 'C.C2.C3': [

{ kind: 'atom', value: 'C' },
{ kind: 'multiplier', value: 3 }
{ kind: 'multiplier', value: 3 },
],

@@ -123,3 +123,3 @@ 'C10.C20.C30': [

{ kind: 'atom', value: 'C' },
{ kind: 'multiplier', value: 30 }
{ kind: 'multiplier', value: 30 },
],

@@ -136,3 +136,3 @@ 'C.0.5H2O.0.6HCl': [

{ kind: 'atom', value: 'H' },
{ kind: 'atom', value: 'Cl' }
{ kind: 'atom', value: 'Cl' },
],

@@ -148,3 +148,3 @@ 'NH3 . 2HCl': [

{ kind: 'atom', value: 'H' },
{ kind: 'atom', value: 'Cl' }
{ kind: 'atom', value: 'Cl' },
],

@@ -161,5 +161,17 @@ '2NH3 . 2HCl': [

{ kind: 'atom', value: 'H' },
{ kind: 'atom', value: 'Cl' }
{ kind: 'atom', value: 'Cl' },
],
D: [{ kind: 'atom', value: 'D' }]
D: [{ kind: 'atom', value: 'D' }],
'C1-2': [
{ kind: 'atom', value: 'C' },
{ kind: 'multiplierRange', value: { from: 1, to: 2 } },
],
'C2-1': [
{ kind: 'atom', value: 'C' },
{ kind: 'multiplierRange', value: { from: 1, to: 2 } },
],
'C-1--2': [
{ kind: 'atom', value: 'C' },
{ kind: 'multiplierRange', value: { from: -2, to: -1 } },
],
};

@@ -166,0 +178,0 @@

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

SUPERIMPOSE: 'superimpose',
TEXT: 'text'
TEXT: 'text',
};

@@ -12,4 +12,4 @@ 'use strict';

function parseToHtml(mf) {
var parsed = parse(mf);
var display = toDisplay(parsed);
let parsed = parse(mf);
let display = toDisplay(parsed);
return toHtml(display);

@@ -23,2 +23,3 @@ }

parse: require('./parse'),
ensureCase: require('./ensureCase'),
toDisplay,

@@ -25,0 +26,0 @@ toHtml,

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

TEXT: 'text',
COMMENT: 'comment'
COMMENT: 'comment',
};

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

const getInfo = require('./util/getInfo');
const ensureCase = require('./ensureCase');
const getEA = require('./util/getEA');

@@ -15,3 +16,6 @@ const getIsotopesInfo = require('./util/getIsotopesInfo');

class MF {
constructor(mf) {
constructor(mf, options = {}) {
if (options.ensureCase) {
mf = ensureCase(mf);
}
this.parsed = parse(mf);

@@ -44,2 +48,3 @@ this.cache = {};

* as well as the same informations for all the parts
* @param {object} [options={}] options
*/

@@ -87,2 +92,13 @@ getInfo(options = {}) {

/**
* Get a canonized MF
*/
toNeutralMF() {
if (!this.cache.neutralMF) {
this.toParts();
this.cache.neutralMF = partsToMF(this.cache.parts, { neutral: true });
}
return this.cache.neutralMF;
}
canonize() {

@@ -89,0 +105,0 @@ this.toParts();

'use strict';
const Kind = require('./Kind');

@@ -24,3 +23,6 @@ const parseCharge = require('./util/parseCharge');

while (this.i < mf.length) {
if (this.result.length > 0 && this.result[this.result.length - 1].kind !== Kind.TEXT) {
if (
this.result.length > 0 &&
this.result[this.result.length - 1].kind !== Kind.TEXT
) {
lastKind = this.result[this.result.length - 1].kind;

@@ -33,10 +35,30 @@ }

if ((ascii > 47 && ascii < 58) || (char === '-' && nextAscii > 47 && nextAscii < 58)) { // a number
if (
(ascii > 47 && ascii < 58) ||
(char === '-' && nextAscii > 47 && nextAscii < 58)
) {
// a number
let value = this.getNumber(ascii);
if (lastKind === Kind.SALT || lastKind === Kind.BEGIN || lastKind === Kind.OPENING_PARENTHESIS) {
if (value.to) throw new MFError(this.mf, this.i, 'Premultiplier may not contain a -');
if (
lastKind === Kind.SALT ||
lastKind === Kind.BEGIN ||
lastKind === Kind.OPENING_PARENTHESIS
) {
if (value.to) {
throw new MFError(
this.mf,
this.i,
'Premultiplier may not contain a -',
);
}
this.result.push({ kind: Kind.PRE_MULTIPLIER, value: value.from });
} else {
if (value.to) {
this.result.push({ kind: Kind.MULTIPLIER_RANGE, value });
this.result.push({
kind: Kind.MULTIPLIER_RANGE,
value: {
from: Math.min(value.from, value.to),
to: Math.max(value.from, value.to),
},
});
} else {

@@ -48,12 +70,19 @@ this.result.push({ kind: Kind.MULTIPLIER, value: value.from });

continue;
} else if (char === '.') { // a point
} else if (char === '.') {
// a point
this.result.push({ kind: Kind.SALT, value: char });
// it is not in a number otherwise it would have been taken before
// it must be in a salt
} else if (ascii > 64 && ascii < 91) { // an uppercase = new atom
} else if (ascii > 64 && ascii < 91) {
// an uppercase = new atom
let value = this.getAtom(ascii);
this.result.push({ kind: Kind.ATOM, value });
continue;
} else if (ascii > 96 && ascii < 123) { // a lowercase
throw new MFError(this.mf, this.i, 'found a lowercase not following an uppercase');
} else if (ascii > 96 && ascii < 123) {
// a lowercase
throw new MFError(
this.mf,
this.i,
'found a lowercase not following an uppercase',
);
} else if (char === '(') {

@@ -68,8 +97,14 @@ let charge = this.getParenthesisCharge(ascii);

this.result.push({ kind: Kind.CLOSING_PARENTHESIS, value: ')' });
} else if (char === '[') { // defines an isotope
} else if (char === '[') {
// defines an isotope
let isotope = this.getIsotope(ascii);
this.result.push({ kind: Kind.ISOTOPE, value: isotope });
} else if (char === ']') {
throw new MFError(this.mf, this.i, 'should never meet an closing bracket not in isotopes');
} else if (char === '{') { // can define an exotic isotopic ratio or mixtures of groups
throw new MFError(
this.mf,
this.i,
'should never meet an closing bracket not in isotopes',
);
} else if (char === '{') {
// can define an exotic isotopic ratio or mixtures of groups
let isotopeRatio = this.getCurlyBracketIsotopeRatio(ascii);

@@ -81,17 +116,31 @@ if (lastKind === Kind.ATOM) {

atom: lastResult.value,
ratio: isotopeRatio
ratio: isotopeRatio,
};
} else {
throw new MFError(this.mf, this.i, 'isotopic composition has to follow an atom');
throw new MFError(
this.mf,
this.i,
'isotopic composition has to follow an atom',
);
}
} else if (char === '}') {
throw new MFError(this.mf, this.i, 'found a unexpected closing curly bracket');
} else if (char === '+') { // charge not in parenthesis
throw new MFError(
this.mf,
this.i,
'found a unexpected closing curly bracket',
);
} else if (char === '+') {
// charge not in parenthesis
let charge = this.getNonParenthesisCharge(ascii);
this.result.push({ kind: Kind.CHARGE, value: charge });
} else if (char === '-') { // charge not in parenthesis
} 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
this.result.push({ kind: Kind.COMMENT, value: this.mf.substring(this.i + 1) });
} else if (char === '$') {
// it is a comment after
this.result.push({
kind: Kind.COMMENT,
value: this.mf.substring(this.i + 1),
});
break;

@@ -115,3 +164,7 @@ } else {

if (counter !== 0) {
throw new MFError(this.mf, this.i, 'number of opening and closing parenthesis not equal');
throw new MFError(
this.mf,
this.i,
'number of opening and closing parenthesis not equal',
);
}

@@ -128,3 +181,3 @@ }

ascii = this.mf.charCodeAt(this.i);
} while (ascii > 47 && ascii < 58 || ascii === 46 || ascii === 45); // number, . or -
} while ((ascii > 47 && ascii < 58) || ascii === 46 || ascii === 45); // number, . or -
// we need to deal with the case there is a from / to

@@ -135,3 +188,6 @@ if (previous === 46) this.i--;

if (indexOfDash > -1) {
return { from: Number(number.substr(0, indexOfDash)), to: Number(number.substr(indexOfDash + 1)) };
return {
from: Number(number.substr(0, indexOfDash)),
to: Number(number.substr(indexOfDash + 1)),
};
}

@@ -151,3 +207,4 @@ return { from: Number(number) };

getIsotope(ascii) { // [13C]
getIsotope(ascii) {
// [13C]
let substring = '';

@@ -165,3 +222,2 @@ do {

getCurlyBracketIsotopeRatio(ascii) {

@@ -182,3 +238,7 @@ let substring = '';

}
throw new MFError(this.mf, this.i, 'Curly brackets should contain only number and comma');
throw new MFError(
this.mf,
this.i,
'Curly brackets should contain only number and comma',
);
}

@@ -185,0 +245,0 @@

'use strict';
module.exports = {
SUPERIMPOSE: 'flex-direction: column;display: inline-flex;justify-content: center;text-align: left;vertical-align: middle;',
SUPERIMPOSE_SUP_SUB: 'line-height: 1; font-size: 70%'
SUPERIMPOSE:
'flex-direction: column;display: inline-flex;justify-content: center;text-align: left;vertical-align: middle;',
SUPERIMPOSE_SUP_SUB: 'line-height: 1; font-size: 70%',
};
'use strict';
var tests = [
let tests = [
{
mf: 'C10',
parsed: [{ kind: 'atom', value: 'C' }, { kind: 'multiplier', value: 10 }],
result: [{ kind: 'text', value: 'C' }, { kind: 'subscript', value: '10' }]
result: [{ kind: 'text', value: 'C' }, { kind: 'subscript', value: '10' }],
},

@@ -12,3 +12,3 @@ {

parsed: [{ kind: 'atom', value: 'C' }, { kind: 'multiplier', value: -1 }],
result: [{ kind: 'text', value: 'C' }, { kind: 'subscript', value: '-1' }]
result: [{ kind: 'text', value: 'C' }, { kind: 'subscript', value: '-1' }],
},

@@ -19,5 +19,8 @@ {

{ kind: 'atom', value: 'C' },
{ kind: 'multiplierRange', value: { from: 1, to: 10 } }
{ kind: 'multiplierRange', value: { from: 1, to: 10 } },
],
result: [{ kind: 'text', value: 'C' }, { kind: 'subscript', value: '1-10' }]
result: [
{ kind: 'text', value: 'C' },
{ kind: 'subscript', value: '1-10' },
],
},

@@ -27,3 +30,3 @@ {

parsed: [{ kind: 'preMultiplier', value: 2 }, { kind: 'atom', value: 'H' }],
result: [{ kind: 'text', value: '2H' }]
result: [{ kind: 'text', value: '2H' }],
},

@@ -33,3 +36,3 @@ {

parsed: [{ kind: 'isotope', value: { atom: 'C', isotope: 13 } }],
result: [{ kind: 'superscript', value: 13 }, { kind: 'text', value: 'C' }]
result: [{ kind: 'superscript', value: 13 }, { kind: 'text', value: 'C' }],
},

@@ -39,3 +42,6 @@ {

parsed: [{ kind: 'atom', value: 'C' }, { kind: 'charge', value: 2 }],
result: [{ kind: 'text', value: 'C' }, { kind: 'superscript', value: '+2' }]
result: [
{ kind: 'text', value: 'C' },
{ kind: 'superscript', value: '+2' },
],
},

@@ -47,8 +53,8 @@ {

{ kind: 'multiplier', value: 2 },
{ kind: 'charge', value: 1 }
{ kind: 'charge', value: 1 },
],
result: [
{ kind: 'text', value: 'C' },
{ kind: 'superimpose', over: '+', under: '2' }
]
{ kind: 'superimpose', over: '+', under: '2' },
],
},

@@ -62,3 +68,3 @@ {

{ kind: 'multiplier', value: -2 },
{ kind: 'closingParenthesis', value: ')' }
{ kind: 'closingParenthesis', value: ')' },
],

@@ -68,4 +74,4 @@ result: [

{ kind: 'subscript', value: '-2' },
{ kind: 'text', value: ')' }
]
{ kind: 'text', value: ')' },
],
},

@@ -77,5 +83,5 @@ {

{ kind: 'salt', value: '.' },
{ kind: 'atom', value: 'Cl' }
{ kind: 'atom', value: 'Cl' },
],
result: [{ kind: 'text', value: 'H•Cl' }]
result: [{ kind: 'text', value: 'H•Cl' }],
},

@@ -87,5 +93,5 @@ {

{ kind: 'text', value: 'H' },
{ kind: 'superscript', value: '{1,1}' }
]
}
{ kind: 'superscript', value: '{1,1}' },
],
},
];

@@ -96,4 +102,4 @@

test.each(tests)('toDisplay', function (aTest) {
var display = toDisplay(aTest.parsed);
let display = toDisplay(aTest.parsed);
expect(display).toMatchObject(aTest.result);
});

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

var tests = [
let tests = [
{ mf: 'C', result: [[{ kind: 'atom', value: 'C', multiplier: 1 }]] },

@@ -55,5 +55,5 @@ { mf: 'C2', result: [[{ kind: 'atom', value: 'C', multiplier: 2 }]] },

test.each(tests)('toParts %p', function (aTest) {
var parsed = parse(aTest.mf);
var parts = toParts(parsed);
let parsed = parse(aTest.mf);
let parts = toParts(parsed);
expect(parts).toMatchObject(aTest.result);
});

@@ -16,4 +16,4 @@ 'use strict';

*/
module.exports = function getInfo(parts) {
var results = {};
module.exports = function getEA(parts) {
let results = {};
for (let part of parts) {

@@ -26,3 +26,3 @@ for (let line of part) {

throw new Error(
`Unknown isotope: ${line.value.isotope}${line.value.atom}`
`Unknown isotope: ${line.value.isotope}${line.value.atom}`,
);

@@ -39,3 +39,3 @@ }

line.value.atom,
isotopeRatioInfo.mass * line.multiplier
isotopeRatioInfo.mass * line.multiplier,
);

@@ -70,3 +70,3 @@ break;

element: key,
mass: results[key]
mass: results[key],
});

@@ -78,3 +78,2 @@ }

});
return eas;

@@ -81,0 +80,0 @@ };

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

const unsaturations = require('chemical-elements/src/unsaturationsObject.js');
const { ELECTRON_MASS } = require('chemical-elements/src/constants');
const Kind = require('../Kind');
const { ELECTRON_MASS } = require('chemical-elements/src/constants');
const partToMF = require('./partToMF');

@@ -29,3 +28,3 @@ const partToAtoms = require('./partToAtoms');

var result = { parts: [] };
let result = { parts: [] };
for (let part of parts) {

@@ -53,3 +52,3 @@ result.parts.push(getProcessedPart(part, customUnsaturations));

mf: '',
atoms: partToAtoms(part)
atoms: partToAtoms(part),
};

@@ -87,3 +86,3 @@ let unsaturation = 0;

throw new Error(
`Unknown isotope: ${line.value.isotope}${line.value.atom}`
`Unknown isotope: ${line.value.isotope}${line.value.atom}`,
);

@@ -134,2 +133,1 @@ }

}

@@ -14,5 +14,3 @@ 'use strict';

throw new Error(
`the number of specified ratios is bigger that the number of stable isotopes: ${
value.atom
}`
`the number of specified ratios is bigger that the number of stable isotopes: ${value.atom}`,
);

@@ -19,0 +17,0 @@ }

@@ -16,3 +16,5 @@ 'use strict';

if (parts.length === 0) return [];
if (parts.length > 1) throw new Error('getIsotopesInfo can not be applied on multipart MF');
if (parts.length > 1) {
throw new Error('getIsotopesInfo can not be applied on multipart MF');
}

@@ -25,3 +27,3 @@ return getProcessedPart(parts[0]);

charge: 0,
isotopes: []
isotopes: [],
};

@@ -32,21 +34,27 @@ for (let line of part) {

let isotope = isotopes[line.value.isotope + line.value.atom];
if (!isotope) throw Error('unknown isotope:', line.value.atom, line.value.isotope);
if (!isotope) {
throw Error('unknown isotope:', line.value.atom, line.value.isotope);
}
result.isotopes.push({
atom: `[${line.value.isotope}${line.value.atom}]`,
number: line.multiplier,
distribution: [{ x: isotope.mass, y: 1 }]
distribution: [{ x: isotope.mass, y: 1 }],
});
break;
}
case Kind.ISOTOPE_RATIO: {
let element = elements[line.value.atom];
if (!element) throw new Error('unknown element:', line.value);
case Kind.ISOTOPE_RATIO:
{
let element = elements[line.value.atom];
if (!element) throw new Error('unknown element:', line.value);
let distribution = getDistribution(element.isotopes, line.value.ratio);
result.isotopes.push({
atom: `${line.value.atom}{${line.value.ratio.join(',')}}`,
number: line.multiplier,
distribution
});
}
let distribution = getDistribution(
element.isotopes,
line.value.ratio,
);
result.isotopes.push({
atom: `${line.value.atom}{${line.value.ratio.join(',')}}`,
number: line.multiplier,
distribution,
});
}
break;

@@ -59,3 +67,6 @@ case Kind.ATOM: {

number: line.multiplier,
distribution: element.isotopes.map((e) => ({ x: e.mass, y: e.abundance }))
distribution: element.isotopes.map((e) => ({
x: e.mass,
y: e.abundance,
})),
});

@@ -74,3 +85,2 @@ break;

function getDistribution(isotopesArray, ratio) {

@@ -80,3 +90,5 @@ let ratios = normalize(ratio);

if (ratios.length > isotopesArray.length) {
throw new Error(`the number of specified ratios is bigger that the number of stable isotopes: ${isotopes}`);
throw new Error(
`the number of specified ratios is bigger that the number of stable isotopes: ${isotopes}`,
);
}

@@ -86,3 +98,3 @@ for (let i = 0; i < ratios.length; i++) {

x: isotopesArray[i].mass,
y: ratios[i]
y: ratios[i],
});

@@ -89,0 +101,0 @@ }

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

abundance: i.abundance,
mass: i.mass
mass: i.mass,
};

@@ -18,2 +18,1 @@ });

module.exports = isotopes;
'use strict';
/**

@@ -12,5 +11,5 @@ * Parse a string to extract the charge

charge = charge.replace(/[()]/g, '');
var chargeNumber = 0;
let chargeNumber = 0;
if (charge.match(/^[+-]+$/)) {
for (var i = 0; i < charge.length; i++) {
for (let i = 0; i < charge.length; i++) {
if (charge.charAt(i) === '+') chargeNumber++;

@@ -20,3 +19,5 @@ else chargeNumber--;

} else if (charge.match(/^[0-9]+[+-]$/)) {
chargeNumber = Number(charge.charAt(charge.length - 1) + charge.substring(0, charge.length - 1));
chargeNumber = Number(
charge.charAt(charge.length - 1) + charge.substring(0, charge.length - 1),
);
} else {

@@ -23,0 +24,0 @@ chargeNumber = Number(charge);

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

module.exports = function partsToDisplay(parts) {
var lines = [];
let lines = [];
for (let part of parts) {

@@ -21,3 +21,3 @@ if (lines.length > 0) lines.push({ kind: Kind.SALT, value: '•' });

kind: Kind.MULTIPLIER,
value: partLine.multiplier
value: partLine.multiplier,
});

@@ -24,0 +24,0 @@ }

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

module.exports = function partsToMF(parts) {
var mf = [];
module.exports = function partsToMF(parts, options) {
let mf = [];
for (let part of parts) {
mf.push(partToMF(part));
mf.push(partToMF(part, options));
}
return mf.join(' . ');
};

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

module.exports = function partToAtoms(part) {
var atoms = {};
let atoms = {};
for (let line of part) {

@@ -15,0 +15,0 @@ switch (line.kind) {

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

module.exports = function partToMF(part) {
var mf = [];
module.exports = function partToMF(part, options = {}) {
let mf = [];
for (let line of part) {

@@ -15,3 +15,3 @@ switch (line.kind) {

line.multiplier !== 1 ? line.multiplier : ''
}`
}`,
);

@@ -25,3 +25,3 @@ }

line.multiplier !== 1 ? line.multiplier : ''
}`
}`,
);

@@ -36,3 +36,3 @@ }

case Kind.CHARGE:
if (line.value === 0) break;
if (line.value === 0 || options.neutral) break;
mf.push(`(${line.value > 0 ? `+${line.value}` : line.value})`);

@@ -39,0 +39,0 @@ break;

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

kind: Format.SUBSCRIPT,
value: String(line.value)
value: String(line.value),
};

@@ -31,3 +31,3 @@ results.push(result);

kind: Format.SUBSCRIPT,
value: `${String(line.value.from)}-${line.value.to}`
value: `${String(line.value.from)}-${line.value.to}`,
};

@@ -45,3 +45,3 @@ results.push(result);

kind: Format.SUPERSCRIPT,
value: formatCharge(line.value)
value: formatCharge(line.value),
};

@@ -56,3 +56,3 @@ results.push(result);

kind: Format.SUPERSCRIPT,
value: line.value.isotope
value: line.value.isotope,
};

@@ -62,3 +62,3 @@ results.push(result);

kind: Format.TEXT,
value: line.value.atom
value: line.value.atom,
};

@@ -74,3 +74,3 @@ results.push(result);

kind: Format.TEXT,
value: line.value.atom
value: line.value.atom,
};

@@ -81,3 +81,3 @@ results.push(result);

kind: Format.SUPERSCRIPT,
value: `{${line.value.ratio.join(',')}}`
value: `{${line.value.ratio.join(',')}}`,
};

@@ -92,3 +92,3 @@ results.push(result);

kind: Format.TEXT,
value: ' • '
value: ' • ',
};

@@ -104,3 +104,3 @@ results.push(result);

kind: Format.TEXT,
value: line.value
value: line.value,
};

@@ -107,0 +107,0 @@ results.push(result);

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

module.exports = function getHtml(lines) {
var html = [];
let html = [];
for (let line of lines) {

@@ -19,4 +19,8 @@ switch (line.kind) {

html.push(`<span style="${Style.SUPERIMPOSE}">`);
html.push(`<sup style="${Style.SUPERIMPOSE_SUP_SUB}">${line.over}</sup>`);
html.push(`<sub style="${Style.SUPERIMPOSE_SUP_SUB}">${line.under}</sub>`);
html.push(
`<sup style="${Style.SUPERIMPOSE_SUP_SUB}">${line.over}</sup>`,
);
html.push(
`<sub style="${Style.SUPERIMPOSE_SUP_SUB}">${line.under}</sub>`,
);
html.push('</span>');

@@ -23,0 +27,0 @@ break;

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

* @param {*} lines
* @param {object} options
* @param {boolean} [true] options.expand - Should we expand the groups
* @param {object} [options={}]
* @param {boolean} [options.expand=true] - Should we expand the groups
*/

@@ -69,3 +69,3 @@

value: 1,
fromIndex: currentPart.lines.length
fromIndex: currentPart.lines.length,
};

@@ -133,3 +133,3 @@ currentPart.multipliers.push(currentPart.currentMultiplier);

value: { atom: element.symbol, isotope: element.isotope },
multiplier: line.multiplier * element.number
multiplier: line.multiplier * element.number,
});

@@ -140,3 +140,3 @@ } else {

value: element.symbol,
multiplier: line.multiplier * element.number
multiplier: line.multiplier * element.number,
});

@@ -166,3 +166,3 @@ }

kind: Kind.CHARGE,
value: key.value.value * key.value.multiplier
value: key.value.value * key.value.multiplier,
});

@@ -205,3 +205,3 @@ } else {

part.keys = [];
for (var line of part.lines) {
for (let line of part.lines) {
part.keys.push({ key: getKey(line), value: line });

@@ -208,0 +208,0 @@ }

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