2.0.2 • Published 24 days ago

@hugoalh/pressure v2.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
24 days ago

Pressure (NodeJS)

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

ReleasesLatest (GitHub Latest Release Date)Pre (GitHub Latest Pre-Release Date)
GitHub GitHub Total DownloadsGitHub Latest Release VersionGitHub Latest Pre-Release Version
NPM NPM Total DownloadsNPM Latest Release VersionNPM Latest Pre-Release Version

📝 Description

A NodeJS module to convert pressure units.

Units of pressure are from "Wikipedia - Pressure measurement - Units".

Name ASCIIName StandardSymbol ASCIISymbol Standard... (*: Exclusive)
[SI] PascalPascalPascalPaPa
BarBarBarbarbar
Pound Per Square InchPoundPerSquareInchPound Per Square Inchpsipsi
Standard AtmosphereStandardAtmosphereStandard Atmosphereatmatm
Technical AtmosphereTechnicalAtmosphereTechnical Atmosphereatat
TorrTorrTorrTorrTorr

📋 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 | string = "Pa"): Pressure;
      .toJSON(keyType: PressureToJSONKeyType = "symbolASCII"): { [x: string]: number; };// Get all of the units value.
      .toStringASCII(unit: PressureUnits | string = "Pa"): string;// Get unit's value with ASCII symbol.
      .toStringStandard(unit: PressureUnits | string = "Pa"): string;// Get unit's value with Standard symbol.
      .toValue(unit: PressureUnits | string = "Pa"): number;// Get unit's value.
    
    Pressure.difference(a: Pressure, b: Pressure): PressureDifference;// Calculate pressure difference by units.
    Pressure.unit(unit: PressureUnits | string): 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";
  • type 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"
3.0.0-beta.1

24 days ago

2.0.2

11 months ago

2.0.1

11 months ago

2.0.0

12 months ago

2.0.0-beta.1

1 year ago

1.0.2

1 year ago

1.0.3

1 year ago

1.0.1

2 years ago

1.0.0

2 years ago