@hugoalh/temperature
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

Temperature (NodeJS)

License GitHub Repository GitHub Stars GitHub Contributors GitHub Issues GitHub Pull Requests GitHub Discussions CodeFactor Grade

Releases Latest (GitHub Latest Release Date) Pre (GitHub Latest Pre-Release Date)
GitHub GitHub Total Downloads GitHub Latest Release Version GitHub Latest Pre-Release Version
NPM NPM Total Downloads NPM Latest Release Version NPM Latest Pre-Release Version

📝 Description

A NodeJS module to convert temperature units.

Units of temperature are from "Wikipedia - Conversion of scales of temperature".

Name ASCII Name Standard Symbol ASCII Symbol Standard ... (*: Exclusive)
[SI] Kelvin Kelvin Kelvin K K
Celsius Celsius Celsius C °C
Delisle Delisle Delisle De °De D
Fahrenheit Fahrenheit Fahrenheit F °F
Rankine Rankine Rankine R °R Ra
Réaumur Reaumur Réaumur Re °Ré r
Rømer Roemer Rømer Ro °Rø Romer
Sir Isaac Newton's degree of temperature (Newton) Newton Newton N °N

📋 Notice

This module uses the built in JavaScript Number type, which is a floating point number with a limited precision of 64 bits, about 16 digits. Floating point numbers round-off errors can occur during calculations:

0.1 + 0.2;
//=> 0.30000000000000004

In most cases, round-off errors do not matter, they have no significant impact on the results. However, it looks ugly when displaying output to a user. A solution is to limit the precision just below the actual precision of 16 digits in the displayed output:

(0.1 + 0.2).toPrecision(14);
//=> 0.3

📚 Documentation

Getting Started

  • NodeJS ^ v12.20.0 || ^ v14.15.0 || >= v16.13.0
npm install @hugoalh/temperature
/* Either */
import { ... } from "@hugoalh/temperature";// Named Import
import * as temperature from "@hugoalh/temperature";// Namespace Import
import Temperature from "@hugoalh/temperature";// Default Import (Class `Temperature`)

API

Class

  • new Temperature(value: number, unit: TemperatureUnits = "K"): Temperature;
      .toJSON(keyType: TemperatureToJSONKeyType = "symbolASCII"): { [x: string]: number; };// Get all of the units value.
      .toStringASCII(unit: TemperatureUnits = "K"): string;// Get unit's value with ASCII symbol.
      .toStringStandard(unit: TemperatureUnits = "K"): string;// Get unit's value with Standard symbol.
      .toValue(unit: TemperatureUnits = "K"): number;// Get unit's value.
    
    Temperature.difference(a: Temperature, b: Temperature): TemperatureDifference;// Calculate temperature difference by units.
    Temperature.unit(unit: TemperatureUnits): TemperatureUnitMeta;// Get a temperature unit meta.
    Temperature.units(): TemperatureUnitMeta[];// Get all of the temperature units meta.
    Temperature.unitSI(): TemperatureUnitMeta;// Get temperature SI unit meta.

Interface / Type

  • type TemperatureToJSONKeyType = "nameASCII" | "nameStandard" | "symbolASCII" | "symbolStandard";
  • interface TemperatureUnitMeta {
      isSIUnit: boolean;
      nameASCII: string;
      nameStandard: string;
      symbolASCII: string;
      symbolStandard: string;
    }

Example

new Temperature(25, "C").toValue("K");
//=> 298.15
new Temperature(25, "C").toStringStandard("K");
//=> "298.15 K"
new Temperature(298.15).toValue("C");
//=> 25
new Temperature(298.15).toStringStandard("C");
//=> "25 °C"

Package Sidebar

Install

npm i @hugoalh/temperature

Weekly Downloads

0

Version

2.0.2

License

MIT

Unpacked Size

32.5 kB

Total Files

6

Last publish

Collaborators

  • hugoalh