All Projects → ben-ng → Convert Units

ben-ng / Convert Units

Licence: other
An elegant way to convert quantities between different units.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Convert Units

Length.js
📏 JavaScript library for length units conversion.
Stars: ✭ 292 (-39.17%)
Mutual labels:  measure, units, conversion, convert
Js Quantities
JavaScript library for quantity calculation and unit conversion
Stars: ✭ 335 (-30.21%)
Mutual labels:  measure, units, conversion, convert
Unitsnet
Makes life working with units of measurement just a little bit better.
Stars: ✭ 641 (+33.54%)
Mutual labels:  measure, units, conversion
Rink Rs
Unit conversion tool and library written in rust
Stars: ✭ 242 (-49.58%)
Mutual labels:  units, conversion
Units Converter
A simple utility library to measure and convert between units
Stars: ✭ 31 (-93.54%)
Mutual labels:  units, conversion
Dimensioned
Compile-time dimensional analysis for various unit systems using Rust's type system.
Stars: ✭ 235 (-51.04%)
Mutual labels:  units, conversion
Unit Api
Units of Measurement API
Stars: ✭ 140 (-70.83%)
Mutual labels:  measure, units
Membrain
🧠 Type-safe memory units
Stars: ✭ 53 (-88.96%)
Mutual labels:  measure, units
cpc
Text calculator with support for units and conversion
Stars: ✭ 89 (-81.46%)
Mutual labels:  conversion, units
qTsConverter
A simple tool to convert qt translation file (ts) to other format (xlsx / csv) and vice versa
Stars: ✭ 26 (-94.58%)
Mutual labels:  convert, conversion
convert
The smallest & fastest library for really easy, totally type-safe unit conversions in TypeScript & JavaScript.
Stars: ✭ 47 (-90.21%)
Mutual labels:  convert, conversion
Timezone Support
Lightweight time zone support for your applications or other date libraries.
Stars: ✭ 90 (-81.25%)
Mutual labels:  conversion, convert
Indriya
JSR 385 - Reference Implementation
Stars: ✭ 74 (-84.58%)
Mutual labels:  measure, units
fp-units
An FP-oriented library to easily convert CSS units.
Stars: ✭ 18 (-96.25%)
Mutual labels:  conversion, units
physikal
Mirror of Gitlab Repository
Stars: ✭ 33 (-93.12%)
Mutual labels:  conversion, units
php-unit-conversion
A library providing full PSR-4 compatible unit conversions
Stars: ✭ 47 (-90.21%)
Mutual labels:  conversion, units
Tiny Utf8
Unicode (UTF-8) capable std::string
Stars: ✭ 322 (-32.92%)
Mutual labels:  conversion
Pngquant
Lossy PNG compressor — pngquant command based on libimagequant library
Stars: ✭ 4,086 (+751.25%)
Mutual labels:  conversion
Korkut
Quick and simple image processing at the command line. 🔨
Stars: ✭ 310 (-35.42%)
Mutual labels:  convert
Use Resize Observer
A React hook that allows you to use a ResizeObserver to measure an element's size.
Stars: ✭ 305 (-36.46%)
Mutual labels:  measure

convert-units

Downloads

A handy utility for converting between quantities in different units.

Installation

npm install convert-units --save

Usage

convert-units has a simple chained API that is easy to read.

Here's how you move between the metric units for volume:

var convert = require('convert-units')

convert(1).from('l').to('ml')
// 1000

Jump from imperial to metric units the same way:

convert(1).from('lb').to('kg')
// 0.4536... (tested to 4 significant figures)

Just be careful not to ask for an impossible conversion:

convert(1).from('oz').to('fl-oz')
// throws -- you can't go from mass to volume!

You can ask convert-units to select the best unit for you. You can also optionally explicitly exclude orders of magnitude or specify a cut off number for selecting the best representation.

convert(12000).from('mm').toBest()
// 12 Meters (the smallest unit with a value above 1)

convert(12000).from('mm').toBest({ exclude: ['m'] })
// 1200 Centimeters (the smallest unit excluding meters)

convert(900).from('mm').toBest({ cutOffNumber: 10 });
// 90 Centimeters (the smallest unit with a value equal to or above 10)

convert(1000).from('mm').toBest({ cutOffNumber: 10 })
// 100 Centimeters (the smallest unit with a value equal to or above 10)

You can get a list of the measurement types supported with .measures

convert().measures()
// [ 'length', 'mass', 'volume' ]

If you ever want to know the possible conversions for a unit, just use .possibilities

convert().from('l').possibilities()
// [ 'ml', 'l', 'tsp', 'Tbs', 'fl-oz', 'cup', 'pnt', 'qt', 'gal' ]

convert().from('kg').possibilities()
// [ 'mcg', 'mg', 'g', 'kg', 'oz', 'lb' ]

You can also get the possible conversions for a measure:

convert().possibilities('mass')
// [ 'mcg', 'mg', 'g', 'kg', 'oz', 'lb', 'mt', 't' ]

You can also get the all the available units:

convert().possibilities()
// [ 'mm', 'cm', 'm', 'in', 'ft-us', 'ft', 'mi', 'mcg', 'mg', 'g', 'kg', 'oz', 'lb', 'mt', 't', 'ml', 'l', 'tsp', 'Tbs', 'fl-oz', 'cup', 'pnt', 'qt', 'gal', 'ea', 'dz' ];

To get a detailed description of a unit, use describe

convert().describe('kg')
/*
  {
    abbr: 'kg'
  , measure: 'mass'
  , system: 'metric'
  , singular: 'Kilogram'
  , plural: 'Kilograms'
  }
*/

To get detailed descriptions of all units, use list.

convert().list()
/*
  [{
    abbr: 'kg'
  , measure: 'mass'
  , system: 'metric'
  , singular: 'Kilogram'
  , plural: 'Kilograms'
  }, ...]
*/

You can also get detailed descriptions of all units for a measure:

convert().list('mass')
/*
  [{
    abbr: 'kg'
  , measure: 'mass'
  , system: 'metric'
  , singular: 'Kilogram'
  , plural: 'Kilograms'
  }, ...]
*/

Supported Units

Length

  • mm
  • cm
  • m
  • in
  • ft-us
  • ft
  • fathom
  • mi
  • nMi

Area

  • mm2
  • cm2
  • m2
  • ha
  • km2
  • in2
  • ft2
  • ac
  • mi2

Mass

  • mcg
  • mg
  • g
  • kg
  • oz
  • lb
  • mt
  • t

Volume

  • mm3
  • cm3
  • ml
  • l
  • kl
  • m3
  • km3
  • tsp
  • Tbs
  • in3
  • fl-oz
  • cup
  • pnt
  • qt
  • gal
  • ft3
  • yd3

Volume Flow Rate

  • mm3/s
  • cm3/s
  • ml/s
  • cl/s
  • dl/s
  • l/s
  • l/min
  • l/h
  • kl/s
  • kl/min
  • kl/h
  • m3/s
  • m3/min
  • m3/h
  • km3/s
  • tsp/s
  • Tbs/s
  • in3/s
  • in3/min
  • in3/h
  • fl-oz/s
  • fl-oz/min
  • fl-oz/h
  • cup/s
  • pnt/s
  • pnt/min
  • pnt/h
  • qt/s
  • gal/s
  • gal/min
  • gal/h
  • ft3/s
  • ft3/min
  • ft3/h
  • yd3/s
  • yd3/min
  • yd3/h'

Temperature

  • C
  • F
  • K
  • R

Time

  • ns
  • mu
  • ms
  • s
  • min
  • h
  • d
  • week
  • month
  • year

Frequency

  • Hz
  • mHz
  • kHz
  • MHz
  • GHz
  • THz
  • rpm
  • deg/s
  • rad/s

Speed

  • m/s
  • km/h
  • m/h
  • knot
  • ft/s

Pace

  • s/m
  • min/km
  • s/ft
  • min/mi

Pressure

  • Pa
  • hPa
  • kPa
  • MPa
  • bar
  • torr
  • psi
  • ksi

Digital

  • b
  • Kb
  • Mb
  • Gb
  • Tb
  • B
  • KB
  • MB
  • GB
  • TB

Illuminance

  • lx
  • ft-cd

Parts-Per

  • ppm
  • ppb
  • ppt
  • ppq

Voltage

  • V
  • mV
  • kV

Current

  • A
  • mA
  • kA

Power

  • W
  • mW
  • kW
  • MW
  • GW

Apparent Power

  • VA
  • mVA
  • kVA
  • MVA
  • GVA

Reactive Power

  • VAR
  • mVAR
  • kVAR
  • MVAR
  • GVAR

Energy

  • Wh
  • mWh
  • kWh
  • MWh
  • GWh
  • J
  • kJ

Reactive Energy

  • VARh
  • mVARh
  • kVARh
  • MVARh
  • GVARh

Angle

  • deg
  • rad
  • grad
  • arcmin
  • arcsec

Charge

  • c
  • mC
  • μC
  • nC
  • pC

Force

  • N
  • kN
  • lbf

Acceleration

  • g (g-force)
  • m/s2

Want More?

Adding new measurement sets is easy. Take a look at lib/definitions to see how it's done.

License

Copyright (c) 2013-2017 Ben Ng and Contributors, http://benng.me

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].