@typecad/jlcpcb-parts
Version:
Intelligent fuzzy search for JLCPCB electrical components with CLI interface
173 lines • 7.47 kB
TypeScript
import { ElectricalValue } from '../types/index.js';
/**
* Comprehensive utility class for converting between different electrical units and normalizing values.
*
* The UnitConverter handles the complex task of normalizing electrical values from various input formats
* to standard base units. It supports all common electrical units with proper prefix handling and
* case-sensitive distinction between similar units (e.g., MΩ vs mΩ).
*
* Supported conversions:
* - **Capacitance**: pF, nF, µF, mF → F (Farads)
* - **Resistance**: mΩ, Ω, kΩ, MΩ, GΩ → Ω (Ohms)
* - **Inductance**: nH, µH, mH, H → H (Henries)
* - **Voltage**: mV, V, kV → V (Volts)
* - **Current**: µA, mA, A → A (Amperes)
* - **Power**: mW, W, kW → W (Watts)
*
* @class UnitConverter
* @example
* ```typescript
* // Capacitance conversions
* const cap1 = UnitConverter.normalizeCapacitance(100, "nF"); // Returns 100e-9
* const cap2 = UnitConverter.normalizeCapacitance(10, "µF"); // Returns 10e-6
*
* // Resistance conversions
* const res1 = UnitConverter.normalizeResistance(10, "kΩ"); // Returns 10000
* const res2 = UnitConverter.normalizeResistance(1, "MΩ"); // Returns 1000000
*
* // Generic value normalization
* const value = UnitConverter.normalizeValue(100, "nF");
* // Returns: { value: 100e-9, unit: "F", originalText: "100nF" }
* ```
*/
export declare class UnitConverter {
/**
* Normalizes a capacitance value to the base unit of Farads (F).
*
* Supports all common capacitance units with proper prefix handling:
* - pF (picofarads): 1e-12 F
* - nF (nanofarads): 1e-9 F
* - µF/uF (microfarads): 1e-6 F
* - mF (millifarads): 1e-3 F
* - F (farads): 1 F
*
* @param value - The numerical capacitance value
* @param unit - The unit string (case-insensitive for most units)
* @returns Capacitance value normalized to Farads
*
* @example
* ```typescript
* UnitConverter.normalizeCapacitance(100, "pF"); // Returns 100e-12
* UnitConverter.normalizeCapacitance(47, "nF"); // Returns 47e-9
* UnitConverter.normalizeCapacitance(10, "µF"); // Returns 10e-6
* UnitConverter.normalizeCapacitance(1, "mF"); // Returns 1e-3
* ```
*/
static normalizeCapacitance(value: number, unit: string): number;
/**
* Normalizes a resistance value to the base unit of Ohms (Ω).
*
* Supports all common resistance units with case-sensitive prefix handling:
* - mΩ (milliohms): 1e-3 Ω (lowercase 'm')
* - Ω/ohm (ohms): 1 Ω
* - kΩ (kiloohms): 1e3 Ω
* - MΩ (megaohms): 1e6 Ω (uppercase 'M')
* - GΩ (gigaohms): 1e9 Ω
*
* **Important**: Case sensitivity matters for 'M' vs 'm' to distinguish
* between megaohms (MΩ) and milliohms (mΩ).
*
* @param value - The numerical resistance value
* @param unit - The unit string (case-sensitive for M/m distinction)
* @returns Resistance value normalized to Ohms
*
* @example
* ```typescript
* UnitConverter.normalizeResistance(500, "mΩ"); // Returns 0.5 (milliohms)
* UnitConverter.normalizeResistance(10, "kΩ"); // Returns 10000
* UnitConverter.normalizeResistance(1, "MΩ"); // Returns 1000000 (megaohms)
* UnitConverter.normalizeResistance(2.2, "GΩ"); // Returns 2.2e9
* ```
*/
static normalizeResistance(value: number, unit: string): number;
/**
* Normalizes an inductance value to Henries (H)
* @param value - The inductance value
* @param unit - The unit of the value
* @returns Value normalized to Henries
*/
static normalizeInductance(value: number, unit: string): number;
/**
* Normalizes a voltage value to Volts (V)
* @param value - The voltage value
* @param unit - The unit of the value
* @returns Value normalized to Volts
*/
static normalizeVoltage(value: number, unit: string): number;
/**
* Normalizes a frequency value to Hertz (Hz)
* @param value - The frequency value
* @param unit - The unit of the value
* @returns Value normalized to Hertz
*/
static normalizeFrequency(value: number, unit: string): number;
/**
* Normalizes a current value to Amperes (A)
* @param value - The current value
* @param unit - The unit of the value
* @returns Value normalized to Amperes
*/
static normalizeCurrent(value: number, unit: string): number;
/**
* Normalizes a temperature value to Celsius (°C)
* @param value - The temperature value
* @param unit - The unit of the value
* @returns Value normalized to Celsius
*/
static normalizeTemperature(value: number, unit: string): number;
/**
* Generic method to normalize values based on type
* @param value - The value to normalize
* @param unit - The unit of the value
* @param type - The type of measurement (capacitance, resistance, etc.)
* @returns Normalized value in base units
*/
static normalizeValue(value: number, unit: string, type: string): number;
/**
* Converts a capacitance value to the specified target unit
* @param value - The capacitance value to convert
* @param targetUnit - The target unit (pF, nF, µF, mF, F)
* @returns Converted value in the target unit
*/
static convertCapacitance(value: ElectricalValue, targetUnit: 'pF' | 'nF' | 'µF' | 'mF' | 'F'): number;
/**
* Converts a resistance value to the specified target unit
* @param value - The resistance value to convert
* @param targetUnit - The target unit (mΩ, Ω, kΩ, MΩ, GΩ)
* @returns Converted value in the target unit
*/
static convertResistance(value: ElectricalValue, targetUnit: 'mΩ' | 'Ω' | 'kΩ' | 'MΩ' | 'GΩ'): number;
/**
* Converts an inductance value to the specified target unit
* @param value - The inductance value to convert
* @param targetUnit - The target unit (nH, µH, mH, H)
* @returns Converted value in the target unit
*/
static convertInductance(value: ElectricalValue, targetUnit: 'nH' | 'µH' | 'mH' | 'H'): number;
/**
* Converts a voltage value to the specified target unit
* @param value - The voltage value to convert
* @param targetUnit - The target unit (mV, V, kV)
* @returns Converted value in the target unit
*/
static convertVoltage(value: ElectricalValue, targetUnit: 'mV' | 'V' | 'kV'): number;
/**
* Gets the most appropriate unit for displaying a capacitance value
* @param valueInF - The capacitance value in Farads
* @returns The most appropriate unit (pF, nF, µF, mF, F)
*/
static getBestCapacitanceUnit(valueInF: number): 'pF' | 'nF' | 'µF' | 'mF' | 'F';
/**
* Gets the most appropriate unit for displaying a resistance value
* @param valueInOhm - The resistance value in Ohms
* @returns The most appropriate unit (mΩ, Ω, kΩ, MΩ, GΩ)
*/
static getBestResistanceUnit(valueInOhm: number): 'mΩ' | 'Ω' | 'kΩ' | 'MΩ' | 'GΩ';
/**
* Gets the most appropriate unit for displaying an inductance value
* @param valueInH - The inductance value in Henries
* @returns The most appropriate unit (nH, µH, mH, H)
*/
static getBestInductanceUnit(valueInH: number): 'nH' | 'µH' | 'mH' | 'H';
}
//# sourceMappingURL=UnitConverter.d.ts.map