2 typeof define === "function" ? function (m) { define("kismet-units-js", m); } :
3 typeof exports === "object" ? function (m) { module.exports = m(); } :
4 function(m){ this.kismet_units = m(); }
9 var local_uri_prefix = "";
10 if (typeof(KISMET_URI_PREFIX) !== 'undefined')
11 local_uri_prefix = KISMET_URI_PREFIX;
15 exports.RenderTrimmedTime = function(opts) {
16 return (new Date(opts['value'] * 1000).toString()).substring(4, 25);
19 exports.RenderHumanSize = function(opts) {
20 return kismet.HumanReadableSize(opts['value']);
23 exports.DegToDir = function(deg) {
25 "N", "NNE", "NE", "ENE",
26 "E", "ESE", "SE", "SSE",
27 "S", "SSW", "SW", "WSW",
28 "W", "WNW", "NW", "NNW"
38 for (var p = 1; p < degrees.length; p++) {
40 return directions[p - 1];
43 return directions[directions.length - 1];
46 // Use our settings to make some conversion functions for distance and temperature
47 exports.renderDistance = function(k, precision = 5) {
48 if (kismet.getStorage('kismet.base.unit.distance') === 'metric' ||
49 kismet.getStorage('kismet.base.unit.distance') === '') {
51 return (k * 1000).toFixed(precision) + ' m';
54 return k.toFixed(precision) + ' km';
56 var m = (k * 0.621371);
59 return (5280 * m).toFixed(precision) + ' feet';
61 return (k * 0.621371).toFixed(precision) + ' miles';
65 // Use our settings to make some conversion functions for distance and temperature
66 exports.renderHeightDistance = function(m, precision = 5, lowest = false) {
67 if (kismet.getStorage('kismet.base.unit.distance') === 'metric' ||
68 kismet.getStorage('kismet.base.unit.distance') === '') {
69 if (m < 1000 || lowest) {
70 return m.toFixed(precision) + ' m';
73 return (m / 1000).toFixed(precision) + ' km';
75 var f = (m * 3.2808399);
77 if (f < 5280 || lowest) {
78 return f.toFixed(precision) + ' ft';
80 return (f / 5280).toFixed(precision) + ' mls';
84 exports.renderHeightDistanceUnitless = function(m, precision = 5) {
85 if (kismet.getStorage('kismet.base.unit.distance') === 'metric' ||
86 kismet.getStorage('kismet.base.unit.distance') === '') {
87 return m.toFixed(precision);
89 var f = (m * 3.2808399);
90 return f.toFixed(precision);
94 exports.renderSpeed = function(kph, precision = 5) {
95 if (kismet.getStorage('kismet.base.unit.speed') === 'metric' ||
96 kismet.getStorage('kismet.base.unit.speed') === '') {
97 return kph.toFixed(precision) + ' KPH';
99 return (kph * 0.621371).toFixed(precision) + ' MPH';
103 exports.renderSpeedUnitless = function(kph, precision = 5) {
104 if (kismet.getStorage('kismet.base.unit.speed') === 'metric' ||
105 kismet.getStorage('kismet.base.unit.speed') === '') {
106 return kph.toFixed(precision);
108 return (kph * 0.621371).toFixed(precision);
112 exports.renderTemperature = function(c, precision = 5) {
113 if (kismet.getStorage('kismet.base.unit.temp') === 'celsius' ||
114 kismet.getStorage('kismet.base.unit.temp') === '') {
115 return c.toFixed(precision) + '° C';
117 return (c * (9/5) + 32).toFixed(precision) + '° F';