|
| 1 | +// This files has functions to convert different temperature units |
| 2 | +// Functions take temperature value as a arguement and returns corresponding converted value |
| 3 | + |
| 4 | +const celsiusToFahrenheit = (celsius) => { |
| 5 | + // Wikipedia reference: https://en.wikipedia.org/wiki/Celsius |
| 6 | + // Wikipedia reference: https://en.wikipedia.org/wiki/Fahrenheit |
| 7 | + return Math.round(((celsius) * 9 / 5) + 32) |
| 8 | +} |
| 9 | + |
| 10 | +const celsiusToKelvin = (celsius) => { |
| 11 | + // Wikipedia reference: https://en.wikipedia.org/wiki/Celsius |
| 12 | + // Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin |
| 13 | + return Math.round((celsius) + 273.15) |
| 14 | +} |
| 15 | + |
| 16 | +const celsiusToRankine = (celsius) => { |
| 17 | + // Wikipedia reference: https://en.wikipedia.org/wiki/Celsius |
| 18 | + // Wikipedia reference: https://en.wikipedia.org/wiki/Rankine_scale |
| 19 | + return Math.round(((celsius) * 9 / 5) + 491.67) |
| 20 | +} |
| 21 | + |
| 22 | +const fahrenheitToCelsius = (fahrenheit) => { |
| 23 | + // Wikipedia reference: https://en.wikipedia.org/wiki/Fahrenheit |
| 24 | + // Wikipedia reference: https://en.wikipedia.org/wiki/Celsius |
| 25 | + return Math.round(((fahrenheit) - 32) * 5 / 9) |
| 26 | +} |
| 27 | + |
| 28 | +const fahrenheitToKelvin = (fahrenheit) => { |
| 29 | + // Wikipedia reference: https://en.wikipedia.org/wiki/Fahrenheit |
| 30 | + // Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin |
| 31 | + return Math.round((((fahrenheit) - 32) * 5 / 9) + 273.15) |
| 32 | +} |
| 33 | + |
| 34 | +const fahrenheitToRankine = (fahrenheit) => { |
| 35 | + // Wikipedia reference: https://en.wikipedia.org/wiki/Fahrenheit |
| 36 | + // Wikipedia reference: https://en.wikipedia.org/wiki/Rankine_scale |
| 37 | + return Math.round((fahrenheit) + 459.67) |
| 38 | +} |
| 39 | + |
| 40 | +const kelvinToCelsius = (kelvin) => { |
| 41 | + // Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin |
| 42 | + // Wikipedia reference: https://en.wikipedia.org/wiki/Celsius |
| 43 | + return Math.round((kelvin) - 273.15) |
| 44 | + |
| 45 | +} |
| 46 | + |
| 47 | +const kelvinToFahrenheit = (kelvin) => { |
| 48 | + // Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin |
| 49 | + // Wikipedia reference: https://en.wikipedia.org/wiki/Fahrenheit |
| 50 | + return Math.round((((kelvin) - 273.15) * 9 / 5) + 32) |
| 51 | +} |
| 52 | + |
| 53 | +const kelvinToRankine = (kelvin) => { |
| 54 | + // Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin |
| 55 | + // Wikipedia reference: https://en.wikipedia.org/wiki/Rankine_scale |
| 56 | + return Math.round(( (kelvin) * 9 / 5)) |
| 57 | +} |
| 58 | + |
| 59 | +const rankineToCelsius = (rankine) => { |
| 60 | + // Wikipedia reference: https://en.wikipedia.org/wiki/Rankine_scale |
| 61 | + // Wikipedia reference: https://en.wikipedia.org/wiki/Celsius |
| 62 | + return Math.round(((rankine) - 491.67) * 5 / 9) |
| 63 | +} |
| 64 | + |
| 65 | +const rankineToFahrenheit = (rankine) => { |
| 66 | + // Wikipedia reference: https://en.wikipedia.org/wiki/Rankine_scale |
| 67 | + // Wikipedia reference: https://en.wikipedia.org/wiki/Fahrenheit |
| 68 | + return Math.round((rankine) - 459.67) |
| 69 | +} |
| 70 | + |
| 71 | +const rankineToKelvin = (rankine) => { |
| 72 | + // Wikipedia reference: https://en.wikipedia.org/wiki/Rankine_scale |
| 73 | + // Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin |
| 74 | + return Math.round(((rankine) * 5 / 9)) |
| 75 | +} |
| 76 | + |
| 77 | +const reaumurToKelvin = (reaumur) => { |
| 78 | + // Reference:- http://www.csgnetwork.com/temp2conv.html |
| 79 | + return Math.round(((reaumur) * 1.25 + 273.15)) |
| 80 | +} |
| 81 | + |
| 82 | +const reaumurToFahrenheit = (reaumur) => { |
| 83 | + // Reference:- http://www.csgnetwork.com/temp2conv.html |
| 84 | + return Math.round(((reaumur) * 2.25 + 32)) |
| 85 | +} |
| 86 | + |
| 87 | +const reaumurToCelsius = (reaumur) => { |
| 88 | + // Reference:- http://www.csgnetwork.com/temp2conv.html |
| 89 | + return Math.round(((reaumur) * 1.25)) |
| 90 | +} |
| 91 | + |
| 92 | +const reaumurToRankine = (reaumur) => { |
| 93 | + // Reference:- http://www.csgnetwork.com/temp2conv.html |
| 94 | + return Math.round(((reaumur) * 2.25 + 32 + 459.67)) |
| 95 | +} |
| 96 | + |
| 97 | +export { |
| 98 | + celsiusToFahrenheit, celsiusToKelvin, celsiusToRankine, |
| 99 | + fahrenheitToCelsius, fahrenheitToKelvin, fahrenheitToRankine, |
| 100 | + kelvinToCelsius, kelvinToFahrenheit, kelvinToRankine, |
| 101 | + rankineToCelsius, rankineToFahrenheit, rankineToKelvin, |
| 102 | + reaumurToCelsius, reaumurToFahrenheit, reaumurToKelvin, reaumurToRankine |
| 103 | +} |
0 commit comments