Pressure (NodeJS)
Releases | Latest () | Pre () |
---|---|---|
📝 Description
A NodeJS module to convert pressure units.
Units of pressure are from "Wikipedia - Pressure measurement - Units".
Name ASCII | Name Standard | Symbol ASCII | Symbol Standard | ... (*: Exclusive) | |
---|---|---|---|---|---|
[SI] Pascal | Pascal |
Pascal |
Pa |
Pa |
|
Bar | Bar |
Bar |
bar |
bar |
|
Pound Per Square Inch | PoundPerSquareInch |
Pound Per Square Inch |
psi |
psi |
|
Standard Atmosphere | StandardAtmosphere |
Standard Atmosphere |
atm |
atm |
|
Technical Atmosphere | TechnicalAtmosphere |
Technical Atmosphere |
at |
at |
|
Torr | Torr |
Torr |
Torr |
Torr |
📋 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/pressure
/* Either */
import { ... } from "@hugoalh/pressure";// Named Import
import * as pressure from "@hugoalh/pressure";// Namespace Import
import Pressure from "@hugoalh/pressure";// Default Import (Class `Pressure`)
API
Class
-
new Pressure(value: number, unit: PressureUnits = "Pa"): Pressure; .toJSON(keyType: PressureToJSONKeyType = "symbolASCII"): { [x: string]: number; };// Get all of the units value. .toStringASCII(unit: PressureUnits = "Pa"): string;// Get unit's value with ASCII symbol. .toStringStandard(unit: PressureUnits = "Pa"): string;// Get unit's value with Standard symbol. .toValue(unit: PressureUnits = "Pa"): number;// Get unit's value. Pressure.difference(a: Pressure, b: Pressure): PressureDifference;// Calculate pressure difference by units. Pressure.unit(unit: PressureUnits): PressureUnitMeta;// Get a pressure unit meta. Pressure.units(): PressureUnitMeta[];// Get all of the pressure units meta. Pressure.unitSI(): PressureUnitMeta;// Get pressure SI unit meta.
Interface / Type
-
type PressureToJSONKeyType = "nameASCII" | "nameStandard" | "symbolASCII" | "symbolStandard";
-
interface PressureUnitMeta { isSIUnit: boolean; nameASCII: string; nameStandard: string; symbolASCII: string; symbolStandard: string; }
Example
new Pressure(1, "Bar").toValue("Pa");
//=> 100000
new Pressure(1, "Bar").toStringStandard("Pa");
//=> "100000 Pa"
new Pressure(100000).toValue("Bar");
//=> 1
new Pressure(100000).toStringStandard("Bar");
//=> "1 bar"