Sign In

@squawk/units

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@squawk/units - npm Package Compare versions

Comparing version
0.3.0
to
0.4.0
+134
dist/fuel.d.ts
/**
* Typed unit string literals for fuel quantities to prevent unit confusion at the call site.
*
* - `gal`: US liquid gallons (3.785411784 L). The UK Imperial gallon (4.54609 L) is out of
* scope; callers working with Imperial gallons should convert to US gallons first.
* - `L`: litres.
* - `lb`: international avoirdupois pounds.
* - `kg`: kilograms.
*/
export type FuelUnit = 'gal' | 'L' | 'lb' | 'kg';
/**
* Fuel density, expressed either in kilograms per litre or pounds per US gallon.
*
* The discriminated shape forces the call site to name its unit explicitly. This
* prevents the classic silent bug where a caller passes a bare density number in the
* wrong unit (lb/gal and kg/L differ by a factor of ~0.12) and gets a plausible-looking
* but badly wrong weight. US flight-planning materials typically publish fuel density
* in `lb/gal`; SI and European sources use `kg/L`.
*/
export type FuelDensity = {
readonly kgPerL: number;
} | {
readonly lbPerGal: number;
};
/**
* Nominal fuel densities for common aviation fuels, referenced at 15 degrees C per
* industry convention. Real-world fuel density varies roughly 0.7% per 10 degrees C
* temperature change and also between refinery batches, so pilots performing precise
* weight-and-balance calculations should prefer the field-measured density printed on
* the fuel ticket. These constants are appropriate defaults for planning and estimation.
*/
export declare const FUEL_DENSITY: {
/** 100 low-lead avgas, the standard piston-aircraft fuel in the US. */
readonly '100LL': FuelDensity;
/** Jet A, the primary turbine fuel used in North America. */
readonly 'Jet A': FuelDensity;
/** Jet A-1, the international turbine fuel (lower freeze point than Jet A). */
readonly 'Jet A-1': FuelDensity;
/** Jet B, a wide-cut turbine fuel used in very cold climates. */
readonly 'Jet B': FuelDensity;
};
/**
* Converts US liquid gallons to litres.
*
* @param gallons - Fuel quantity in US gallons.
* @returns Fuel quantity in litres.
*/
export declare function gallonsToLiters(gallons: number): number;
/**
* Converts litres to US liquid gallons.
*
* @param liters - Fuel quantity in litres.
* @returns Fuel quantity in US gallons.
*/
export declare function litersToGallons(liters: number): number;
/**
* Converts pounds to kilograms.
*
* @param pounds - Fuel mass in pounds.
* @returns Fuel mass in kilograms.
*/
export declare function poundsToKilograms(pounds: number): number;
/**
* Converts kilograms to pounds.
*
* @param kilograms - Fuel mass in kilograms.
* @returns Fuel mass in pounds.
*/
export declare function kilogramsToPounds(kilograms: number): number;
/**
* Converts US gallons of fuel to pounds using the given fuel density.
*
* @param gallons - Fuel quantity in US gallons.
* @param density - Fuel density as `{ kgPerL }` or `{ lbPerGal }`.
* @returns Fuel mass in pounds.
*/
export declare function gallonsToPounds(gallons: number, density: FuelDensity): number;
/**
* Converts pounds of fuel to US gallons using the given fuel density.
*
* @param pounds - Fuel mass in pounds.
* @param density - Fuel density as `{ kgPerL }` or `{ lbPerGal }`.
* @returns Fuel quantity in US gallons.
*/
export declare function poundsToGallons(pounds: number, density: FuelDensity): number;
/**
* Converts US gallons of fuel to kilograms using the given fuel density.
*
* @param gallons - Fuel quantity in US gallons.
* @param density - Fuel density as `{ kgPerL }` or `{ lbPerGal }`.
* @returns Fuel mass in kilograms.
*/
export declare function gallonsToKilograms(gallons: number, density: FuelDensity): number;
/**
* Converts kilograms of fuel to US gallons using the given fuel density.
*
* @param kilograms - Fuel mass in kilograms.
* @param density - Fuel density as `{ kgPerL }` or `{ lbPerGal }`.
* @returns Fuel quantity in US gallons.
*/
export declare function kilogramsToGallons(kilograms: number, density: FuelDensity): number;
/**
* Converts litres of fuel to pounds using the given fuel density.
*
* @param liters - Fuel quantity in litres.
* @param density - Fuel density as `{ kgPerL }` or `{ lbPerGal }`.
* @returns Fuel mass in pounds.
*/
export declare function litersToPounds(liters: number, density: FuelDensity): number;
/**
* Converts pounds of fuel to litres using the given fuel density.
*
* @param pounds - Fuel mass in pounds.
* @param density - Fuel density as `{ kgPerL }` or `{ lbPerGal }`.
* @returns Fuel quantity in litres.
*/
export declare function poundsToLiters(pounds: number, density: FuelDensity): number;
/**
* Converts litres of fuel to kilograms using the given fuel density.
*
* @param liters - Fuel quantity in litres.
* @param density - Fuel density as `{ kgPerL }` or `{ lbPerGal }`.
* @returns Fuel mass in kilograms.
*/
export declare function litersToKilograms(liters: number, density: FuelDensity): number;
/**
* Converts kilograms of fuel to litres using the given fuel density.
*
* @param kilograms - Fuel mass in kilograms.
* @param density - Fuel density as `{ kgPerL }` or `{ lbPerGal }`.
* @returns Fuel quantity in litres.
*/
export declare function kilogramsToLiters(kilograms: number, density: FuelDensity): number;
//# sourceMappingURL=fuel.d.ts.map
{"version":3,"file":"fuel.d.ts","sourceRoot":"","sources":["../src/fuel.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;AAEjD;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAuBtF;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,EAAE;IACzB,uEAAuE;IACvE,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,6DAA6D;IAC7D,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,+EAA+E;IAC/E,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC;IAChC,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;CAM/B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAExD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,MAAM,CAI7E;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,MAAM,CAI5E;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,MAAM,CAGhF;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,MAAM,CAGlF;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,MAAM,CAG3E;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,MAAM,CAG3E;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,MAAM,CAG9E;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,MAAM,CAGjF"}
/** US liquid gallon to litre conversion factor (exact, per NIST). */
const GAL_TO_L = 3.785411784;
/** International avoirdupois pound to kilogram conversion factor (exact). */
const LB_TO_KG = 0.45359237;
/**
* Converts a {@link FuelDensity} to its kilograms-per-litre value. Both discriminated
* variants yield the same canonical internal unit, so every cross-dimension conversion
* normalizes through this helper.
*
* @param density - Fuel density in either `kg/L` or `lb/gal`.
* @returns Density in kg/L.
*/
function densityToKgPerL(density) {
if ('kgPerL' in density) {
return density.kgPerL;
}
return (density.lbPerGal * LB_TO_KG) / GAL_TO_L;
}
/**
* Nominal fuel densities for common aviation fuels, referenced at 15 degrees C per
* industry convention. Real-world fuel density varies roughly 0.7% per 10 degrees C
* temperature change and also between refinery batches, so pilots performing precise
* weight-and-balance calculations should prefer the field-measured density printed on
* the fuel ticket. These constants are appropriate defaults for planning and estimation.
*/
export const FUEL_DENSITY = {
'100LL': { kgPerL: 0.72 },
'Jet A': { kgPerL: 0.803 },
'Jet A-1': { kgPerL: 0.804 },
'Jet B': { kgPerL: 0.762 },
};
/**
* Converts US liquid gallons to litres.
*
* @param gallons - Fuel quantity in US gallons.
* @returns Fuel quantity in litres.
*/
export function gallonsToLiters(gallons) {
return gallons * GAL_TO_L;
}
/**
* Converts litres to US liquid gallons.
*
* @param liters - Fuel quantity in litres.
* @returns Fuel quantity in US gallons.
*/
export function litersToGallons(liters) {
return liters / GAL_TO_L;
}
/**
* Converts pounds to kilograms.
*
* @param pounds - Fuel mass in pounds.
* @returns Fuel mass in kilograms.
*/
export function poundsToKilograms(pounds) {
return pounds * LB_TO_KG;
}
/**
* Converts kilograms to pounds.
*
* @param kilograms - Fuel mass in kilograms.
* @returns Fuel mass in pounds.
*/
export function kilogramsToPounds(kilograms) {
return kilograms / LB_TO_KG;
}
/**
* Converts US gallons of fuel to pounds using the given fuel density.
*
* @param gallons - Fuel quantity in US gallons.
* @param density - Fuel density as `{ kgPerL }` or `{ lbPerGal }`.
* @returns Fuel mass in pounds.
*/
export function gallonsToPounds(gallons, density) {
const kgPerL = densityToKgPerL(density);
const kilograms = gallons * GAL_TO_L * kgPerL;
return kilograms / LB_TO_KG;
}
/**
* Converts pounds of fuel to US gallons using the given fuel density.
*
* @param pounds - Fuel mass in pounds.
* @param density - Fuel density as `{ kgPerL }` or `{ lbPerGal }`.
* @returns Fuel quantity in US gallons.
*/
export function poundsToGallons(pounds, density) {
const kgPerL = densityToKgPerL(density);
const kilograms = pounds * LB_TO_KG;
return kilograms / kgPerL / GAL_TO_L;
}
/**
* Converts US gallons of fuel to kilograms using the given fuel density.
*
* @param gallons - Fuel quantity in US gallons.
* @param density - Fuel density as `{ kgPerL }` or `{ lbPerGal }`.
* @returns Fuel mass in kilograms.
*/
export function gallonsToKilograms(gallons, density) {
const kgPerL = densityToKgPerL(density);
return gallons * GAL_TO_L * kgPerL;
}
/**
* Converts kilograms of fuel to US gallons using the given fuel density.
*
* @param kilograms - Fuel mass in kilograms.
* @param density - Fuel density as `{ kgPerL }` or `{ lbPerGal }`.
* @returns Fuel quantity in US gallons.
*/
export function kilogramsToGallons(kilograms, density) {
const kgPerL = densityToKgPerL(density);
return kilograms / kgPerL / GAL_TO_L;
}
/**
* Converts litres of fuel to pounds using the given fuel density.
*
* @param liters - Fuel quantity in litres.
* @param density - Fuel density as `{ kgPerL }` or `{ lbPerGal }`.
* @returns Fuel mass in pounds.
*/
export function litersToPounds(liters, density) {
const kgPerL = densityToKgPerL(density);
return (liters * kgPerL) / LB_TO_KG;
}
/**
* Converts pounds of fuel to litres using the given fuel density.
*
* @param pounds - Fuel mass in pounds.
* @param density - Fuel density as `{ kgPerL }` or `{ lbPerGal }`.
* @returns Fuel quantity in litres.
*/
export function poundsToLiters(pounds, density) {
const kgPerL = densityToKgPerL(density);
return (pounds * LB_TO_KG) / kgPerL;
}
/**
* Converts litres of fuel to kilograms using the given fuel density.
*
* @param liters - Fuel quantity in litres.
* @param density - Fuel density as `{ kgPerL }` or `{ lbPerGal }`.
* @returns Fuel mass in kilograms.
*/
export function litersToKilograms(liters, density) {
const kgPerL = densityToKgPerL(density);
return liters * kgPerL;
}
/**
* Converts kilograms of fuel to litres using the given fuel density.
*
* @param kilograms - Fuel mass in kilograms.
* @param density - Fuel density as `{ kgPerL }` or `{ lbPerGal }`.
* @returns Fuel quantity in litres.
*/
export function kilogramsToLiters(kilograms, density) {
const kgPerL = densityToKgPerL(density);
return kilograms / kgPerL;
}
+16
-0
import type { DistanceUnit } from './distance.js';
import type { PressureUnit } from './pressure.js';
import type { TemperatureUnit } from './temperature.js';
import type { FuelUnit } from './fuel.js';
/**

@@ -105,2 +106,17 @@ * Speed unit string literals accepted by formatSpeed. Includes 'mach' in addition

/**
* Formats a fuel quantity with its unit label.
*
* Default precision:
* - `gal`: 1 decimal place (e.g. "42.5 gal")
* - `L`: 1 decimal place
* - `lb`: 0 decimal places (pounds are typically reported as integers in POH weight-and-balance)
* - `kg`: 0 decimal places
*
* @param value - Fuel quantity in the given unit.
* @param unit - The fuel unit to display.
* @param options - Optional formatting overrides.
* @returns Formatted fuel string such as "42.5 gal" or "250 lb".
*/
export declare function formatFuel(value: number, unit: FuelUnit, options?: FormatOptions): string;
/**
* Formats a temperature value with its unit symbol.

@@ -107,0 +123,0 @@ * Optionally appends the ISA deviation when showISADeviation is true and

+1
-1

@@ -1,1 +0,1 @@

{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,IAAI,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;AAErE;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,qFAAqF;IACrF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAyB,SAAQ,aAAa;IAC7D;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,yEAAyE;IACzE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAQD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MA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a: 2,
};

@@ -138,2 +140,30 @@ const precision = options?.precision ?? defaultPrecision[unit];

/**
* Formats a fuel quantity with its unit label.
*
* Default precision:
* - `gal`: 1 decimal place (e.g. "42.5 gal")
* - `L`: 1 decimal place
* - `lb`: 0 decimal places (pounds are typically reported as integers in POH weight-and-balance)
* - `kg`: 0 decimal places
*
* @param value - Fuel quantity in the given unit.
* @param unit - The fuel unit to display.
* @param options - Optional formatting overrides.
* @returns Formatted fuel string such as "42.5 gal" or "250 lb".
*/
export function formatFuel(value, unit, options) {
const defaultPrecision = {
gal: 1,
L: 1,
lb: 0,
kg: 0,
};
const precision = options?.precision ?? defaultPrecision[unit];
const formatted = new Intl.NumberFormat(options?.locale, {
minimumFractionDigits: precision,
maximumFractionDigits: precision,
}).format(value);
return `${formatted} ${unit}`;
}
/**
* Formats a temperature value with its unit symbol.

@@ -140,0 +170,0 @@ * Optionally appends the ISA deviation when showISADeviation is true and

@@ -21,2 +21,3 @@ /**

export * as temperature from './temperature.js';
export * as fuel from './fuel.js';
export * as angle from './angle.js';

@@ -23,0 +24,0 @@ export * as isa from './isa.js';

@@ -1,1 +0,1 @@

{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC"}
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC"}

@@ -21,4 +21,5 @@ /**

export * as temperature from './temperature.js';
export * as fuel from './fuel.js';
export * as angle from './angle.js';
export * as isa from './isa.js';
export * as format from './format.js';
/**
* Typed unit string literals for pressure values to prevent unit confusion at the call site.
*
* `mb` (millibar) is numerically identical to `hPa` by SI definition (CGPM 1983,
* 1 mb = 100 Pa = 1 hPa). It is retained as a distinct unit so call sites can match
* whichever label the source data uses: METAR SLP groups report "mb", Q-code altimeter
* groups report "hPa".
*/
export type PressureUnit = 'inHg' | 'hPa' | 'mmHg';
export type PressureUnit = 'inHg' | 'hPa' | 'mmHg' | 'mb' | 'kPa';
/**

@@ -52,2 +57,99 @@ * ISA sea-level standard pressure in hPa.

/**
* Converts hectopascals to kilopascals.
* @param hectopascals - Pressure in hPa.
* @returns Pressure in kPa.
*/
export declare function hectopascalsToKilopascals(hectopascals: number): number;
/**
* Converts kilopascals to hectopascals.
* @param kilopascals - Pressure in kPa.
* @returns Pressure in hPa.
*/
export declare function kilopascalsToHectopascals(kilopascals: number): number;
/**
* Converts hectopascals to millibars. Numerically an identity because 1 mb = 1 hPa
* by SI definition; exposed as a named pair so call sites can match the label their
* data source uses (e.g. METAR SLP reports "mb", Q-code altimeter groups report "hPa").
*
* @param hectopascals - Pressure in hPa.
* @returns Pressure in mb.
*/
export declare function hectopascalsToMillibars(hectopascals: number): number;
/**
* Converts millibars to hectopascals. Identity conversion; see
* {@link hectopascalsToMillibars}.
*
* @param millibars - Pressure in mb.
* @returns Pressure in hPa.
*/
export declare function millibarsToHectopascals(millibars: number): number;
/**
* Converts inches of mercury to kilopascals.
* @param inchesOfMercury - Pressure in inHg.
* @returns Pressure in kPa.
*/
export declare function inchesOfMercuryToKilopascals(inchesOfMercury: number): number;
/**
* Converts kilopascals to inches of mercury.
* @param kilopascals - Pressure in kPa.
* @returns Pressure in inHg.
*/
export declare function kilopascalsToInchesOfMercury(kilopascals: number): number;
/**
* Converts inches of mercury to millibars. Numerically equivalent to
* {@link inchesOfMercuryToHectopascals}; exposed for call-site clarity when the
* source data uses the "mb" label.
*
* @param inchesOfMercury - Pressure in inHg.
* @returns Pressure in mb.
*/
export declare function inchesOfMercuryToMillibars(inchesOfMercury: number): number;
/**
* Converts millibars to inches of mercury. See {@link inchesOfMercuryToMillibars}.
*
* @param millibars - Pressure in mb.
* @returns Pressure in inHg.
*/
export declare function millibarsToInchesOfMercury(millibars: number): number;
/**
* Converts kilopascals to millibars.
* @param kilopascals - Pressure in kPa.
* @returns Pressure in mb.
*/
export declare function kilopascalsToMillibars(kilopascals: number): number;
/**
* Converts millibars to kilopascals.
* @param millibars - Pressure in mb.
* @returns Pressure in kPa.
*/
export declare function millibarsToKilopascals(millibars: number): number;
/**
* Converts millibars to millimetres of mercury. Numerically equivalent to
* {@link hectopascalsToMillimetersOfMercury}; exposed for call-site clarity.
*
* @param millibars - Pressure in mb.
* @returns Pressure in mmHg.
*/
export declare function millibarsToMillimetersOfMercury(millibars: number): number;
/**
* Converts millimetres of mercury to millibars. See
* {@link millibarsToMillimetersOfMercury}.
*
* @param millimetersOfMercury - Pressure in mmHg.
* @returns Pressure in mb.
*/
export declare function millimetersOfMercuryToMillibars(millimetersOfMercury: number): number;
/**
* Converts kilopascals to millimetres of mercury.
* @param kilopascals - Pressure in kPa.
* @returns Pressure in mmHg.
*/
export declare function kilopascalsToMillimetersOfMercury(kilopascals: number): number;
/**
* Converts millimetres of mercury to kilopascals.
* @param millimetersOfMercury - Pressure in mmHg.
* @returns Pressure in kPa.
*/
export declare function millimetersOfMercuryToKilopascals(millimetersOfMercury: number): number;
/**
* Converts QNH (sea-level altimeter setting) to QFE (field elevation pressure)

@@ -54,0 +156,0 @@ * for a given airfield elevation.

@@ -1,1 +0,1 @@

{"version":3,"file":"pressure.d.ts","sourceRoot":"","sources":["../src/pressure.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,CAAC;AAoBnD;;;GAGG;AACH,QAAA,MAAM,UAAU,UAAU,CAAC;AAE3B;;;GAGG;AACH,QAAA,MAAM,WAAW,WAAW,CAAC;AAuB7B;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAE7E;AAED;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAE1E;AAED;;;;GAIG;AACH,wBAAgB,kCAAkC,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAE/E;AAED;;;;GAIG;AACH,wBAAgB,kCAAkC,CAAC,oBAAoB,EAAE,MAAM,GAAG,MAAM,CAEvF;AAED;;;;GAIG;AACH,wBAAgB,qCAAqC,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAErF;AAED;;;;GAIG;AACH,wBAAgB,qCAAqC,CAAC,oBAAoB,EAAE,MAAM,GAAG,MAAM,CAE1F;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,GAAG,MAAM,CAG5E;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,GAAG,MAAM,CAG5E;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,kBAAkB,CAAC,mBA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 1013.25;
/** Conversion factor: 1 kPa = 10 hPa (exact, SI definition). */
const KPA_TO_HPA = 10;
/**

@@ -91,2 +93,127 @@ * ISA sea-level standard pressure in hPa.

/**
* Converts hectopascals to kilopascals.
* @param hectopascals - Pressure in hPa.
* @returns Pressure in kPa.
*/
export function hectopascalsToKilopascals(hectopascals) {
return hectopascals / KPA_TO_HPA;
}
/**
* Converts kilopascals to hectopascals.
* @param kilopascals - Pressure in kPa.
* @returns Pressure in hPa.
*/
export function kilopascalsToHectopascals(kilopascals) {
return kilopascals * KPA_TO_HPA;
}
/**
* Converts hectopascals to millibars. Numerically an identity because 1 mb = 1 hPa
* by SI definition; exposed as a named pair so call sites can match the label their
* data source uses (e.g. METAR SLP reports "mb", Q-code altimeter groups report "hPa").
*
* @param hectopascals - Pressure in hPa.
* @returns Pressure in mb.
*/
export function hectopascalsToMillibars(hectopascals) {
return hectopascals;
}
/**
* Converts millibars to hectopascals. Identity conversion; see
* {@link hectopascalsToMillibars}.
*
* @param millibars - Pressure in mb.
* @returns Pressure in hPa.
*/
export function millibarsToHectopascals(millibars) {
return millibars;
}
/**
* Converts inches of mercury to kilopascals.
* @param inchesOfMercury - Pressure in inHg.
* @returns Pressure in kPa.
*/
export function inchesOfMercuryToKilopascals(inchesOfMercury) {
return (inchesOfMercury * INHG_TO_HPA) / KPA_TO_HPA;
}
/**
* Converts kilopascals to inches of mercury.
* @param kilopascals - Pressure in kPa.
* @returns Pressure in inHg.
*/
export function kilopascalsToInchesOfMercury(kilopascals) {
return (kilopascals * KPA_TO_HPA) / INHG_TO_HPA;
}
/**
* Converts inches of mercury to millibars. Numerically equivalent to
* {@link inchesOfMercuryToHectopascals}; exposed for call-site clarity when the
* source data uses the "mb" label.
*
* @param inchesOfMercury - Pressure in inHg.
* @returns Pressure in mb.
*/
export function inchesOfMercuryToMillibars(inchesOfMercury) {
return inchesOfMercury * INHG_TO_HPA;
}
/**
* Converts millibars to inches of mercury. See {@link inchesOfMercuryToMillibars}.
*
* @param millibars - Pressure in mb.
* @returns Pressure in inHg.
*/
export function millibarsToInchesOfMercury(millibars) {
return millibars / INHG_TO_HPA;
}
/**
* Converts kilopascals to millibars.
* @param kilopascals - Pressure in kPa.
* @returns Pressure in mb.
*/
export function kilopascalsToMillibars(kilopascals) {
return kilopascals * KPA_TO_HPA;
}
/**
* Converts millibars to kilopascals.
* @param millibars - Pressure in mb.
* @returns Pressure in kPa.
*/
export function millibarsToKilopascals(millibars) {
return millibars / KPA_TO_HPA;
}
/**
* Converts millibars to millimetres of mercury. Numerically equivalent to
* {@link hectopascalsToMillimetersOfMercury}; exposed for call-site clarity.
*
* @param millibars - Pressure in mb.
* @returns Pressure in mmHg.
*/
export function millibarsToMillimetersOfMercury(millibars) {
return millibars * HPA_TO_MMHG;
}
/**
* Converts millimetres of mercury to millibars. See
* {@link millibarsToMillimetersOfMercury}.
*
* @param millimetersOfMercury - Pressure in mmHg.
* @returns Pressure in mb.
*/
export function millimetersOfMercuryToMillibars(millimetersOfMercury) {
return millimetersOfMercury / HPA_TO_MMHG;
}
/**
* Converts kilopascals to millimetres of mercury.
* @param kilopascals - Pressure in kPa.
* @returns Pressure in mmHg.
*/
export function kilopascalsToMillimetersOfMercury(kilopascals) {
return kilopascals * KPA_TO_HPA * HPA_TO_MMHG;
}
/**
* Converts millimetres of mercury to kilopascals.
* @param millimetersOfMercury - Pressure in mmHg.
* @returns Pressure in kPa.
*/
export function millimetersOfMercuryToKilopascals(millimetersOfMercury) {
return millimetersOfMercury / HPA_TO_MMHG / KPA_TO_HPA;
}
/**
* Converts QNH (sea-level altimeter setting) to QFE (field elevation pressure)

@@ -93,0 +220,0 @@ * for a given airfield elevation.

{
"name": "@squawk/units",
"version": "0.3.0",
"version": "0.4.0",
"type": "module",

@@ -5,0 +5,0 @@ "description": "Aviation-aware unit conversion and formatting utilities",

@@ -5,3 +5,3 @@ <h1><img src="../../assets/squawk-logo.svg" alt="squawk logo" width="48" height="48" style="vertical-align: middle">&nbsp; @squawk/units</h1>

Aviation-aware unit conversion and formatting utilities. Conversions and formatters for speed, distance, altitude, pressure, temperature, and angle—plus ISA standard atmosphere calculations and compressible-flow aerodynamics.
Aviation-aware unit conversion and formatting utilities. Conversions and formatters for speed, distance, altitude, pressure, temperature, fuel, and angle, plus ISA standard atmosphere calculations and compressible-flow aerodynamics.

@@ -29,2 +29,3 @@ **[Documentation](https://neilcochran.github.io/squawk/modules/_squawk_units.html)**

temperature,
fuel,
angle,

@@ -46,2 +47,3 @@ isa,

const hpa = pressure.inchesOfMercuryToHectopascals(29.92);
const kpa = pressure.hectopascalsToKilopascals(hpa);
const qfe = pressure.qnhToQfe(1013.25, 5280); // Denver elevation

@@ -52,2 +54,6 @@

// Fuel conversions (density-aware volume <-> mass)
const jetALbs = fuel.gallonsToPounds(40, fuel.FUEL_DENSITY['Jet A']);
const avgasKg = fuel.litersToKilograms(200, fuel.FUEL_DENSITY['100LL']);
// Angle conversions

@@ -76,6 +82,7 @@ const radians = angle.degreesToRadians(45);

- **Altitude:** Feet, metres (with flight-level awareness)
- **Pressure:** inHg, hPa, mmHg; QNH/QFE conversions; pressure altitude
- **Pressure:** inHg, hPa, mb, kPa, mmHg; QNH/QFE conversions; pressure altitude
- **Temperature:** Celsius, Fahrenheit, Kelvin
- **Fuel:** Gallons, litres, pounds, kilograms; density-aware volume <-> mass conversions with common fuel-type constants (100LL, Jet A, Jet A-1, Jet B)
- **Angle:** Degrees, radians
- **ISA Atmosphere:** Temperature and pressure profiles, TAS/CAS/Mach calculations, density altitude
- **Formatting:** Locale-aware number formatting, flight-level conversion, ISA deviation display