@shangzhen/periodic-table
TypeScript icon, indicating that this package has built-in type declarations

2.1.3 • Public • Published

periodic-table

It contains the entire periodic table and has handy functions that return information about elements and compounds. It supports both Node.js and browsers.

Installation

npm install @shangzhen/periodic-table

Usage

import {
    elements,
    getElement,
    getCompound,
    isErrorResult
} from "@shangzhen/periodic-table";

// Get all elements
console.log(elements);

// Get element
getElement("8"); // by atomic number
getElement("o"); // by symbol
getElement("oxygen"); // by name
getElement("氧"); // by Chinese name
getElement("15.999"); // by atomic mass

// Get compound
getCompound("carbon dioxide"); // by name
getCompound("CO2"); // by formula with proper case
getCompound("c o2"); // by formula with space
getCompound("二氧化碳"); // by Chinese name
getCompound("Fe2(SO4)3"); // by formula with parentheses

// Check if the result is an error
isErrorResult(getElement("abc")); // true

Returned Data

// ElementResult
{
    "mass": 15.999,
    "mole": 1,
    "name": "Oxygen",
    "name_chs": "氧",
    "name_cht": "氧",
    "number": 8,
    "symbol": "O"
}

// CompoundResult
{
    "mass": 44.009,
    "symbol": "CO2"
}

// ErrorResult
{
    "error": "notFound",
    "message": "Element not found."
}

getElement returns either an ElementResult or an ErrorResult.

getCompound returns either a CompoundResult, an ElementResult, or an ErrorResult.

License

MIT.

/@shangzhen/periodic-table/

    Package Sidebar

    Install

    npm i @shangzhen/periodic-table

    Weekly Downloads

    9

    Version

    2.1.3

    License

    MIT

    Unpacked Size

    28.3 kB

    Total Files

    6

    Last publish

    Collaborators

    • shangzhen