-
Notifications
You must be signed in to change notification settings - Fork 1
/
metric.min.js
1 lines (1 loc) · 6.04 KB
/
metric.min.js
1
!function(e){"use strict";var a="1.0.1",s=function(e){throw new Error(e)},t=function(e){if(null!==e){if(!isNaN(e))return Number(e);s("This function allows only numbers.")}else s("You can't test a null value.")},n={distance:{ly:{name:"light-year",base:9460731e9},km:{name:"kilometer",base:1e3},hm:{name:"hectometer",base:100},dam:{name:"decameter",base:10},m:{name:"meter",base:1},dm:{name:"decimeter",base:.1},cm:{name:"centimeter",base:.01},mm:{name:"millimeter",base:.001},um:{name:"micrometer",base:1e-6},nm:{name:"nanometer",base:1e-9},mi:{name:"mile",base:1609.344},nmi:{name:"nautical mile",base:1852},in:{name:"inch",base:.0254},ft:{name:"feet",base:.3048},yd:{name:"yard",base:.9144}},area:{sqkm:{name:"square kilometer",base:1e6},sqm:{name:"square meter",base:1},sqmi:{name:"square mile",base:259e4},sqyd:{name:"square yard",base:.83613119866071},sqft:{name:"square foot",base:.092903},sqin:{name:"square inch",base:64516e-8},ha:{name:"hectare",base:1e4},ac:{name:"acre",base:4046.86}},time:{y:{name:"year",base:31536e3},w:{name:"week",base:604800},d:{name:"day",base:86400},hr:{name:"hour",base:3600},min:{name:"minute",base:60},s:{name:"second",base:1},ds:{name:"decisecond",base:.1},cs:{name:"centisecond",base:.01},ms:{name:"millisecond",base:.001},us:{name:"microsecond",base:1e-6},ns:{name:"nanosecond",base:1e-9}},temperature:{c:{name:"celsius"},f:{name:"fahrenheit"},k:{name:"kelvin"}},mass:{lt:{name:"long ton",base:1016050},t:{name:"tonne",base:1e6},kg:{name:"kilogram",base:1e3},hg:{name:"hectogram",base:100},dag:{name:"decagram",base:10},g:{name:"gram",base:1},dg:{name:"decigram",base:.1},cg:{name:"centigram",base:.01},mg:{name:"milligram",base:.001},ug:{name:"microgram",base:1e-6},ng:{name:"nanogram",base:1e-9},st:{name:"stone",base:6350.29318},lb:{name:"pound",base:453.59237},oz:{name:"ounce",base:28.349523}},speed:{mph:{name:"miles per hour",base:1.60934},kph:{name:"kilometers per hour",base:1},fts:{name:"foots per second",base:1.09728},ms:{name:"meters per second",base:3.6},kn:{name:"knot",base:1.852}},angle:{deg:{name:"degree"},rad:{name:"radian"}}},m=function(e){var a=n[f.value.type][e],s=n[f.value.type][f.value.name];return f.value.value*s.base/a.base},r=function(e){return function(){return m(e)}},o=function(e){if(e===f.value.name)return f.value.value;switch(f.value.name){case"c":return"k"===e?f.value.value+273.15:1.8*f.value.value+32;case"k":return"f"===e?1.8*(f.value.value-273.15)+32:f.value.value-273.15;case"f":return"c"===e?(f.value.value-32)/1.8:(f.value.value-32)/1.8+273.15}},i=function(e){return function(){return o(e)}},c=function(e){if(e===f.value.name)return f.value.value;switch(f.value.name){case"deg":return f.value.value*(Math.PI/180);case"rad":return f.value.value*(180/Math.PI)}},u=function(e){return function(){return c(e)}},d={};d.distance={toLightyears:r("ly"),toKilometers:r("km"),toHectometers:r("hm"),toDecameters:r("dam"),toMeters:r("m"),toDecimeters:r("dm"),toCentimeters:r("cm"),toMillimimeters:r("mm"),toMicrometers:r("um"),toNanometers:r("nm"),toMiles:r("mi"),toNauticalMiles:r("nmi"),toInches:r("in"),toFeets:r("ft"),toYards:r("yd")},d.area={toSquareKilometers:r("sqkm"),toSquareMeters:r("sqm"),toSquareMiles:r("sqmi"),toSquareYards:r("sqyd"),toSquareFoots:r("sqft"),toSquareInches:r("sqin"),toHectares:r("ha"),toAcres:r("ac")},d.time={toYears:r("y"),toWeeks:r("w"),toDays:r("d"),toHours:r("hr"),toMinutes:r("min"),toSeconds:r("s"),toDeciseconds:r("ds"),toCentiseconds:r("cs"),toMilliseconds:r("ms"),toMicroseconds:r("us"),toNanoseconds:r("ns")},d.temperature={toKelvin:i("k"),toFahrenheit:i("f"),toCelsius:i("c")},d.mass={toLongtons:r("lt"),toTonnes:r("t"),toKilograms:r("kg"),toHectograms:r("hg"),toDecagrams:r("dag"),toGrams:r("g"),toDecigrams:r("dg"),toCentigrams:r("cg"),toMillimigrams:r("mg"),toMicrograms:r("ug"),toNanograms:r("ng"),toStones:r("st"),toPounds:r("lb"),toOunces:r("oz")},d.speed={toMilesPerHour:r("mph"),toKilometersPerHour:r("kph"),toFootsPerSecond:r("fts"),toMetersPerSeconds:r("ms"),toKnot:r("kn")},d.angle={toDegrees:u("deg"),toRadians:u("rad")};var l=function(e,a){return function(s){var n=this;return(t(s)||0===Number(s))&&n.setValue({name:e,value:Number(s),type:a}),d[a]}},g={lightyears:l("ly","distance"),kilometers:l("km","distance"),hectometers:l("hm","distance"),decameters:l("dam","distance"),meters:l("m","distance"),decimeters:l("dm","distance"),centimeters:l("cm","distance"),millimeters:l("mm","distance"),micrometers:l("um","distance"),nanometers:l("nm","distance"),miles:l("mi","distance"),nauticalMiles:l("nmi","distance"),inches:l("in","distance"),feets:l("ft","distance"),yards:l("yd","distance"),squareKilometers:l("sqkm","area"),squareMeters:l("sqm","area"),squareMiles:l("sqmi","area"),squareYards:l("sqyd","area"),squareFoots:l("sqft","area"),squareInches:l("sqin","area"),hectares:l("ha","area"),acres:l("ac","area"),years:l("y","time"),weeks:l("w","time"),days:l("d","time"),hours:l("hr","time"),minutes:l("min","time"),seconds:l("s","time"),deciseconds:l("ds","time"),centiseconds:l("cs","time"),milliseconds:l("ms","time"),microseconds:l("us","time"),nanoseconds:l("ns","time"),kelvin:l("k","temperature"),fahrenheit:l("f","temperature"),celsius:l("c","temperature"),longtons:l("lt","mass"),tonnes:l("t","mass"),kilograms:l("kg","mass"),hectograms:l("hg","mass"),decagrams:l("dag","mass"),grams:l("g","mass"),decigrams:l("dg","mass"),centigrams:l("cg","mass"),milligrams:l("mg","mass"),micrograms:l("ug","mass"),nanograms:l("ng","mass"),stones:l("st","mass"),pounds:l("lb","mass"),ounces:l("oz","mass"),milesPerHour:l("mph","speed"),kilometersPerHour:l("kph","speed"),footsPerSecond:l("fts","speed"),metersPerSecond:l("ms","speed"),knot:l("kn","speed"),degrees:l("deg","angle"),radians:l("rad","angle")},b=function(){this.value={},this.setValue=function(e){"object"==typeof e&&e?e.name&&(e.value||0===e.value)&&e.type&&(this.value=e):s("Expected an object")}};b.prototype=g;var f=new b;if(f.version=a,"object"==typeof exports&&"object"==typeof module)module.exports=f;else if("function"==typeof define&&define.amd)define(function(){return f});else if("undefined"!=typeof e||"undefined"!=typeof self){var h="undefined"!=typeof e?e:self;h.metric=f}}(this);