2.7.2 • Published 6 years ago

mezur v2.7.2

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago

Mezur

Converting any measuring unit to any unit

NPM Version Build Status Downloads Stats

Sometimes you want to convert hours to seconds. Something you want to know how many weeks are in a decade. And sometimes, you want to know how many blinks of an eye are in a day...

Installation

npm install mezur --save

Usage example

const time = require('mezur/time')
time.hours(5).inSeconds() // 18000
time.decades(1).inWeeks() // 521.4285714285714

Also exposes the timeunit methods directly

const { hours, minutes } = require('mezur/time')
hours(3).inDays() // 0.125
minutes(60).inHours() // 1

Also possible is .asHours() or .toHours()

same for

require('mezur/angles')
require('mezur/area')
require('mezur/mass')
require('mezur/length')
require('mezur/pressure')
require('mezur/time')

There are other unit conversion packages, what gives?

Some of the other packages only give you partial conversions (i.e. minutes to seconds) without anything else. Some are great, but are not complete, so you need several packages to "collect the whole set" Some are more "complete" but without an easy way to add more units.

Building this is with intent to provide as much flexibility and extendability as possibly while keeping an easy-on-the-eyes usage, since you want to an easy and reliable API when converting, so it won't get in the way of your other important code. I believe that hours(5).inSeconds() do just that (to as much as javascript can give)

Supported Conversions

Acceleration

namesymbolvalue
centigalcgal0.0001mpsps
centigalileocgali0.0001mpsps
centimeterPerSecPerSeccmpsps0.01mpsps
feetPerHourPerHourftphph0.00000002351852mpsps
feetPerHourPerMinfphpmin0.000001411mpsps
feetPerHourSecfphps0.000084667mpsps
feetPerMinPerMinftpmpm0.000084667mpsps
feetPerMinutePerSecfpmps0.00508mpsps
feetPerSecPerSecftpsps0.3048mpsps
gUnitsgu9.80665mpsps
galgal0.01mpsps
galileogali0.01mpsps
gravityg9.80665mpsps
inchPerHourPerHourinphph0.000000001959877mpsps
inchPerHourPerMiniphpm0.0000001175926mpsps
inchPerHourPerSecondiphps0.000007055556mpsps
inchPerMinPerMininpmpm0.000007055556mpsps
inchPerMinPerSecipmps0.000423333mpsps
inchPerSecPerSecinpsps0.0254mpsps
kilogalkgal10mpsps
kilogalileokgali10mpsps
kilometerPerSecPerSeckmpsps1000mpsps
knotsPerHourknphph0.0001429012mpsps
knotsPerMillisecknpmspms514.444444444444mpsps
knotsPerMinknpmpm0.00857407407407407mpsps
knotsPerSecknpsps0.514444444444444mpsps
metersPerHourPerHourmphph0.00000007716049mpsps
metersPerMinPerMinmpmpm0.000277778mpsps
metersPerSecPerSecmpsps1
milePerHourPerHourmiphph0.000124178mpsps
milesPerMinPerMinmipmpm0.44704mpsps
milesPerSecPerSecmipsps1609.344mpsps
milligalmgal0.00001mpsps
milligalileomgali0.00001mpsps
millimeterPerSecPerSecmmpsps0.001mpsps

Angles

namesymbolvalue
arcMinutearcmin1deg / 60
arcSecondarcsec1deg / 3600
degreedeg1
gradiangrad0.9deg
hourAnglehrang15deg
milliradianmrad0.001rad
quadrantqd90deg
radianrad1deg * 180/3.141592653589793
sextantsxt60deg
turntr360deg

Area

namesymbolvalue
acreacre4046.856430051sqm
area100sqm
centcn40.468564301sqm
centiareca0.1sqm
decaredaa100sqm
deciareda10sqm
hectareha10000
squareFeetsqft0.092903035sqm
squareInchsqin0.00064516sqm
squareKilometersqkm1000000sqm
squareMetersqm1
squareYardsqy.836127392sqm

Length

namesymbolvalue
centimetercm0.01m
feetft12in
inchin0.0254m
kilometerkm1000m
meterm1
micrometermcm0.001mm
mileml1.609344km
millimetermm0.01cm
nanometernm0.001mcm
nauticalMilenml1.852km
yardyard0.9144m

Mass

namesymbolvalue
caratct0.2g
graingr0.06479891g
gramg1
imperialTonimpT1016.05kg
jinjin0.002g
kilogramkg1000g
microgrammcg0.000001g
milligrammg0.001g
ounceoz28.349523125g
poundlb453.59237g
stonest6.35029318kg
tonT1000000g
usTonusT907.18474kg

Pressure

namesymbolvalue
atmosphereatm1.01325000bar
barbar1
pascalpas0.00001bar
psipsi0.06894757293bar
torrtr0.001333223684bar

Temperature

namesymbolvalue
CelsiusC1K + 273.15
DelisleD(1K - 373.15) * (-3 / 2)
FahrenheitF(1K * 9 / 5) - 459.67
KelvinK1
NewtonN(1K - 273.15) * 33 / 100
RankineR1K * 9 / 5

Time

namesymbolvalue
centuryC10D
dayd24h
decadeD10Y
gigasecondGs31Y + 287d
hectosecondhs1m + 40s
hourh60m
killosecondks16m + 40s
megasecondMs11d + 13h + 46m + 40s
millisecondms0.001s
minutem60s
monthM31d
seconds1
terasecondTs31600Y
weekw7d
yearY365d

Development setup

yarn install
yarn test

How to extend Mezur?

Let's say you now landed on Mars, and obviously everything is in javascript because only hipsters live on Mars.

const marsUnits = [
  {
    name: 'martianDay', // or sol
    symbol: 'marsd',
    value: '24h + 39m + 35.244s'
  },
  {
    name: 'martianYear',
    symbol: 'marsY',
    value: '668.5991marsd'
  }
]

const timeUnits = require('./units/time.json') // note that angles is a js file, so PI calculates will be accurate

const marsTime = require('mezur')(timeUnits.concat(marsUnits))

marsTime.martianYears(1).inMartianDays() // 668.5991
marsTime.martianYears(1).inSeconds() // 59355048.240680404

Release History

see changelog.md

Meta

Guy Israeli – @isguyra

Distributed under the MIT license. See LICENSE for more information.

https://github.com/guyisra/mezur

Contributing

  1. Fork it (https://github.com/guyisra/mezur)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request
2.7.2

6 years ago

2.7.1

6 years ago

2.7.0

6 years ago

2.6.0

6 years ago

2.5.1

6 years ago

2.5.0

6 years ago

2.4.0

6 years ago

2.3.1

6 years ago

2.3.0

6 years ago

2.2.0

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago