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 🙏

© 2025 – Pkg Stats / Ryan Hefner

chem-units

v1.5.0

Published

A JavaScript library for converting between different units of measurement commonly used in chemistry

Downloads

540

Readme

chem-units

A JavaScript library for converting between different units of measurement commonly used in chemistry.

npm version Downloads

Table of Contents

Features

  • ✅ Convert between common chemistry and scientific units
  • ✅ Support for multiple unit categories (mass, volume, pressure, temperature, etc.)
  • ✅ Simple and intuitive API
  • ✅ Lightweight and dependency-free

Requirements

  • Node.js: >=20.0.0 <25.0.0

Installation

Install using npm:

npm install chem-units

Or using yarn:

yarn add chem-units

Quick Start

import { convert } from 'chem-units';

// Convert 1 atmosphere to Pascal
const pressure = convert('pressure', 1, 'atm', 'pa');
console.log(pressure); // 101325

// Convert 42 moles to millimoles
const amount = convert('amount_substance', 42, 'mol', 'mmol');
console.log(amount); // 42000

// Convert 0°C to Fahrenheit
const temp = convert('temperature', 0, 'C', 'F');
console.log(temp); // 32

Usage

Universal Convert Function

The convert() function provides a simple and explicit way to convert between units. You specify the unit category, value, source unit, and target unit.

ℹ️ Note: The unit category refers to the field type (e.g., 'amount_substance', 'pressure', 'mass'). See Supported Units for the complete list of supported units and categories.

Examples

Amount of Substance:

import { convert } from 'chem-units';

// Convert moles to millimoles
const result = convert('amount_substance', 42, 'mol', 'mmol');
console.log(result); // 42000

Pressure Conversions:

// Convert atmospheres to Pascals
const result = convert('pressure', 1, 'atm', 'pa');
console.log(result); // 101325

Length Conversions:

// Convert millimeters to centimeters
const result = convert('length', 10, 'mm', 'cm');
console.log(result); // 1

Mass Conversions:

// Convert grams to milligrams
const result = convert('mass', 1, 'g', 'mg');
console.log(result); // 1000

Temperature Conversions:

// Convert Celsius to Fahrenheit
const result1 = convert('temperature', 0, 'C', 'F');
console.log(result1); // 32

// Convert Celsius to Kelvin
const result2 = convert('temperature', 100, 'C', 'K');
console.log(result2); // 373.15

unitConversion Function (simplified)

The unitConversion() is a simplified version of the general conversion function, requiring only the unit category, the value to be converted, and the target unit.

import { unitConversion } from 'chem-units';

const type = 'temperature';
const targetUnit = 'F';
const value = '32';

const result = unitConversion(type, targetUnit, value);
console.log(result); // 89.6

API Reference

convert(unit_category, value, from, to)

Parameters

  • unit_category (string): The unit_category name (e.g., 'amount_substance', 'pressure', 'mass', 'length')
  • value (number): The numeric value to be converted
  • from (string): The source unit key (e.g., 'mol', 'atm', 'mm')
  • to (string): The target unit key (e.g., 'mmol', 'pa', 'cm')

Returns

(number): The converted value

Example

import { convert } from 'chem-units';

convert('amount_substance', 42, 'mol', 'mmol'); // Returns 42000
convert('pressure', 1, 'atm', 'pa'); // Returns 101325
convert('length', 10, 'mm', 'cm'); // Returns 1

unitConversion(unit_category, targetUnit, value)

Parameters

  • type (string): The unit type/category
  • targetUnit (string): The unit to convert the value to
  • value (string | number): The value to be converted

Returns

(number): The converted value


genUnits(unit_category)

Returns a list of available units for a given unit category.

Parameters

  • unit_category (string): The unit type/category

Returns

(Array): List of available units for the specified type

Example

import { genUnits } from 'chem-units';

const pressureUnits = genUnits('pressure');
console.log(pressureUnits);
// Returns array of available pressure units

Supported Units

For a complete list of supported units and categories, see the Supported Units for System Defined Field documentation.

Contributing

chem-units provides commonly used units of measurement in chemistry. If you don't find a suitable unit for your application, please feel free to:

  • Open an issue on GitHub
  • Submit a pull request with your proposed changes
  • Contact the Maintainer

We welcome contributions to expand the library's capabilities!

Maintainer

This project is maintained by:

Feel free to reach out if you have any questions or suggestions!