UNPKG

nhb-toolbox

Version:

A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.

79 lines (78 loc) 2.32 kB
"use strict"; var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.$Volume = void 0; const base_1 = require("./base"); const constants_1 = require("./constants"); class $Volume extends base_1.$BaseConverter { static #factors = { 'cubic-millimeter': 1e-9, 'cubic-centimeter': 1e-6, 'cubic-meter': 1, 'cubic-kilometer': 1e9, 'cubic-millimetre': 1e-9, 'cubic-centimetre': 1e-6, 'cubic-metre': 1, 'cubic-kilometre': 1e9, 'cubic-inch': 0.000016387064, 'cubic-foot': 0.028316846592, 'cubic-yard': 0.764554857984, liter: 0.001, litre: 0.001, milliliter: 1e-6, millilitre: 1e-6, gallon: 0.003785411784, quart: 0.000946352946, pint: 0.000473176473, cup: 0.0002365882365, tablespoon: 0.00001478676478125, teaspoon: 0.00000492892159375, }; constructor(value, unit) { super(value, unit); } #toCubicMeters() { return this.value * _a.#factors[this.unit]; } to(target) { const base = this.#toCubicMeters(); return base / _a.#factors[target]; } toAll() { const base = this.#toCubicMeters(); const result = {}; for (const unit of constants_1.UNITS.volume) { result[unit] = base / _a.#factors[unit]; } return result; } formatTo(target, options) { const value = this.to(target); const shortLabels = { 'cubic-millimeter': 'mm³', 'cubic-centimeter': 'cm³', 'cubic-meter': 'm³', 'cubic-kilometer': 'km³', 'cubic-millimetre': 'mm³', 'cubic-centimetre': 'cm³', 'cubic-metre': 'm³', 'cubic-kilometre': 'km³', 'cubic-inch': 'in³', 'cubic-foot': 'ft³', 'cubic-yard': 'yd³', liter: 'L', litre: 'L', milliliter: 'mL', millilitre: 'mL', gallon: 'gal', quart: 'qt', pint: 'pt', cup: 'c', tablespoon: 'tbsp', teaspoon: 'tsp', }; return this.$formatTo(value, target, shortLabels, options); } } exports.$Volume = $Volume; _a = $Volume;