Mendeleev
A small library for working with element data and building compounds.
PeriodicTable
PeriodicTable contains information on individual elements. It allows retrieval by symbol, name, or atomic number. It also allows filtering by type, period, and group.
Initialization
; // ES2015var PeriodicTable = PeriodicTable; // CommonJS
.getElement(str)
Takes an element's symbol as an argument, such as 'H' or 'Ni', returning the elements data if it's found, null if it's not.
var hydrogen = PeriodicTable;hydrogen == name:"hydrogen" symbol:"H" type:"other-nonmetal" number:1 mass:1008 period:1 group:1 melting:1401 boiling:2028 density:000008988 electronegativity:220 radius:25 valence:1 specificheat:14304 var unknown = PeriodicTable;unknown == null;
.getAtomic(number)
Takes an element's atomic number as an argument, such as 17 or 118, returning the elements data if it's found, null if it's not.
var helium = PeriodicTable; // { name: 'helium', ... }var unknown = PeriodicTable; // null
.getType(string)
Takes an element type as an argument, returning an array of matching elements.
Possible element types include: alkali-metal
, alkaline-earth
, transition-metal
, post-transition-metal
, metalloid
, other-nonmetal
, halogen
, noble-gas
, lanthanoid
, actinoid
.
var halogens = PeriodicTable; // [{ name: 'fluorine', ... }, { name: 'chlorine', ... }, ...]var unknown = PeriodicTable; // []
.getPeriod(number)
Takes an elemental period (1 to 7) as an argument, returning an array of matching elements.
var periodOne = PeriodicTable; // [{ name: 'hydrogen', ... }, { name: 'helium', ... }, ...]var unknown = PeriodicTable; // []
.getGroup(number)
Takes an elemental group (1 to 18) as an argument, returning an array of matching elements.
var alkalineEarth = PeriodicTable; // [{ name: 'beryllium', ... }, { name: 'magnesium', ... }, ...]var unknown = PeriodicTable; // []
Compound
Compound is an object that represents a chemical compound. After being initialized, it can have elements added and subtracted. It also has methods for getting the molecular mass, mass percentages, and for creating an HTML representation of the compound.
Initialization
You can initialize an empty compound, or pre-populate it with elements.
; // ES2015var Compound = Compound; // CommonJS var empty = ;var water = 'H': 2 'O' 1;
.add(str, ?number)
Allows you to add an element to a compound, with an optional quantity. The default quantity is 1.
var water = ;water;water;
.remove(str, ?number)
Allows you to remove an element from a compound, with an optional quantity. The default quantity is 1.
var c = 'H': 2 'O': 1;c // Compound would be H2
.getMass()
Returns the molecular mass of the compound.
var silverNitrate = "Ag": 1 "N": 1 "O": 3var m = silverNitrate; // 169.87490
.getPercentages()
Returns an array in the form of [{element: <str>, percentage: <number>}, ....]
var water = 'H': 2 'O' 1;var p = water; // [{element: 'H', percentage:11.19}, {element: 'O', percentage:88.81}]
.toHTML()
Returns the compound as HTML, giving the quantities <sub>
tags.
var water = 'H': 2 'O' 1;var h = water; // H<sub>2</sub>O
Utility
Utility is where a few static utility methods are kept. It currently only has one.
Initialization
; // ES2015var Utility = Utility; // CommonJS
.stringToElementList(string)
Accepts a string, such as 'H2O', and turns it into an element list, of the form {'H': 2, 'O', 1}. An element list is what you would use to initialize a compound. This currently does not work with parentheses
var formula = "AlO";var elementList = Utility;var aluminiumMonoxide = elementList;