Socket
Socket
Sign inDemoInstall

simple-units

Package Overview
Dependencies
3
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    simple-units

unit converter with focus on the golden mean between simplicity, customizability and performance


Version published
Maintainers
1
Created

Readme

Source

simple-units

GitHub milestones GitHub last commit
unit converter with focus on the golden mean between simplicity, customizability and performance

Key Features

Converting

const converted = units.from(3, "cm").to("in");
console.log(converted);
// Output: 1.1811

Comparing

const c1 = units.Convertible(100, "kilometer");
const c2 = units.Convertible(1000, "meter");

if (c1.lt(c2)) {
    console.log(`${c1} is less than ${c2}!`);
} else if (c1.eq(c2)) {
    console.log(`${c1} and ${c2} are equal!`);
} else {
    console.log(`${c1} is greater than ${c2}!`);
}
// Output: 100km is greater than 1000m!

Formatting

const convertible = units.Convertible(12.2323123, "kt");
console.log(convertible.format("%.2f %s", { length: "long" }));
// Output: 12.23 knots

Customizing


const myCustomUnit = new Unit(...);

units.group("length").Editor.add(myCustomUnit);

Documentation

Read useful guides here. Read the full documentation here.

Why simple-units?

simple-units is one of the fastest unit converters (see performance tests) while being the most flexible and easiest one. It's designed to feel natural. Added to that as adding custom units to simple-units is very simple, you are not dependend on the package developer (!). Last but not least it supports a huge amount of units and powerful functionality like comparing quantities of different units or formatting them nicely.

Supported Units

Area

unitsynonyms%
%0m²%0m^2, %0m2, square %0meter, sq %0meter, sq %0metre, square %0metre, square %0meters, sq %0meters, sq %0metres, square %0metres

0: SI-Prefixes from y (yocto) to Y (yotta)

%0a%0are, %0ares

0: c(centiare), d(deciare), da(decare), h(hectare)

in²″², in^2, ″^2, ″2, in2, square inch, sq inch, square inches, sq inches-
ft²ft^2, ft2, square foot, sq foot, square feet, sq feet-
mi²mi^2, mi2, square mile, sq mile, square miles, sq miles-
yd²yd^2, yd2, square yard, sq yard, square yards, sq yards-
acacre, acres-

Current

unitsynonyms%
%0A%0ampere, %0ampere

0: SI-Prefixes from y (yocto) to Y (yotta)

Digital

unitsynonyms%
%0B%0byte, %0bytes

0: SI-Prefixes from k(kilo) to Y (yotta) and IEC-Prefixes from Ki (kibi) to Yi (yobi)

%0b%0bit, %0bits

0: SI-Prefixes from k(kilo) to Y (yotta) and IEC-Prefixes from Ki (kibi) to Yi (yobi)

Energy

unitsynonyms%
%0J%0joule, %0joule, %0joules

0: SI-Prefixes from y (yocto) to Y (yotta)

%0W%1%0watt-%1, %0watt-%1

0: SI-Prefixes from y (yocto) to Y (yotta)

1: h (hour, hours), s (second, seconds)

%0eV%0electronvolt, %0electronvolts

0: SI-Prefixes from y (yocto) to Y (yotta)

%0cal%0calorie, %0calories

0: k (kilo)

ergergs-

Force

unitsynonyms%
%0N%0newton

0: SI-Prefixes from y (yocto) to Y (yotta)

Length

unitsynonyms%
%0m%0meter, %0meters, %0metre, %0metres

0: SI-Prefixes from y (yocto) to Y (yotta)

in″, inch, inches-
ydyard, yards-
lylight-year, lightyear, light-years, lightyears-
ftfoot, feet-
mimi., mile, miles-

Mass

unitsynonyms%
%0g%0gram, %0gramme, %0grams

0: SI-Prefixes from y (yocto) to Y (yotta)

%0mt%0metric ton, %0metric tons

0: SI-Prefixes from da (deca) to Y (yotta)

tton, short ton, tons, short tons-
ozoz av, ounce, avoirdupois ounce, ounces, avoirdupois ounces-
lblb av, pound, avoirdupois pound, pound-mass, pounds, avoirdupois pounds-

Parts-Per

unitsynonyms%
ppmparts per million, part per million-
ppbparts per billion, part per billion-
pptparts per trillion, part per trillion-
ppqparts per quadrillion, part per quadrillion-

Power

unitsynonyms%
%0W%0watt, %0watts

0: SI-Prefixes from μ (micro) to Y (yotta)

%0J/%1%0joule/%1, %0joules/%1

0: SI-Prefixes from μ (micro) to Y (yotta)

1: All time units.

Pressure

unitsynonyms%
%0Pa%0pascal, %0pascals

0: SI-Prefixes from μ (micro) to Y (yotta)

barBar, Bars-
torrTorr, Torrs-
atmstandard atmosphere, standard atmospheres-
Mpsimegapound per square inch, megapounds per square inch-
psilb. p. sq. in., psia, psig, pound-force per square inch, pound per square inch, pounds per square inch-
ksikilopound per square inch, kilopounds per square inch-
inHginch of mercury, inches of mercury-

Speed

unitsynonyms%
%0m/%1%0meter/%1, %0metre/%1, %0meter per %1, %0metre per %1, %0meters/%1, %0metres/%1, %0meters per %1, %0metres per %1

0: SI-Prefixes from y (yocto) to Y (yotta)

1: Any time unit

ft/%0foot/%0, foot per %0, feet/%0, feet per %0

0: Any time unit

mi/%0mp%0, mile/%0, mile per %0, miles/%0, miles per %0

0: Any time unit

ktkn, knot, knots-
BftBeaufort-
MaM, mach, Mach-
clightspeed, light-speed-

Temperature

unitsynonyms%
°Cdegree Celsius, degrees Celsius-
°Fdegree Fahrenheit, degrees Fahrenheit-
°Rdegree Rankine, degrees Rankine-
KKelvin-

Time

unitsynonyms%
%0s%0second, %0seconds

0: SI-Prefixes from y (yocto) to d (deci)

minminute, minutes-
hhour, hours-
dday, days-
wkweek, weeks-
mthmonth, months-
ayear, years-

Voltage

unitsynonyms%
%0V%0volt, %0volts

0: SI-Prefixes from y (yocto) to Y (yotta)

Volume

unitsynonyms%
%0m³%0m^3, %0m3, cubic %0meter, cubic %0meters, cubic %0metre, cubic %0metres

0: SI-Prefixes from y (yocto) to d (deci)

%0l%0liter, %0liters, %0litre, %0litres

0: SI-Prefixes from m (milli) to k (kilo)

in³″³, in^3, ″^3, ″3, in3, cubic inch, cubic inches-
ft³ft^3, ft3, cubic foot, cubic feet-
yd³yd^3, yd3, cubic yard, cubic yards-
ccup, cups-
tspteaspoon, teaspoons-
tbsptablespoon, tablespoons-
fl ozfl-oz, fluid ounce, fluid ounces-
qtquart, quarts-
galgallon, gallons-

Keywords

FAQs

Last updated on 26 Mar 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc