Skip to content
This repository has been archived by the owner on Sep 10, 2023. It is now read-only.

shangzhenyang/periodic-table

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
April 26, 2023 20:21
April 16, 2023 20:56
April 16, 2023 20:56
April 16, 2023 20:56
April 26, 2023 20:00
April 16, 2023 20:56

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.

About

It is an npm package that contains the entire periodic table and has handy functions that return information about elements and compounds.

Topics

Resources

License

Stars

Watchers

Forks