molecular-formula
Advanced tools
Comparing version 1.1.4 to 1.1.5
@@ -5,3 +5,5 @@ var isoAbund = require('isotope-abundances'); | ||
constructor(mf) { | ||
this.formula = mf; | ||
this.formula = mf.replace(/[⁰¹²³⁴-⁹₀-₉]/g, function(char) { | ||
return char.charCodeAt(0).toString(16).slice(-1) | ||
}); | ||
var expanded = this.cleanParantheses(this.formula); | ||
@@ -207,2 +209,2 @@ this.composition = this.formulaToJson(expanded); | ||
} | ||
} |
{ | ||
"name": "molecular-formula", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"description": "A library for working with molecular-formula", | ||
@@ -28,3 +28,2 @@ "main": "index.js", | ||
"chai": "^4.1.2", | ||
"fs": "0.0.1-security", | ||
"mocha": "^5.2.0" | ||
@@ -31,0 +30,0 @@ }, |
# molecular-formula | ||
[![Build Status](https://travis-ci.org/emptyport/molecular-formula.svg?branch=master)](https://travis-ci.org/emptyport/molecular-formula) | ||
[![codecov](https://codecov.io/gh/emptyport/molecular-formula/branch/master/graph/badge.svg)](https://codecov.io/gh/emptyport/molecular-formula) | ||
[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors) | ||
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) | ||
A simple library to work with molecular formula. | ||
@@ -17,2 +24,8 @@ | ||
``` | ||
Subscripts are also now supported thanks to [AprilArcus](https://github.com/AprilArcus)! | ||
``` javascript | ||
var water = new molFormula('H₂O'); | ||
``` | ||
You can retrieve the original formula like so. | ||
@@ -22,2 +35,3 @@ ``` javascript | ||
``` | ||
You also have access to the elemental composition. | ||
@@ -27,2 +41,3 @@ ``` javascript | ||
``` | ||
Output: | ||
@@ -76,2 +91,7 @@ ``` | ||
## Contributors | ||
[<img src="https://avatars1.githubusercontent.com/u/2045543?s=400&v=4" width="75px;"/><br /><sub><b>April Arcus</b></sub>](https://github.com/AprilArcus)<br /> | ||
[💻](https://github.com/emptyport/molecular-formula/commits?author=AprilArcus "Code") | ||
[⚠️](https://github.com/emptyport/molecular-formula/commits?author=AprilArcus "Tests") | ||
## Future functionality | ||
@@ -78,0 +98,0 @@ There are currently no planned improvements to this module. I am open to suggestions so let me know if you think something is missing. |
@@ -35,11 +35,11 @@ var should = require('chai').should(); | ||
it('formula for H2O matches', function() { | ||
it('formula for Na2(OH)2CH4(Na(Cl)2)2U(CN) matches', function() { | ||
formula.getFormula().should.equal('Na2(OH)2CH4(Na(Cl)2)2U(CN)'); | ||
}); | ||
it('simplified formula for H2O matches', function() { | ||
it('simplified formula for Na2(OH)2CH4(Na(Cl)2)2U(CN) matches', function() { | ||
formula.getSimplifiedFormula().should.equal('Na4O2H6C2Cl4UN'); | ||
}); | ||
it('composition for H2O matches', function() { | ||
it('composition for Na2(OH)2CH4(Na(Cl)2)2U(CN) matches', function() { | ||
var composition = formula.getComposition(); | ||
@@ -58,2 +58,27 @@ Object.keys(composition).length.should.equal(7); | ||
describe('Unicode Subscripts', function() { | ||
formula = new molFormula('Na₂(OH)₂CH₄(Na(Cl)₂)₂U(CN)'); | ||
it('formula for Na₂(OH)₂CH₄(Na(Cl)₂)₂U(CN) matches', function() { | ||
formula.getFormula().should.equal('Na2(OH)2CH4(Na(Cl)2)2U(CN)'); | ||
}); | ||
it('simplified formula for Na₂(OH)₂CH₄(Na(Cl)₂)₂U(CN) matches', function() { | ||
formula.getSimplifiedFormula().should.equal('Na4O2H6C2Cl4UN'); | ||
}); | ||
it('composition for Na₂(OH)₂CH₄(Na(Cl)₂)₂U(CN) matches', function() { | ||
var composition = formula.getComposition(); | ||
Object.keys(composition).length.should.equal(7); | ||
composition['Na'].should.equal(4); | ||
composition['O'].should.equal(2); | ||
composition['H'].should.equal(6); | ||
composition['C'].should.equal(2); | ||
composition['Cl'].should.equal(4); | ||
composition['U'].should.equal(1); | ||
composition['N'].should.equal(1); | ||
formula.getComposition().should.deep.equal({ Na: 4, O: 2, H: 6, C: 2, Cl: 4, U: 1, N: 1}); | ||
}); | ||
}); | ||
describe('Adding and Subtracting Formulae', function() { | ||
@@ -106,2 +131,2 @@ methyl = new molFormula('CH3'); | ||
}); | ||
}); | ||
}); |
14954
2
6
286
101