3.3.2 • Published 5 years ago

measure-ts v3.3.2

Weekly downloads
20
License
MIT
Repository
github
Last release
5 years ago

measure-unit

Convert or print measurement units units: length, area, volume and weight.

Usage

Class based API:

import Measure from 'measure-ts'

const measure = new Measure(1)
Number(measure) // 1
String(measure) // "1 m"

const ha = new Measure(2, 'ha') // 2
String(ha) // "2 ha"
const ha2m2 = ha.to('m2') // 20_000
String(ha2m2) // "20_000 m²"

Pretty unit chooser:

import { measureFrom } from 'measure-ts'

const measure = measureFrom('m2', 'a', 'ha', 'km2')
measure(1) // 1 || "1 m²"
measure(100) // 100 || "1 a"
measure(10000) // 10_000 ||  "1 ha"
measure(1000000) // 1_000_000 ||  "1 km²"

Units

SI prefixes

Meters (normal, square and cubic), grams and litres are prefixable with SI prefixes. Examples:

KeyUnitValue
kmkilometre1 * 1000
cmcentimetre1 / 100
mlmililitre1 / 1000
km2square kilometre1 1000 1000

Length

KeyNameValue
mMeter (meter)1
MNautical MileMetre * 1852
inInchFoot / 12
ftFootYard / 3
ydYardMetre * 0.9144
chChainYard * 22
furFurlongChain * 10
miMileFurlong * 8
leaLeagueMile * 3

Area

Square length units can be used to measure area, i.e. "m2".

KeyNameValue
aAreMetre * 2 100
haHectareAre * 100
acAcreYard * 2 4840

Volume

Cubic length units can be used to measure volume, i.e. "m3".

I'm not sure how imperial volume units "really" work (in practise), so create an issue or PR to fix anything that is a miss.

KeyNameValue
lLitreMetre ** 3 / 1000
pintPint (Imperial)Litre * 0.568
galGallon (American)Inch ** 3 / 231
qtQuart (American)Gallon / 4
ptPint (American)Gallon / 8
giGill (American)Gallon / 32
fl ozFluid Ounce (American)Gallon / 128
peckPeckLitre * 8.809_768
buBushelLitre * 35.239_070_166_88

Mass (weight)

KeyNameValue
kgKilogram1
gGramKilogram / 1000
lbPoundGram * 453.592_37
tTonne (Metric Ton)Kilogram * 1000
tonAmerican Ton (short)Pound * 2000
longtonImperial Ton (long)Pound * 2240
cwtAmerican Hundredweight (short)Pound * 100
longcwtImperial Hundredweight (long)Pound * 112
qrQuarterPound * 25
stStonePound * 14
ozOuncePound / 16
drDrachmPound / 256
grGrainPound / 7000

Roadmap

Lincese

MIT © Farmis

3.3.2

5 years ago

3.3.1

5 years ago

3.3.0

5 years ago

3.2.3

5 years ago

3.2.2

5 years ago

3.2.1

5 years ago

3.2.0

5 years ago

3.1.5

5 years ago

3.1.4

5 years ago

3.1.3

5 years ago

3.1.2

5 years ago

3.1.1

5 years ago

3.1.0

5 years ago

3.0.0

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago