npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mendeleev

v1.2.2

Published

A small library for working with element data and building compounds.

Downloads

167

Readme

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

import { PeriodicTable } from 'mendeleev'; // ES2015
var PeriodicTable = require('mendeleev').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.getElement('H');
hydrogen == {  
    name:"hydrogen",
    symbol:"H",
    type:"other-nonmetal",
    number:1,
    mass:1.008,
    period:1,
    group:1,
    melting:14.01,
    boiling:20.28,
    density:0.00008988,
    electronegativity:2.20,
    radius:25,
    valence:1,
    specificheat:14.304
}

var unknown = PeriodicTable.getElement('Nope');
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.getAtomic(2); // { name: 'helium', ... }
var unknown = PeriodicTable.getAtomic(1028); // 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.getType('halogen'); // [{ name: 'fluorine', ... }, { name: 'chlorine', ... }, ...]
var unknown = PeriodicTable.getType('fake-type'); // []

.getPeriod(number)

Takes an elemental period (1 to 7) as an argument, returning an array of matching elements.

var periodOne = PeriodicTable.getPeriod(1); // [{ name: 'hydrogen', ... }, { name: 'helium', ... }, ...]
var unknown = PeriodicTable.getPeriod(1000); // []

.getGroup(number)

Takes an elemental group (1 to 18) as an argument, returning an array of matching elements.

var alkalineEarth = PeriodicTable.getGroup(2); // [{ name: 'beryllium', ... }, { name: 'magnesium', ... }, ...]
var unknown = PeriodicTable.getGroup(1000); // []

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.

import { Compound } from 'mendeleev'; // ES2015
var Compound = require('mendeleev').Compound; // CommonJS

var empty = new Compound();
var water = new Compound({'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 = new Compound();
water.add('H', 2);
water.add('O');

.remove(str, ?number)

Allows you to remove an element from a compound, with an optional quantity. The default quantity is 1.

var c = new Compound({'H': 2, 'O': 1});
c.remove('O') // Compound would be H2

.getMass()

Returns the molecular mass of the compound.

var silverNitrate = new Compound({"Ag": 1, "N": 1, "O": 3})
var m = silverNitrate.getMass(); // 169.87490

.getPercentages()

Returns an array in the form of [{element: <str>, percentage: <number>}, ....]

var water = new Compound({'H': 2, 'O', 1});
var p = water.getPercentages(); // [{element: 'H', percentage:11.19}, {element: 'O', percentage:88.81}]

.toHTML()

Returns the compound as HTML, giving the quantities <sub> tags.

var water = new Compound({'H': 2, 'O', 1});
var h = water.toHTML(); // H<sub>2</sub>O

Utility

Utility is where a few static utility methods are kept. It currently only has one.

Initialization

import { Utility } from 'mendeleev'; // ES2015
var Utility = require('mendeleev').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.stringToElementList(formula);
var aluminiumMonoxide = new Compound(elementList);