convert-units
Advanced tools
Comparing version 3.0.0-beta.4 to 3.0.0-beta.5
"use strict"; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -16,4 +7,4 @@ exports.Converter = void 0; | ||
*/ | ||
var Converter = /** @class */ (function () { | ||
function Converter(measures, value) { | ||
class Converter { | ||
constructor(measures, value) { | ||
this.val = 0; | ||
@@ -33,3 +24,3 @@ this.destination = null; | ||
*/ | ||
Converter.prototype.from = function (from) { | ||
from(from) { | ||
if (this.destination != null) | ||
@@ -42,7 +33,7 @@ throw new Error('.from must be called before .to'); | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Converts the unit and returns the value | ||
*/ | ||
Converter.prototype.to = function (to) { | ||
to(to) { | ||
var _a, _b; | ||
@@ -55,4 +46,4 @@ if (this.origin == null) | ||
} | ||
var destination = this.destination; | ||
var origin = this.origin; | ||
const destination = this.destination; | ||
const origin = this.origin; | ||
// Don't change the value if origin and destination are the same | ||
@@ -64,3 +55,3 @@ if (origin.abbr === destination.abbr) { | ||
if (destination.measure != origin.measure) { | ||
throw new Error("Cannot convert incompatible measures of " + destination.measure + " and " + origin.measure); | ||
throw new Error(`Cannot convert incompatible measures of ${destination.measure} and ${origin.measure}`); | ||
} | ||
@@ -70,3 +61,3 @@ /** | ||
*/ | ||
var result = this.val * origin.unit.to_anchor; | ||
let result = this.val * origin.unit.to_anchor; | ||
/** | ||
@@ -86,13 +77,13 @@ * For some changes it's a simple shift (C to K) | ||
if (origin.system != destination.system) { | ||
var measure = this.measureData[origin.measure]; | ||
var anchors = measure.anchors; | ||
const measure = this.measureData[origin.measure]; | ||
const anchors = measure.anchors; | ||
if (anchors == null) { | ||
throw new Error("Unable to convert units. Anchors are missing for \"" + origin.measure + "\" and \"" + destination.measure + "\" measures."); | ||
throw new Error(`Unable to convert units. Anchors are missing for "${origin.measure}" and "${destination.measure}" measures.`); | ||
} | ||
var anchor = anchors[origin.system]; | ||
const anchor = anchors[origin.system]; | ||
if (anchor == null) { | ||
throw new Error("Unable to find anchor for \"" + origin.measure + "\" to \"" + destination.measure + "\". Please make sure it is defined."); | ||
throw new Error(`Unable to find anchor for "${origin.measure}" to "${destination.measure}". Please make sure it is defined.`); | ||
} | ||
var transform = (_a = anchor[destination.system]) === null || _a === void 0 ? void 0 : _a.transform; | ||
var ratio = (_b = anchor[destination.system]) === null || _b === void 0 ? void 0 : _b.ratio; | ||
const transform = (_a = anchor[destination.system]) === null || _a === void 0 ? void 0 : _a.transform; | ||
const ratio = (_b = anchor[destination.system]) === null || _b === void 0 ? void 0 : _b.ratio; | ||
if (typeof transform === 'function') { | ||
@@ -118,14 +109,14 @@ result = transform(result); | ||
return result / destination.unit.to_anchor; | ||
}; | ||
} | ||
/** | ||
* Converts the unit to the best available unit. | ||
*/ | ||
Converter.prototype.toBest = function (options) { | ||
toBest(options) { | ||
var _a, _b, _c; | ||
if (this.origin == null) | ||
throw new Error('.toBest must be called after .from'); | ||
var isNegative = this.val < 0; | ||
var exclude = []; | ||
var cutOffNumber = isNegative ? -1 : 1; | ||
var system = this.origin.system; | ||
const isNegative = this.val < 0; | ||
let exclude = []; | ||
let cutOffNumber = isNegative ? -1 : 1; | ||
let system = this.origin.system; | ||
if (typeof options === 'object') { | ||
@@ -136,3 +127,3 @@ exclude = (_a = options.exclude) !== null && _a !== void 0 ? _a : []; | ||
} | ||
var best = null; | ||
let best = null; | ||
/** | ||
@@ -143,8 +134,7 @@ Looks through every possibility for the 'best' available unit. | ||
*/ | ||
for (var _i = 0, _d = this.possibilities(); _i < _d.length; _i++) { | ||
var possibility = _d[_i]; | ||
var unit = this.describe(possibility); | ||
var isIncluded = exclude.indexOf(possibility) === -1; | ||
for (const possibility of this.possibilities()) { | ||
const unit = this.describe(possibility); | ||
const isIncluded = exclude.indexOf(possibility) === -1; | ||
if (isIncluded && unit.system === system) { | ||
var result = this.to(possibility); | ||
const result = this.to(possibility); | ||
if (isNegative ? result > cutOffNumber : result < cutOffNumber) { | ||
@@ -167,14 +157,11 @@ continue; | ||
return best; | ||
}; | ||
} | ||
/** | ||
* Finds the unit | ||
*/ | ||
Converter.prototype.getUnit = function (abbr) { | ||
var found = null; | ||
for (var _i = 0, _a = Object.entries(this.measureData); _i < _a.length; _i++) { | ||
var _b = _a[_i], measureName = _b[0], measure = _b[1]; | ||
for (var _c = 0, _d = Object.entries(measure.systems); _c < _d.length; _c++) { | ||
var _e = _d[_c], systemName = _e[0], system = _e[1]; | ||
for (var _f = 0, _g = Object.entries(system); _f < _g.length; _f++) { | ||
var _h = _g[_f], testAbbr = _h[0], unit = _h[1]; | ||
getUnit(abbr) { | ||
const found = null; | ||
for (const [measureName, measure] of Object.entries(this.measureData)) { | ||
for (const [systemName, system] of Object.entries(measure.systems)) { | ||
for (const [testAbbr, unit] of Object.entries(system)) { | ||
if (testAbbr == abbr) { | ||
@@ -192,8 +179,8 @@ return { | ||
return found; | ||
}; | ||
} | ||
/** | ||
* An alias for getUnit | ||
*/ | ||
Converter.prototype.describe = function (abbr) { | ||
var result = this.getUnit(abbr); | ||
describe(abbr) { | ||
const result = this.getUnit(abbr); | ||
if (result != null) { | ||
@@ -203,4 +190,4 @@ return this.describeUnit(result); | ||
this.throwUnsupportedUnitError(abbr); | ||
}; | ||
Converter.prototype.describeUnit = function (unit) { | ||
} | ||
describeUnit(unit) { | ||
return { | ||
@@ -213,3 +200,3 @@ abbr: unit.abbr, | ||
}; | ||
}; | ||
} | ||
/** | ||
@@ -226,14 +213,11 @@ * Detailed list of all supported units | ||
*/ | ||
Converter.prototype.list = function (measureName) { | ||
var list = []; | ||
list(measureName) { | ||
const list = []; | ||
if (measureName == null) { | ||
for (var _i = 0, _a = Object.entries(this.measureData); _i < _a.length; _i++) { | ||
var _b = _a[_i], name_1 = _b[0], measure = _b[1]; | ||
for (var _c = 0, _d = Object.entries(measure.systems); _c < _d.length; _c++) { | ||
var _e = _d[_c], systemName = _e[0], units = _e[1]; | ||
for (var _f = 0, _g = Object.entries(units); _f < _g.length; _f++) { | ||
var _h = _g[_f], abbr = _h[0], unit = _h[1]; | ||
for (const [name, measure] of Object.entries(this.measureData)) { | ||
for (const [systemName, units] of Object.entries(measure.systems)) { | ||
for (const [abbr, unit] of Object.entries(units)) { | ||
list.push(this.describeUnit({ | ||
abbr: abbr, | ||
measure: name_1, | ||
measure: name, | ||
system: systemName, | ||
@@ -247,10 +231,8 @@ unit: unit, | ||
else if (!(measureName in this.measureData)) { | ||
throw new Error("Meausre \"" + measureName + "\" not found."); | ||
throw new Error(`Meausre "${measureName}" not found.`); | ||
} | ||
else { | ||
var measure = this.measureData[measureName]; | ||
for (var _j = 0, _k = Object.entries(measure.systems); _j < _k.length; _j++) { | ||
var _l = _k[_j], systemName = _l[0], units = _l[1]; | ||
for (var _m = 0, _o = Object.entries(units); _m < _o.length; _m++) { | ||
var _p = _o[_m], abbr = _p[0], unit = _p[1]; | ||
const measure = this.measureData[measureName]; | ||
for (const [systemName, units] of Object.entries(measure.systems)) { | ||
for (const [abbr, unit] of Object.entries(units)) { | ||
list.push(this.describeUnit({ | ||
@@ -266,14 +248,12 @@ abbr: abbr, | ||
return list; | ||
}; | ||
Converter.prototype.throwUnsupportedUnitError = function (what) { | ||
var validUnits = []; | ||
for (var _i = 0, _a = Object.values(this.measureData); _i < _a.length; _i++) { | ||
var measure = _a[_i]; | ||
for (var _b = 0, _c = Object.values(measure.systems); _b < _c.length; _b++) { | ||
var systems = _c[_b]; | ||
} | ||
throwUnsupportedUnitError(what) { | ||
let validUnits = []; | ||
for (const measure of Object.values(this.measureData)) { | ||
for (const systems of Object.values(measure.systems)) { | ||
validUnits = validUnits.concat(Object.keys(systems)); | ||
} | ||
} | ||
throw new Error("Unsupported unit " + what + ", use one of: " + validUnits.join(', ')); | ||
}; | ||
throw new Error(`Unsupported unit ${what}, use one of: ${validUnits.join(', ')}`); | ||
} | ||
/** | ||
@@ -283,5 +263,5 @@ * Returns the abbreviated measures that the value can be | ||
*/ | ||
Converter.prototype.possibilities = function (forMeasure) { | ||
var possibilities = []; | ||
var list_measures = []; | ||
possibilities(forMeasure) { | ||
let possibilities = []; | ||
let list_measures = []; | ||
if (typeof forMeasure == 'string') { | ||
@@ -296,12 +276,13 @@ list_measures.push(forMeasure); | ||
} | ||
for (var _i = 0, list_measures_1 = list_measures; _i < list_measures_1.length; _i++) { | ||
var measure = list_measures_1[_i]; | ||
var systems = this.measureData[measure].systems; | ||
for (var _a = 0, _b = Object.values(systems); _a < _b.length; _a++) { | ||
var system = _b[_a]; | ||
possibilities = __spreadArray(__spreadArray([], possibilities, true), Object.keys(system), true); | ||
for (const measure of list_measures) { | ||
const systems = this.measureData[measure].systems; | ||
for (const system of Object.values(systems)) { | ||
possibilities = [ | ||
...possibilities, | ||
...Object.keys(system), | ||
]; | ||
} | ||
} | ||
return possibilities; | ||
}; | ||
} | ||
/** | ||
@@ -311,13 +292,10 @@ * Returns the abbreviated measures that the value can be | ||
*/ | ||
Converter.prototype.measures = function () { | ||
measures() { | ||
return Object.keys(this.measureData); | ||
}; | ||
return Converter; | ||
}()); | ||
} | ||
} | ||
exports.Converter = Converter; | ||
function default_1(measures) { | ||
return function (value) { | ||
return new Converter(measures, value); | ||
}; | ||
return (value) => new Converter(measures, value); | ||
} | ||
exports.default = default_1; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metric = { | ||
const metric = { | ||
'g-force': { | ||
@@ -19,7 +19,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
metric, | ||
}, | ||
}; | ||
exports.default = measure; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var SI = { | ||
const SI = { | ||
rad: { | ||
@@ -40,7 +40,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
}; | ||
exports.default = measure; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var SI = { | ||
const SI = { | ||
VA: { | ||
@@ -40,7 +40,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
}; | ||
exports.default = measure; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metric = { | ||
const metric = { | ||
nm2: { | ||
@@ -54,3 +54,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
in2: { | ||
@@ -92,6 +92,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -98,0 +98,0 @@ anchors: { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var SI = { | ||
const SI = { | ||
c: { | ||
@@ -40,7 +40,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
}; | ||
exports.default = measure; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var SI = { | ||
const SI = { | ||
A: { | ||
@@ -26,7 +26,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
}; | ||
exports.default = measure; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var bits = { | ||
const bits = { | ||
b: { | ||
@@ -16,3 +16,3 @@ name: { | ||
}, | ||
to_anchor: 1024, | ||
to_anchor: 1e3, | ||
}, | ||
@@ -24,3 +24,3 @@ Mb: { | ||
}, | ||
to_anchor: 1048576, | ||
to_anchor: 1e6, | ||
}, | ||
@@ -32,3 +32,3 @@ Gb: { | ||
}, | ||
to_anchor: 1073741824, | ||
to_anchor: 1e9, | ||
}, | ||
@@ -40,6 +40,6 @@ Tb: { | ||
}, | ||
to_anchor: 1099511627776, | ||
to_anchor: 1e12, | ||
}, | ||
}; | ||
var bytes = { | ||
const bytes = { | ||
B: { | ||
@@ -57,3 +57,3 @@ name: { | ||
}, | ||
to_anchor: 1024, | ||
to_anchor: 1e3, | ||
}, | ||
@@ -65,3 +65,3 @@ MB: { | ||
}, | ||
to_anchor: 1048576, | ||
to_anchor: 1e6, | ||
}, | ||
@@ -73,3 +73,3 @@ GB: { | ||
}, | ||
to_anchor: 1073741824, | ||
to_anchor: 1e9, | ||
}, | ||
@@ -81,9 +81,9 @@ TB: { | ||
}, | ||
to_anchor: 1099511627776, | ||
to_anchor: 1e12, | ||
}, | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
bits: bits, | ||
bytes: bytes, | ||
bits, | ||
bytes, | ||
}, | ||
@@ -90,0 +90,0 @@ anchors: { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metric = { | ||
const metric = { | ||
ea: { | ||
@@ -19,7 +19,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
metric, | ||
}, | ||
}; | ||
exports.default = measure; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var SI = { | ||
const SI = { | ||
Wh: { | ||
@@ -68,7 +68,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
}; | ||
exports.default = measure; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var SI = { | ||
const SI = { | ||
N: { | ||
@@ -26,7 +26,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
}; | ||
exports.default = measure; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var SI = { | ||
const SI = { | ||
mHz: { | ||
@@ -68,7 +68,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
}; | ||
exports.default = measure; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metric = { | ||
const metric = { | ||
lx: { | ||
@@ -12,3 +12,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
'ft-cd': { | ||
@@ -22,6 +22,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -28,0 +28,0 @@ anchors: { |
@@ -16,2 +16,3 @@ import { Measure } from '../convert'; | ||
import mass, { MassSystems, MassUnits } from './mass'; | ||
import massFlowRate, { MassFlowRateSystems, MassFlowRateUnits } from './massFlowRate'; | ||
import pace, { PaceSystems, PaceUnits } from './pace'; | ||
@@ -30,8 +31,8 @@ import partsPer, { PartsPerSystems, PartsPerUnits } from './partsPer'; | ||
import volumeFlowRate, { VolumeFlowRateSystems, VolumeFlowRateUnits } from './volumeFlowRate'; | ||
export declare type AllMeasuresSystems = AccelerationSystems | AngleSystems | ApparentPowerSystems | AreaSystems | ChargeSystems | CurrentSystems | DigitalSystems | EachSystems | EnergySystems | ForceSystems | FrequencySystems | IlluminanceSystems | LengthSystems | MassSystems | PaceSystems | PartsPerSystems | PiecesSystems | PowerSystems | PressureSystems | ReactiveEnergySystems | ReactivePowerSystems | SpeedSystems | TemperatureSystems | TimeSystems | VoltageSystems | VolumeSystems | VolumeFlowRateSystems; | ||
export declare type AllMeasuresUnits = AccelerationUnits | AngleUnits | ApparentPowerUnits | AreaUnits | ChargeUnits | CurrentUnits | DigitalUnits | EachUnits | EnergyUnits | ForceUnits | FrequencyUnits | IlluminanceUnits | LengthUnits | MassUnits | PaceUnits | PartsPerUnits | PiecesUnits | PowerUnits | PressureUnits | ReactiveEnergyUnits | ReactivePowerUnits | SpeedUnits | TemperatureUnits | TimeUnits | VoltageUnits | VolumeUnits | VolumeFlowRateUnits; | ||
export declare type AllMeasures = 'acceleration' | 'angle' | 'apparentPower' | 'area' | 'charge' | 'current' | 'digital' | 'each' | 'energy' | 'force' | 'frequency' | 'illuminance' | 'length' | 'mass' | 'pace' | 'partsPer' | 'pieces' | 'power' | 'pressure' | 'reactiveEnergy' | 'reactivePower' | 'speed' | 'temperature' | 'time' | 'voltage' | 'volume' | 'volumeFlowRate'; | ||
export declare type AllMeasuresSystems = AccelerationSystems | AngleSystems | ApparentPowerSystems | AreaSystems | ChargeSystems | CurrentSystems | DigitalSystems | EachSystems | EnergySystems | ForceSystems | FrequencySystems | IlluminanceSystems | LengthSystems | MassSystems | MassFlowRateSystems | PaceSystems | PartsPerSystems | PiecesSystems | PowerSystems | PressureSystems | ReactiveEnergySystems | ReactivePowerSystems | SpeedSystems | TemperatureSystems | TimeSystems | VoltageSystems | VolumeSystems | VolumeFlowRateSystems; | ||
export declare type AllMeasuresUnits = AccelerationUnits | AngleUnits | ApparentPowerUnits | AreaUnits | ChargeUnits | CurrentUnits | DigitalUnits | EachUnits | EnergyUnits | ForceUnits | FrequencyUnits | IlluminanceUnits | LengthUnits | MassUnits | MassFlowRateUnits | PaceUnits | PartsPerUnits | PiecesUnits | PowerUnits | PressureUnits | ReactiveEnergyUnits | ReactivePowerUnits | SpeedUnits | TemperatureUnits | TimeUnits | VoltageUnits | VolumeUnits | VolumeFlowRateUnits; | ||
export declare type AllMeasures = 'acceleration' | 'angle' | 'apparentPower' | 'area' | 'charge' | 'current' | 'digital' | 'each' | 'energy' | 'force' | 'frequency' | 'illuminance' | 'length' | 'mass' | 'massFlowRate' | 'pace' | 'partsPer' | 'pieces' | 'power' | 'pressure' | 'reactiveEnergy' | 'reactivePower' | 'speed' | 'temperature' | 'time' | 'voltage' | 'volume' | 'volumeFlowRate'; | ||
declare const allMeasures: Record<AllMeasures, Measure<AllMeasuresSystems, AllMeasuresUnits>>; | ||
export default allMeasures; | ||
export type { AccelerationSystems, AngleSystems, ApparentPowerSystems, AreaSystems, ChargeSystems, CurrentSystems, DigitalSystems, EachSystems, EnergySystems, ForceSystems, FrequencySystems, IlluminanceSystems, LengthSystems, MassSystems, PaceSystems, PartsPerSystems, PiecesSystems, PowerSystems, PressureSystems, ReactiveEnergySystems, ReactivePowerSystems, SpeedSystems, TemperatureSystems, TimeSystems, VoltageSystems, VolumeSystems, VolumeFlowRateSystems, AccelerationUnits, AngleUnits, ApparentPowerUnits, AreaUnits, ChargeUnits, CurrentUnits, DigitalUnits, EachUnits, EnergyUnits, ForceUnits, FrequencyUnits, IlluminanceUnits, LengthUnits, MassUnits, PaceUnits, PartsPerUnits, PiecesUnits, PowerUnits, PressureUnits, ReactiveEnergyUnits, ReactivePowerUnits, SpeedUnits, TemperatureUnits, TimeUnits, VoltageUnits, VolumeUnits, VolumeFlowRateUnits, }; | ||
export { acceleration, angle, apparentPower, area, charge, current, digital, each, energy, force, frequency, illuminance, length, mass, pace, partsPer, pieces, power, pressure, reactiveEnergy, reactivePower, speed, temperature, time, voltage, volume, volumeFlowRate, }; | ||
export { acceleration, angle, apparentPower, area, charge, current, digital, each, energy, force, frequency, illuminance, length, mass, massFlowRate, pace, partsPer, pieces, power, pressure, reactiveEnergy, reactivePower, speed, temperature, time, voltage, volume, volumeFlowRate, }; |
@@ -6,58 +6,60 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.volumeFlowRate = exports.volume = exports.voltage = exports.time = exports.temperature = exports.speed = exports.reactivePower = exports.reactiveEnergy = exports.pressure = exports.power = exports.pieces = exports.partsPer = exports.pace = exports.mass = exports.length = exports.illuminance = exports.frequency = exports.force = exports.energy = exports.each = exports.digital = exports.current = exports.charge = exports.area = exports.apparentPower = exports.angle = exports.acceleration = void 0; | ||
var acceleration_1 = __importDefault(require("./acceleration")); | ||
exports.volumeFlowRate = exports.volume = exports.voltage = exports.time = exports.temperature = exports.speed = exports.reactivePower = exports.reactiveEnergy = exports.pressure = exports.power = exports.pieces = exports.partsPer = exports.pace = exports.massFlowRate = exports.mass = exports.length = exports.illuminance = exports.frequency = exports.force = exports.energy = exports.each = exports.digital = exports.current = exports.charge = exports.area = exports.apparentPower = exports.angle = exports.acceleration = void 0; | ||
const acceleration_1 = __importDefault(require("./acceleration")); | ||
exports.acceleration = acceleration_1.default; | ||
var angle_1 = __importDefault(require("./angle")); | ||
const angle_1 = __importDefault(require("./angle")); | ||
exports.angle = angle_1.default; | ||
var apparentPower_1 = __importDefault(require("./apparentPower")); | ||
const apparentPower_1 = __importDefault(require("./apparentPower")); | ||
exports.apparentPower = apparentPower_1.default; | ||
var area_1 = __importDefault(require("./area")); | ||
const area_1 = __importDefault(require("./area")); | ||
exports.area = area_1.default; | ||
var charge_1 = __importDefault(require("./charge")); | ||
const charge_1 = __importDefault(require("./charge")); | ||
exports.charge = charge_1.default; | ||
var current_1 = __importDefault(require("./current")); | ||
const current_1 = __importDefault(require("./current")); | ||
exports.current = current_1.default; | ||
var digital_1 = __importDefault(require("./digital")); | ||
const digital_1 = __importDefault(require("./digital")); | ||
exports.digital = digital_1.default; | ||
var each_1 = __importDefault(require("./each")); | ||
const each_1 = __importDefault(require("./each")); | ||
exports.each = each_1.default; | ||
var energy_1 = __importDefault(require("./energy")); | ||
const energy_1 = __importDefault(require("./energy")); | ||
exports.energy = energy_1.default; | ||
var force_1 = __importDefault(require("./force")); | ||
const force_1 = __importDefault(require("./force")); | ||
exports.force = force_1.default; | ||
var frequency_1 = __importDefault(require("./frequency")); | ||
const frequency_1 = __importDefault(require("./frequency")); | ||
exports.frequency = frequency_1.default; | ||
var illuminance_1 = __importDefault(require("./illuminance")); | ||
const illuminance_1 = __importDefault(require("./illuminance")); | ||
exports.illuminance = illuminance_1.default; | ||
var length_1 = __importDefault(require("./length")); | ||
const length_1 = __importDefault(require("./length")); | ||
exports.length = length_1.default; | ||
var mass_1 = __importDefault(require("./mass")); | ||
const mass_1 = __importDefault(require("./mass")); | ||
exports.mass = mass_1.default; | ||
var pace_1 = __importDefault(require("./pace")); | ||
const massFlowRate_1 = __importDefault(require("./massFlowRate")); | ||
exports.massFlowRate = massFlowRate_1.default; | ||
const pace_1 = __importDefault(require("./pace")); | ||
exports.pace = pace_1.default; | ||
var partsPer_1 = __importDefault(require("./partsPer")); | ||
const partsPer_1 = __importDefault(require("./partsPer")); | ||
exports.partsPer = partsPer_1.default; | ||
var pieces_1 = __importDefault(require("./pieces")); | ||
const pieces_1 = __importDefault(require("./pieces")); | ||
exports.pieces = pieces_1.default; | ||
var power_1 = __importDefault(require("./power")); | ||
const power_1 = __importDefault(require("./power")); | ||
exports.power = power_1.default; | ||
var pressure_1 = __importDefault(require("./pressure")); | ||
const pressure_1 = __importDefault(require("./pressure")); | ||
exports.pressure = pressure_1.default; | ||
var reactiveEnergy_1 = __importDefault(require("./reactiveEnergy")); | ||
const reactiveEnergy_1 = __importDefault(require("./reactiveEnergy")); | ||
exports.reactiveEnergy = reactiveEnergy_1.default; | ||
var reactivePower_1 = __importDefault(require("./reactivePower")); | ||
const reactivePower_1 = __importDefault(require("./reactivePower")); | ||
exports.reactivePower = reactivePower_1.default; | ||
var speed_1 = __importDefault(require("./speed")); | ||
const speed_1 = __importDefault(require("./speed")); | ||
exports.speed = speed_1.default; | ||
var temperature_1 = __importDefault(require("./temperature")); | ||
const temperature_1 = __importDefault(require("./temperature")); | ||
exports.temperature = temperature_1.default; | ||
var time_1 = __importDefault(require("./time")); | ||
const time_1 = __importDefault(require("./time")); | ||
exports.time = time_1.default; | ||
var voltage_1 = __importDefault(require("./voltage")); | ||
const voltage_1 = __importDefault(require("./voltage")); | ||
exports.voltage = voltage_1.default; | ||
var volume_1 = __importDefault(require("./volume")); | ||
const volume_1 = __importDefault(require("./volume")); | ||
exports.volume = volume_1.default; | ||
var volumeFlowRate_1 = __importDefault(require("./volumeFlowRate")); | ||
const volumeFlowRate_1 = __importDefault(require("./volumeFlowRate")); | ||
exports.volumeFlowRate = volumeFlowRate_1.default; | ||
var allMeasures = { | ||
const allMeasures = { | ||
acceleration: acceleration_1.default, | ||
@@ -77,2 +79,3 @@ angle: angle_1.default, | ||
mass: mass_1.default, | ||
massFlowRate: massFlowRate_1.default, | ||
pace: pace_1.default, | ||
@@ -79,0 +82,0 @@ partsPer: partsPer_1.default, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metric = { | ||
const metric = { | ||
nm: { | ||
@@ -47,3 +47,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
in: { | ||
@@ -99,6 +99,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -105,0 +105,0 @@ anchors: { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metric = { | ||
const metric = { | ||
mcg: { | ||
@@ -40,3 +40,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
oz: { | ||
@@ -64,6 +64,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -70,0 +70,0 @@ anchors: { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metric = { | ||
const metric = { | ||
'min/km': { | ||
@@ -19,3 +19,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
'min/mi': { | ||
@@ -36,6 +36,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -42,0 +42,0 @@ anchors: { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var SI = { | ||
const SI = { | ||
ppm: { | ||
@@ -33,7 +33,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
}; | ||
exports.default = measure; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var unit = { | ||
const unit = { | ||
pcs: { | ||
@@ -96,7 +96,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
unit: unit, | ||
unit, | ||
}, | ||
}; | ||
exports.default = measure; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metric = { | ||
const metric = { | ||
W: { | ||
@@ -47,3 +47,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
'Btu/s': { | ||
@@ -71,6 +71,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -77,0 +77,0 @@ anchors: { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metric = { | ||
const metric = { | ||
Pa: { | ||
@@ -47,3 +47,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
psi: { | ||
@@ -71,6 +71,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -77,0 +77,0 @@ anchors: { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var SI = { | ||
const SI = { | ||
VARh: { | ||
@@ -40,7 +40,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
}; | ||
exports.default = measure; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var SI = { | ||
const SI = { | ||
VAR: { | ||
@@ -40,7 +40,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
}; | ||
exports.default = measure; |
import { Measure } from './../index'; | ||
export declare type SpeedUnits = SpeedMetricUnits | SpeedImperialUnits; | ||
export declare type SpeedSystems = 'metric' | 'imperial'; | ||
export declare type SpeedMetricUnits = 'm/s' | 'km/h'; | ||
export declare type SpeedImperialUnits = 'mph' | 'knot' | 'ft/s' | 'ft/min'; | ||
export declare type SpeedMetricUnits = 'm/s' | 'km/h' | 'mm/h'; | ||
export declare type SpeedImperialUnits = 'mph' | 'knot' | 'ft/s' | 'ft/min' | 'in/h'; | ||
declare const measure: Measure<SpeedSystems, SpeedUnits>; | ||
export default measure; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metric = { | ||
const metric = { | ||
'm/s': { | ||
@@ -18,4 +18,11 @@ name: { | ||
}, | ||
'mm/h': { | ||
name: { | ||
singular: 'Millimeter per hour', | ||
plural: 'Millimeters per hour', | ||
}, | ||
to_anchor: 0.000001, | ||
}, | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
mph: { | ||
@@ -49,7 +56,14 @@ name: { | ||
}, | ||
'in/h': { | ||
name: { | ||
singular: 'Inch per hour', | ||
plural: 'Inches per hour', | ||
}, | ||
to_anchor: 0.00001578, | ||
}, | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -56,0 +70,0 @@ anchors: { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metric = { | ||
const metric = { | ||
C: { | ||
@@ -21,3 +21,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
F: { | ||
@@ -39,6 +39,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -45,0 +45,0 @@ anchors: { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var daysInYear = 365.25; | ||
var SI = { | ||
const daysInYear = 365.25; | ||
const SI = { | ||
ns: { | ||
@@ -76,7 +76,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
}; | ||
exports.default = measure; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var SI = { | ||
const SI = { | ||
V: { | ||
@@ -26,7 +26,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
}; | ||
exports.default = measure; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metric = { | ||
const metric = { | ||
mm3: { | ||
@@ -125,3 +125,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
tsp: { | ||
@@ -198,6 +198,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -204,0 +204,0 @@ anchors: { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metric = { | ||
const metric = { | ||
'mm3/s': { | ||
@@ -110,3 +110,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
'tsp/s': { | ||
@@ -267,6 +267,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -273,0 +273,0 @@ anchors: { |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -29,7 +33,7 @@ if (k2 === undefined) k2 = k; | ||
exports.Converter = exports.allMeasures = void 0; | ||
var convert_1 = __importStar(require("./convert")); | ||
const convert_1 = __importStar(require("./convert")); | ||
Object.defineProperty(exports, "Converter", { enumerable: true, get: function () { return convert_1.Converter; } }); | ||
var definitions_1 = __importDefault(require("./definitions")); | ||
const definitions_1 = __importDefault(require("./definitions")); | ||
exports.allMeasures = definitions_1.default; | ||
exports.default = convert_1.default; | ||
__exportStar(require("./definitions"), exports); |
@@ -1,15 +0,6 @@ | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
/** | ||
* Represents a conversion path | ||
*/ | ||
var Converter = /** @class */ (function () { | ||
function Converter(measures, value) { | ||
export class Converter { | ||
constructor(measures, value) { | ||
this.val = 0; | ||
@@ -29,3 +20,3 @@ this.destination = null; | ||
*/ | ||
Converter.prototype.from = function (from) { | ||
from(from) { | ||
if (this.destination != null) | ||
@@ -38,7 +29,7 @@ throw new Error('.from must be called before .to'); | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Converts the unit and returns the value | ||
*/ | ||
Converter.prototype.to = function (to) { | ||
to(to) { | ||
var _a, _b; | ||
@@ -51,4 +42,4 @@ if (this.origin == null) | ||
} | ||
var destination = this.destination; | ||
var origin = this.origin; | ||
const destination = this.destination; | ||
const origin = this.origin; | ||
// Don't change the value if origin and destination are the same | ||
@@ -60,3 +51,3 @@ if (origin.abbr === destination.abbr) { | ||
if (destination.measure != origin.measure) { | ||
throw new Error("Cannot convert incompatible measures of " + destination.measure + " and " + origin.measure); | ||
throw new Error(`Cannot convert incompatible measures of ${destination.measure} and ${origin.measure}`); | ||
} | ||
@@ -66,3 +57,3 @@ /** | ||
*/ | ||
var result = this.val * origin.unit.to_anchor; | ||
let result = this.val * origin.unit.to_anchor; | ||
/** | ||
@@ -82,13 +73,13 @@ * For some changes it's a simple shift (C to K) | ||
if (origin.system != destination.system) { | ||
var measure = this.measureData[origin.measure]; | ||
var anchors = measure.anchors; | ||
const measure = this.measureData[origin.measure]; | ||
const anchors = measure.anchors; | ||
if (anchors == null) { | ||
throw new Error("Unable to convert units. Anchors are missing for \"" + origin.measure + "\" and \"" + destination.measure + "\" measures."); | ||
throw new Error(`Unable to convert units. Anchors are missing for "${origin.measure}" and "${destination.measure}" measures.`); | ||
} | ||
var anchor = anchors[origin.system]; | ||
const anchor = anchors[origin.system]; | ||
if (anchor == null) { | ||
throw new Error("Unable to find anchor for \"" + origin.measure + "\" to \"" + destination.measure + "\". Please make sure it is defined."); | ||
throw new Error(`Unable to find anchor for "${origin.measure}" to "${destination.measure}". Please make sure it is defined.`); | ||
} | ||
var transform = (_a = anchor[destination.system]) === null || _a === void 0 ? void 0 : _a.transform; | ||
var ratio = (_b = anchor[destination.system]) === null || _b === void 0 ? void 0 : _b.ratio; | ||
const transform = (_a = anchor[destination.system]) === null || _a === void 0 ? void 0 : _a.transform; | ||
const ratio = (_b = anchor[destination.system]) === null || _b === void 0 ? void 0 : _b.ratio; | ||
if (typeof transform === 'function') { | ||
@@ -114,14 +105,14 @@ result = transform(result); | ||
return result / destination.unit.to_anchor; | ||
}; | ||
} | ||
/** | ||
* Converts the unit to the best available unit. | ||
*/ | ||
Converter.prototype.toBest = function (options) { | ||
toBest(options) { | ||
var _a, _b, _c; | ||
if (this.origin == null) | ||
throw new Error('.toBest must be called after .from'); | ||
var isNegative = this.val < 0; | ||
var exclude = []; | ||
var cutOffNumber = isNegative ? -1 : 1; | ||
var system = this.origin.system; | ||
const isNegative = this.val < 0; | ||
let exclude = []; | ||
let cutOffNumber = isNegative ? -1 : 1; | ||
let system = this.origin.system; | ||
if (typeof options === 'object') { | ||
@@ -132,3 +123,3 @@ exclude = (_a = options.exclude) !== null && _a !== void 0 ? _a : []; | ||
} | ||
var best = null; | ||
let best = null; | ||
/** | ||
@@ -139,8 +130,7 @@ Looks through every possibility for the 'best' available unit. | ||
*/ | ||
for (var _i = 0, _d = this.possibilities(); _i < _d.length; _i++) { | ||
var possibility = _d[_i]; | ||
var unit = this.describe(possibility); | ||
var isIncluded = exclude.indexOf(possibility) === -1; | ||
for (const possibility of this.possibilities()) { | ||
const unit = this.describe(possibility); | ||
const isIncluded = exclude.indexOf(possibility) === -1; | ||
if (isIncluded && unit.system === system) { | ||
var result = this.to(possibility); | ||
const result = this.to(possibility); | ||
if (isNegative ? result > cutOffNumber : result < cutOffNumber) { | ||
@@ -163,14 +153,11 @@ continue; | ||
return best; | ||
}; | ||
} | ||
/** | ||
* Finds the unit | ||
*/ | ||
Converter.prototype.getUnit = function (abbr) { | ||
var found = null; | ||
for (var _i = 0, _a = Object.entries(this.measureData); _i < _a.length; _i++) { | ||
var _b = _a[_i], measureName = _b[0], measure = _b[1]; | ||
for (var _c = 0, _d = Object.entries(measure.systems); _c < _d.length; _c++) { | ||
var _e = _d[_c], systemName = _e[0], system = _e[1]; | ||
for (var _f = 0, _g = Object.entries(system); _f < _g.length; _f++) { | ||
var _h = _g[_f], testAbbr = _h[0], unit = _h[1]; | ||
getUnit(abbr) { | ||
const found = null; | ||
for (const [measureName, measure] of Object.entries(this.measureData)) { | ||
for (const [systemName, system] of Object.entries(measure.systems)) { | ||
for (const [testAbbr, unit] of Object.entries(system)) { | ||
if (testAbbr == abbr) { | ||
@@ -188,8 +175,8 @@ return { | ||
return found; | ||
}; | ||
} | ||
/** | ||
* An alias for getUnit | ||
*/ | ||
Converter.prototype.describe = function (abbr) { | ||
var result = this.getUnit(abbr); | ||
describe(abbr) { | ||
const result = this.getUnit(abbr); | ||
if (result != null) { | ||
@@ -199,4 +186,4 @@ return this.describeUnit(result); | ||
this.throwUnsupportedUnitError(abbr); | ||
}; | ||
Converter.prototype.describeUnit = function (unit) { | ||
} | ||
describeUnit(unit) { | ||
return { | ||
@@ -209,3 +196,3 @@ abbr: unit.abbr, | ||
}; | ||
}; | ||
} | ||
/** | ||
@@ -222,14 +209,11 @@ * Detailed list of all supported units | ||
*/ | ||
Converter.prototype.list = function (measureName) { | ||
var list = []; | ||
list(measureName) { | ||
const list = []; | ||
if (measureName == null) { | ||
for (var _i = 0, _a = Object.entries(this.measureData); _i < _a.length; _i++) { | ||
var _b = _a[_i], name_1 = _b[0], measure = _b[1]; | ||
for (var _c = 0, _d = Object.entries(measure.systems); _c < _d.length; _c++) { | ||
var _e = _d[_c], systemName = _e[0], units = _e[1]; | ||
for (var _f = 0, _g = Object.entries(units); _f < _g.length; _f++) { | ||
var _h = _g[_f], abbr = _h[0], unit = _h[1]; | ||
for (const [name, measure] of Object.entries(this.measureData)) { | ||
for (const [systemName, units] of Object.entries(measure.systems)) { | ||
for (const [abbr, unit] of Object.entries(units)) { | ||
list.push(this.describeUnit({ | ||
abbr: abbr, | ||
measure: name_1, | ||
measure: name, | ||
system: systemName, | ||
@@ -243,10 +227,8 @@ unit: unit, | ||
else if (!(measureName in this.measureData)) { | ||
throw new Error("Meausre \"" + measureName + "\" not found."); | ||
throw new Error(`Meausre "${measureName}" not found.`); | ||
} | ||
else { | ||
var measure = this.measureData[measureName]; | ||
for (var _j = 0, _k = Object.entries(measure.systems); _j < _k.length; _j++) { | ||
var _l = _k[_j], systemName = _l[0], units = _l[1]; | ||
for (var _m = 0, _o = Object.entries(units); _m < _o.length; _m++) { | ||
var _p = _o[_m], abbr = _p[0], unit = _p[1]; | ||
const measure = this.measureData[measureName]; | ||
for (const [systemName, units] of Object.entries(measure.systems)) { | ||
for (const [abbr, unit] of Object.entries(units)) { | ||
list.push(this.describeUnit({ | ||
@@ -262,14 +244,12 @@ abbr: abbr, | ||
return list; | ||
}; | ||
Converter.prototype.throwUnsupportedUnitError = function (what) { | ||
var validUnits = []; | ||
for (var _i = 0, _a = Object.values(this.measureData); _i < _a.length; _i++) { | ||
var measure = _a[_i]; | ||
for (var _b = 0, _c = Object.values(measure.systems); _b < _c.length; _b++) { | ||
var systems = _c[_b]; | ||
} | ||
throwUnsupportedUnitError(what) { | ||
let validUnits = []; | ||
for (const measure of Object.values(this.measureData)) { | ||
for (const systems of Object.values(measure.systems)) { | ||
validUnits = validUnits.concat(Object.keys(systems)); | ||
} | ||
} | ||
throw new Error("Unsupported unit " + what + ", use one of: " + validUnits.join(', ')); | ||
}; | ||
throw new Error(`Unsupported unit ${what}, use one of: ${validUnits.join(', ')}`); | ||
} | ||
/** | ||
@@ -279,5 +259,5 @@ * Returns the abbreviated measures that the value can be | ||
*/ | ||
Converter.prototype.possibilities = function (forMeasure) { | ||
var possibilities = []; | ||
var list_measures = []; | ||
possibilities(forMeasure) { | ||
let possibilities = []; | ||
let list_measures = []; | ||
if (typeof forMeasure == 'string') { | ||
@@ -292,12 +272,13 @@ list_measures.push(forMeasure); | ||
} | ||
for (var _i = 0, list_measures_1 = list_measures; _i < list_measures_1.length; _i++) { | ||
var measure = list_measures_1[_i]; | ||
var systems = this.measureData[measure].systems; | ||
for (var _a = 0, _b = Object.values(systems); _a < _b.length; _a++) { | ||
var system = _b[_a]; | ||
possibilities = __spreadArray(__spreadArray([], possibilities, true), Object.keys(system), true); | ||
for (const measure of list_measures) { | ||
const systems = this.measureData[measure].systems; | ||
for (const system of Object.values(systems)) { | ||
possibilities = [ | ||
...possibilities, | ||
...Object.keys(system), | ||
]; | ||
} | ||
} | ||
return possibilities; | ||
}; | ||
} | ||
/** | ||
@@ -307,12 +288,8 @@ * Returns the abbreviated measures that the value can be | ||
*/ | ||
Converter.prototype.measures = function () { | ||
measures() { | ||
return Object.keys(this.measureData); | ||
}; | ||
return Converter; | ||
}()); | ||
export { Converter }; | ||
} | ||
} | ||
export default function (measures) { | ||
return function (value) { | ||
return new Converter(measures, value); | ||
}; | ||
return (value) => new Converter(measures, value); | ||
} |
@@ -1,2 +0,2 @@ | ||
var metric = { | ||
const metric = { | ||
'g-force': { | ||
@@ -17,7 +17,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
metric, | ||
}, | ||
}; | ||
export default measure; |
@@ -1,2 +0,2 @@ | ||
var SI = { | ||
const SI = { | ||
rad: { | ||
@@ -38,7 +38,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
}; | ||
export default measure; |
@@ -1,2 +0,2 @@ | ||
var SI = { | ||
const SI = { | ||
VA: { | ||
@@ -38,7 +38,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
}; | ||
export default measure; |
@@ -1,2 +0,2 @@ | ||
var metric = { | ||
const metric = { | ||
nm2: { | ||
@@ -52,3 +52,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
in2: { | ||
@@ -90,6 +90,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -96,0 +96,0 @@ anchors: { |
@@ -1,2 +0,2 @@ | ||
var SI = { | ||
const SI = { | ||
c: { | ||
@@ -38,7 +38,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
}; | ||
export default measure; |
@@ -1,2 +0,2 @@ | ||
var SI = { | ||
const SI = { | ||
A: { | ||
@@ -24,7 +24,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
}; | ||
export default measure; |
@@ -1,2 +0,2 @@ | ||
var bits = { | ||
const bits = { | ||
b: { | ||
@@ -14,3 +14,3 @@ name: { | ||
}, | ||
to_anchor: 1024, | ||
to_anchor: 1e3, | ||
}, | ||
@@ -22,3 +22,3 @@ Mb: { | ||
}, | ||
to_anchor: 1048576, | ||
to_anchor: 1e6, | ||
}, | ||
@@ -30,3 +30,3 @@ Gb: { | ||
}, | ||
to_anchor: 1073741824, | ||
to_anchor: 1e9, | ||
}, | ||
@@ -38,6 +38,6 @@ Tb: { | ||
}, | ||
to_anchor: 1099511627776, | ||
to_anchor: 1e12, | ||
}, | ||
}; | ||
var bytes = { | ||
const bytes = { | ||
B: { | ||
@@ -55,3 +55,3 @@ name: { | ||
}, | ||
to_anchor: 1024, | ||
to_anchor: 1e3, | ||
}, | ||
@@ -63,3 +63,3 @@ MB: { | ||
}, | ||
to_anchor: 1048576, | ||
to_anchor: 1e6, | ||
}, | ||
@@ -71,3 +71,3 @@ GB: { | ||
}, | ||
to_anchor: 1073741824, | ||
to_anchor: 1e9, | ||
}, | ||
@@ -79,9 +79,9 @@ TB: { | ||
}, | ||
to_anchor: 1099511627776, | ||
to_anchor: 1e12, | ||
}, | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
bits: bits, | ||
bytes: bytes, | ||
bits, | ||
bytes, | ||
}, | ||
@@ -88,0 +88,0 @@ anchors: { |
@@ -1,2 +0,2 @@ | ||
var metric = { | ||
const metric = { | ||
ea: { | ||
@@ -17,7 +17,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
metric, | ||
}, | ||
}; | ||
export default measure; |
@@ -1,2 +0,2 @@ | ||
var SI = { | ||
const SI = { | ||
Wh: { | ||
@@ -66,7 +66,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
}; | ||
export default measure; |
@@ -1,2 +0,2 @@ | ||
var SI = { | ||
const SI = { | ||
N: { | ||
@@ -24,7 +24,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
}; | ||
export default measure; |
@@ -1,2 +0,2 @@ | ||
var SI = { | ||
const SI = { | ||
mHz: { | ||
@@ -66,7 +66,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
}; | ||
export default measure; |
@@ -1,2 +0,2 @@ | ||
var metric = { | ||
const metric = { | ||
lx: { | ||
@@ -10,3 +10,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
'ft-cd': { | ||
@@ -20,6 +20,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -26,0 +26,0 @@ anchors: { |
@@ -16,2 +16,3 @@ import { Measure } from '../convert'; | ||
import mass, { MassSystems, MassUnits } from './mass'; | ||
import massFlowRate, { MassFlowRateSystems, MassFlowRateUnits } from './massFlowRate'; | ||
import pace, { PaceSystems, PaceUnits } from './pace'; | ||
@@ -30,8 +31,8 @@ import partsPer, { PartsPerSystems, PartsPerUnits } from './partsPer'; | ||
import volumeFlowRate, { VolumeFlowRateSystems, VolumeFlowRateUnits } from './volumeFlowRate'; | ||
export declare type AllMeasuresSystems = AccelerationSystems | AngleSystems | ApparentPowerSystems | AreaSystems | ChargeSystems | CurrentSystems | DigitalSystems | EachSystems | EnergySystems | ForceSystems | FrequencySystems | IlluminanceSystems | LengthSystems | MassSystems | PaceSystems | PartsPerSystems | PiecesSystems | PowerSystems | PressureSystems | ReactiveEnergySystems | ReactivePowerSystems | SpeedSystems | TemperatureSystems | TimeSystems | VoltageSystems | VolumeSystems | VolumeFlowRateSystems; | ||
export declare type AllMeasuresUnits = AccelerationUnits | AngleUnits | ApparentPowerUnits | AreaUnits | ChargeUnits | CurrentUnits | DigitalUnits | EachUnits | EnergyUnits | ForceUnits | FrequencyUnits | IlluminanceUnits | LengthUnits | MassUnits | PaceUnits | PartsPerUnits | PiecesUnits | PowerUnits | PressureUnits | ReactiveEnergyUnits | ReactivePowerUnits | SpeedUnits | TemperatureUnits | TimeUnits | VoltageUnits | VolumeUnits | VolumeFlowRateUnits; | ||
export declare type AllMeasures = 'acceleration' | 'angle' | 'apparentPower' | 'area' | 'charge' | 'current' | 'digital' | 'each' | 'energy' | 'force' | 'frequency' | 'illuminance' | 'length' | 'mass' | 'pace' | 'partsPer' | 'pieces' | 'power' | 'pressure' | 'reactiveEnergy' | 'reactivePower' | 'speed' | 'temperature' | 'time' | 'voltage' | 'volume' | 'volumeFlowRate'; | ||
export declare type AllMeasuresSystems = AccelerationSystems | AngleSystems | ApparentPowerSystems | AreaSystems | ChargeSystems | CurrentSystems | DigitalSystems | EachSystems | EnergySystems | ForceSystems | FrequencySystems | IlluminanceSystems | LengthSystems | MassSystems | MassFlowRateSystems | PaceSystems | PartsPerSystems | PiecesSystems | PowerSystems | PressureSystems | ReactiveEnergySystems | ReactivePowerSystems | SpeedSystems | TemperatureSystems | TimeSystems | VoltageSystems | VolumeSystems | VolumeFlowRateSystems; | ||
export declare type AllMeasuresUnits = AccelerationUnits | AngleUnits | ApparentPowerUnits | AreaUnits | ChargeUnits | CurrentUnits | DigitalUnits | EachUnits | EnergyUnits | ForceUnits | FrequencyUnits | IlluminanceUnits | LengthUnits | MassUnits | MassFlowRateUnits | PaceUnits | PartsPerUnits | PiecesUnits | PowerUnits | PressureUnits | ReactiveEnergyUnits | ReactivePowerUnits | SpeedUnits | TemperatureUnits | TimeUnits | VoltageUnits | VolumeUnits | VolumeFlowRateUnits; | ||
export declare type AllMeasures = 'acceleration' | 'angle' | 'apparentPower' | 'area' | 'charge' | 'current' | 'digital' | 'each' | 'energy' | 'force' | 'frequency' | 'illuminance' | 'length' | 'mass' | 'massFlowRate' | 'pace' | 'partsPer' | 'pieces' | 'power' | 'pressure' | 'reactiveEnergy' | 'reactivePower' | 'speed' | 'temperature' | 'time' | 'voltage' | 'volume' | 'volumeFlowRate'; | ||
declare const allMeasures: Record<AllMeasures, Measure<AllMeasuresSystems, AllMeasuresUnits>>; | ||
export default allMeasures; | ||
export type { AccelerationSystems, AngleSystems, ApparentPowerSystems, AreaSystems, ChargeSystems, CurrentSystems, DigitalSystems, EachSystems, EnergySystems, ForceSystems, FrequencySystems, IlluminanceSystems, LengthSystems, MassSystems, PaceSystems, PartsPerSystems, PiecesSystems, PowerSystems, PressureSystems, ReactiveEnergySystems, ReactivePowerSystems, SpeedSystems, TemperatureSystems, TimeSystems, VoltageSystems, VolumeSystems, VolumeFlowRateSystems, AccelerationUnits, AngleUnits, ApparentPowerUnits, AreaUnits, ChargeUnits, CurrentUnits, DigitalUnits, EachUnits, EnergyUnits, ForceUnits, FrequencyUnits, IlluminanceUnits, LengthUnits, MassUnits, PaceUnits, PartsPerUnits, PiecesUnits, PowerUnits, PressureUnits, ReactiveEnergyUnits, ReactivePowerUnits, SpeedUnits, TemperatureUnits, TimeUnits, VoltageUnits, VolumeUnits, VolumeFlowRateUnits, }; | ||
export { acceleration, angle, apparentPower, area, charge, current, digital, each, energy, force, frequency, illuminance, length, mass, pace, partsPer, pieces, power, pressure, reactiveEnergy, reactivePower, speed, temperature, time, voltage, volume, volumeFlowRate, }; | ||
export { acceleration, angle, apparentPower, area, charge, current, digital, each, energy, force, frequency, illuminance, length, mass, massFlowRate, pace, partsPer, pieces, power, pressure, reactiveEnergy, reactivePower, speed, temperature, time, voltage, volume, volumeFlowRate, }; |
@@ -15,2 +15,3 @@ import acceleration from './acceleration'; | ||
import mass from './mass'; | ||
import massFlowRate from './massFlowRate'; | ||
import pace from './pace'; | ||
@@ -29,32 +30,33 @@ import partsPer from './partsPer'; | ||
import volumeFlowRate from './volumeFlowRate'; | ||
var allMeasures = { | ||
acceleration: acceleration, | ||
angle: angle, | ||
apparentPower: apparentPower, | ||
area: area, | ||
charge: charge, | ||
current: current, | ||
digital: digital, | ||
each: each, | ||
energy: energy, | ||
force: force, | ||
frequency: frequency, | ||
illuminance: illuminance, | ||
length: length, | ||
mass: mass, | ||
pace: pace, | ||
partsPer: partsPer, | ||
pieces: pieces, | ||
power: power, | ||
pressure: pressure, | ||
reactiveEnergy: reactiveEnergy, | ||
reactivePower: reactivePower, | ||
speed: speed, | ||
temperature: temperature, | ||
time: time, | ||
voltage: voltage, | ||
volume: volume, | ||
volumeFlowRate: volumeFlowRate, | ||
const allMeasures = { | ||
acceleration, | ||
angle, | ||
apparentPower, | ||
area, | ||
charge, | ||
current, | ||
digital, | ||
each, | ||
energy, | ||
force, | ||
frequency, | ||
illuminance, | ||
length, | ||
mass, | ||
massFlowRate, | ||
pace, | ||
partsPer, | ||
pieces, | ||
power, | ||
pressure, | ||
reactiveEnergy, | ||
reactivePower, | ||
speed, | ||
temperature, | ||
time, | ||
voltage, | ||
volume, | ||
volumeFlowRate, | ||
}; | ||
export default allMeasures; | ||
export { acceleration, angle, apparentPower, area, charge, current, digital, each, energy, force, frequency, illuminance, length, mass, pace, partsPer, pieces, power, pressure, reactiveEnergy, reactivePower, speed, temperature, time, voltage, volume, volumeFlowRate, }; | ||
export { acceleration, angle, apparentPower, area, charge, current, digital, each, energy, force, frequency, illuminance, length, mass, massFlowRate, pace, partsPer, pieces, power, pressure, reactiveEnergy, reactivePower, speed, temperature, time, voltage, volume, volumeFlowRate, }; |
@@ -1,2 +0,2 @@ | ||
var metric = { | ||
const metric = { | ||
nm: { | ||
@@ -45,3 +45,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
in: { | ||
@@ -97,6 +97,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -103,0 +103,0 @@ anchors: { |
@@ -1,2 +0,2 @@ | ||
var metric = { | ||
const metric = { | ||
mcg: { | ||
@@ -38,3 +38,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
oz: { | ||
@@ -62,6 +62,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -68,0 +68,0 @@ anchors: { |
@@ -1,2 +0,2 @@ | ||
var metric = { | ||
const metric = { | ||
'min/km': { | ||
@@ -17,3 +17,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
'min/mi': { | ||
@@ -34,6 +34,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -40,0 +40,0 @@ anchors: { |
@@ -1,2 +0,2 @@ | ||
var SI = { | ||
const SI = { | ||
ppm: { | ||
@@ -31,7 +31,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
}; | ||
export default measure; |
@@ -1,2 +0,2 @@ | ||
var unit = { | ||
const unit = { | ||
pcs: { | ||
@@ -94,7 +94,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
unit: unit, | ||
unit, | ||
}, | ||
}; | ||
export default measure; |
@@ -1,2 +0,2 @@ | ||
var metric = { | ||
const metric = { | ||
W: { | ||
@@ -45,3 +45,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
'Btu/s': { | ||
@@ -69,6 +69,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -75,0 +75,0 @@ anchors: { |
@@ -1,2 +0,2 @@ | ||
var metric = { | ||
const metric = { | ||
Pa: { | ||
@@ -45,3 +45,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
psi: { | ||
@@ -69,6 +69,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -75,0 +75,0 @@ anchors: { |
@@ -1,2 +0,2 @@ | ||
var SI = { | ||
const SI = { | ||
VARh: { | ||
@@ -38,7 +38,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
}; | ||
export default measure; |
@@ -1,2 +0,2 @@ | ||
var SI = { | ||
const SI = { | ||
VAR: { | ||
@@ -38,7 +38,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
}; | ||
export default measure; |
import { Measure } from './../index'; | ||
export declare type SpeedUnits = SpeedMetricUnits | SpeedImperialUnits; | ||
export declare type SpeedSystems = 'metric' | 'imperial'; | ||
export declare type SpeedMetricUnits = 'm/s' | 'km/h'; | ||
export declare type SpeedImperialUnits = 'mph' | 'knot' | 'ft/s' | 'ft/min'; | ||
export declare type SpeedMetricUnits = 'm/s' | 'km/h' | 'mm/h'; | ||
export declare type SpeedImperialUnits = 'mph' | 'knot' | 'ft/s' | 'ft/min' | 'in/h'; | ||
declare const measure: Measure<SpeedSystems, SpeedUnits>; | ||
export default measure; |
@@ -1,2 +0,2 @@ | ||
var metric = { | ||
const metric = { | ||
'm/s': { | ||
@@ -16,4 +16,11 @@ name: { | ||
}, | ||
'mm/h': { | ||
name: { | ||
singular: 'Millimeter per hour', | ||
plural: 'Millimeters per hour', | ||
}, | ||
to_anchor: 0.000001, | ||
}, | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
mph: { | ||
@@ -47,7 +54,14 @@ name: { | ||
}, | ||
'in/h': { | ||
name: { | ||
singular: 'Inch per hour', | ||
plural: 'Inches per hour', | ||
}, | ||
to_anchor: 0.00001578, | ||
}, | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -54,0 +68,0 @@ anchors: { |
@@ -1,2 +0,2 @@ | ||
var metric = { | ||
const metric = { | ||
C: { | ||
@@ -19,3 +19,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
F: { | ||
@@ -37,6 +37,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -43,0 +43,0 @@ anchors: { |
@@ -1,3 +0,3 @@ | ||
var daysInYear = 365.25; | ||
var SI = { | ||
const daysInYear = 365.25; | ||
const SI = { | ||
ns: { | ||
@@ -74,7 +74,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
}; | ||
export default measure; |
@@ -1,2 +0,2 @@ | ||
var SI = { | ||
const SI = { | ||
V: { | ||
@@ -24,7 +24,7 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
}; | ||
export default measure; |
@@ -1,2 +0,2 @@ | ||
var metric = { | ||
const metric = { | ||
mm3: { | ||
@@ -123,3 +123,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
tsp: { | ||
@@ -196,6 +196,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -202,0 +202,0 @@ anchors: { |
@@ -1,2 +0,2 @@ | ||
var metric = { | ||
const metric = { | ||
'mm3/s': { | ||
@@ -108,3 +108,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
'tsp/s': { | ||
@@ -265,6 +265,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -271,0 +271,0 @@ anchors: { |
@@ -1,10 +0,1 @@ | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
(function (factory) { | ||
@@ -25,4 +16,4 @@ if (typeof module === "object" && typeof module.exports === "object") { | ||
*/ | ||
var Converter = /** @class */ (function () { | ||
function Converter(measures, value) { | ||
class Converter { | ||
constructor(measures, value) { | ||
this.val = 0; | ||
@@ -42,3 +33,3 @@ this.destination = null; | ||
*/ | ||
Converter.prototype.from = function (from) { | ||
from(from) { | ||
if (this.destination != null) | ||
@@ -51,7 +42,7 @@ throw new Error('.from must be called before .to'); | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Converts the unit and returns the value | ||
*/ | ||
Converter.prototype.to = function (to) { | ||
to(to) { | ||
var _a, _b; | ||
@@ -64,4 +55,4 @@ if (this.origin == null) | ||
} | ||
var destination = this.destination; | ||
var origin = this.origin; | ||
const destination = this.destination; | ||
const origin = this.origin; | ||
// Don't change the value if origin and destination are the same | ||
@@ -73,3 +64,3 @@ if (origin.abbr === destination.abbr) { | ||
if (destination.measure != origin.measure) { | ||
throw new Error("Cannot convert incompatible measures of " + destination.measure + " and " + origin.measure); | ||
throw new Error(`Cannot convert incompatible measures of ${destination.measure} and ${origin.measure}`); | ||
} | ||
@@ -79,3 +70,3 @@ /** | ||
*/ | ||
var result = this.val * origin.unit.to_anchor; | ||
let result = this.val * origin.unit.to_anchor; | ||
/** | ||
@@ -95,13 +86,13 @@ * For some changes it's a simple shift (C to K) | ||
if (origin.system != destination.system) { | ||
var measure = this.measureData[origin.measure]; | ||
var anchors = measure.anchors; | ||
const measure = this.measureData[origin.measure]; | ||
const anchors = measure.anchors; | ||
if (anchors == null) { | ||
throw new Error("Unable to convert units. Anchors are missing for \"" + origin.measure + "\" and \"" + destination.measure + "\" measures."); | ||
throw new Error(`Unable to convert units. Anchors are missing for "${origin.measure}" and "${destination.measure}" measures.`); | ||
} | ||
var anchor = anchors[origin.system]; | ||
const anchor = anchors[origin.system]; | ||
if (anchor == null) { | ||
throw new Error("Unable to find anchor for \"" + origin.measure + "\" to \"" + destination.measure + "\". Please make sure it is defined."); | ||
throw new Error(`Unable to find anchor for "${origin.measure}" to "${destination.measure}". Please make sure it is defined.`); | ||
} | ||
var transform = (_a = anchor[destination.system]) === null || _a === void 0 ? void 0 : _a.transform; | ||
var ratio = (_b = anchor[destination.system]) === null || _b === void 0 ? void 0 : _b.ratio; | ||
const transform = (_a = anchor[destination.system]) === null || _a === void 0 ? void 0 : _a.transform; | ||
const ratio = (_b = anchor[destination.system]) === null || _b === void 0 ? void 0 : _b.ratio; | ||
if (typeof transform === 'function') { | ||
@@ -127,14 +118,14 @@ result = transform(result); | ||
return result / destination.unit.to_anchor; | ||
}; | ||
} | ||
/** | ||
* Converts the unit to the best available unit. | ||
*/ | ||
Converter.prototype.toBest = function (options) { | ||
toBest(options) { | ||
var _a, _b, _c; | ||
if (this.origin == null) | ||
throw new Error('.toBest must be called after .from'); | ||
var isNegative = this.val < 0; | ||
var exclude = []; | ||
var cutOffNumber = isNegative ? -1 : 1; | ||
var system = this.origin.system; | ||
const isNegative = this.val < 0; | ||
let exclude = []; | ||
let cutOffNumber = isNegative ? -1 : 1; | ||
let system = this.origin.system; | ||
if (typeof options === 'object') { | ||
@@ -145,3 +136,3 @@ exclude = (_a = options.exclude) !== null && _a !== void 0 ? _a : []; | ||
} | ||
var best = null; | ||
let best = null; | ||
/** | ||
@@ -152,8 +143,7 @@ Looks through every possibility for the 'best' available unit. | ||
*/ | ||
for (var _i = 0, _d = this.possibilities(); _i < _d.length; _i++) { | ||
var possibility = _d[_i]; | ||
var unit = this.describe(possibility); | ||
var isIncluded = exclude.indexOf(possibility) === -1; | ||
for (const possibility of this.possibilities()) { | ||
const unit = this.describe(possibility); | ||
const isIncluded = exclude.indexOf(possibility) === -1; | ||
if (isIncluded && unit.system === system) { | ||
var result = this.to(possibility); | ||
const result = this.to(possibility); | ||
if (isNegative ? result > cutOffNumber : result < cutOffNumber) { | ||
@@ -176,14 +166,11 @@ continue; | ||
return best; | ||
}; | ||
} | ||
/** | ||
* Finds the unit | ||
*/ | ||
Converter.prototype.getUnit = function (abbr) { | ||
var found = null; | ||
for (var _i = 0, _a = Object.entries(this.measureData); _i < _a.length; _i++) { | ||
var _b = _a[_i], measureName = _b[0], measure = _b[1]; | ||
for (var _c = 0, _d = Object.entries(measure.systems); _c < _d.length; _c++) { | ||
var _e = _d[_c], systemName = _e[0], system = _e[1]; | ||
for (var _f = 0, _g = Object.entries(system); _f < _g.length; _f++) { | ||
var _h = _g[_f], testAbbr = _h[0], unit = _h[1]; | ||
getUnit(abbr) { | ||
const found = null; | ||
for (const [measureName, measure] of Object.entries(this.measureData)) { | ||
for (const [systemName, system] of Object.entries(measure.systems)) { | ||
for (const [testAbbr, unit] of Object.entries(system)) { | ||
if (testAbbr == abbr) { | ||
@@ -201,8 +188,8 @@ return { | ||
return found; | ||
}; | ||
} | ||
/** | ||
* An alias for getUnit | ||
*/ | ||
Converter.prototype.describe = function (abbr) { | ||
var result = this.getUnit(abbr); | ||
describe(abbr) { | ||
const result = this.getUnit(abbr); | ||
if (result != null) { | ||
@@ -212,4 +199,4 @@ return this.describeUnit(result); | ||
this.throwUnsupportedUnitError(abbr); | ||
}; | ||
Converter.prototype.describeUnit = function (unit) { | ||
} | ||
describeUnit(unit) { | ||
return { | ||
@@ -222,3 +209,3 @@ abbr: unit.abbr, | ||
}; | ||
}; | ||
} | ||
/** | ||
@@ -235,14 +222,11 @@ * Detailed list of all supported units | ||
*/ | ||
Converter.prototype.list = function (measureName) { | ||
var list = []; | ||
list(measureName) { | ||
const list = []; | ||
if (measureName == null) { | ||
for (var _i = 0, _a = Object.entries(this.measureData); _i < _a.length; _i++) { | ||
var _b = _a[_i], name_1 = _b[0], measure = _b[1]; | ||
for (var _c = 0, _d = Object.entries(measure.systems); _c < _d.length; _c++) { | ||
var _e = _d[_c], systemName = _e[0], units = _e[1]; | ||
for (var _f = 0, _g = Object.entries(units); _f < _g.length; _f++) { | ||
var _h = _g[_f], abbr = _h[0], unit = _h[1]; | ||
for (const [name, measure] of Object.entries(this.measureData)) { | ||
for (const [systemName, units] of Object.entries(measure.systems)) { | ||
for (const [abbr, unit] of Object.entries(units)) { | ||
list.push(this.describeUnit({ | ||
abbr: abbr, | ||
measure: name_1, | ||
measure: name, | ||
system: systemName, | ||
@@ -256,10 +240,8 @@ unit: unit, | ||
else if (!(measureName in this.measureData)) { | ||
throw new Error("Meausre \"" + measureName + "\" not found."); | ||
throw new Error(`Meausre "${measureName}" not found.`); | ||
} | ||
else { | ||
var measure = this.measureData[measureName]; | ||
for (var _j = 0, _k = Object.entries(measure.systems); _j < _k.length; _j++) { | ||
var _l = _k[_j], systemName = _l[0], units = _l[1]; | ||
for (var _m = 0, _o = Object.entries(units); _m < _o.length; _m++) { | ||
var _p = _o[_m], abbr = _p[0], unit = _p[1]; | ||
const measure = this.measureData[measureName]; | ||
for (const [systemName, units] of Object.entries(measure.systems)) { | ||
for (const [abbr, unit] of Object.entries(units)) { | ||
list.push(this.describeUnit({ | ||
@@ -275,14 +257,12 @@ abbr: abbr, | ||
return list; | ||
}; | ||
Converter.prototype.throwUnsupportedUnitError = function (what) { | ||
var validUnits = []; | ||
for (var _i = 0, _a = Object.values(this.measureData); _i < _a.length; _i++) { | ||
var measure = _a[_i]; | ||
for (var _b = 0, _c = Object.values(measure.systems); _b < _c.length; _b++) { | ||
var systems = _c[_b]; | ||
} | ||
throwUnsupportedUnitError(what) { | ||
let validUnits = []; | ||
for (const measure of Object.values(this.measureData)) { | ||
for (const systems of Object.values(measure.systems)) { | ||
validUnits = validUnits.concat(Object.keys(systems)); | ||
} | ||
} | ||
throw new Error("Unsupported unit " + what + ", use one of: " + validUnits.join(', ')); | ||
}; | ||
throw new Error(`Unsupported unit ${what}, use one of: ${validUnits.join(', ')}`); | ||
} | ||
/** | ||
@@ -292,5 +272,5 @@ * Returns the abbreviated measures that the value can be | ||
*/ | ||
Converter.prototype.possibilities = function (forMeasure) { | ||
var possibilities = []; | ||
var list_measures = []; | ||
possibilities(forMeasure) { | ||
let possibilities = []; | ||
let list_measures = []; | ||
if (typeof forMeasure == 'string') { | ||
@@ -305,12 +285,13 @@ list_measures.push(forMeasure); | ||
} | ||
for (var _i = 0, list_measures_1 = list_measures; _i < list_measures_1.length; _i++) { | ||
var measure = list_measures_1[_i]; | ||
var systems = this.measureData[measure].systems; | ||
for (var _a = 0, _b = Object.values(systems); _a < _b.length; _a++) { | ||
var system = _b[_a]; | ||
possibilities = __spreadArray(__spreadArray([], possibilities, true), Object.keys(system), true); | ||
for (const measure of list_measures) { | ||
const systems = this.measureData[measure].systems; | ||
for (const system of Object.values(systems)) { | ||
possibilities = [ | ||
...possibilities, | ||
...Object.keys(system), | ||
]; | ||
} | ||
} | ||
return possibilities; | ||
}; | ||
} | ||
/** | ||
@@ -320,14 +301,11 @@ * Returns the abbreviated measures that the value can be | ||
*/ | ||
Converter.prototype.measures = function () { | ||
measures() { | ||
return Object.keys(this.measureData); | ||
}; | ||
return Converter; | ||
}()); | ||
} | ||
} | ||
exports.Converter = Converter; | ||
function default_1(measures) { | ||
return function (value) { | ||
return new Converter(measures, value); | ||
}; | ||
return (value) => new Converter(measures, value); | ||
} | ||
exports.default = default_1; | ||
}); |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metric = { | ||
const metric = { | ||
'g-force': { | ||
@@ -29,5 +29,5 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
metric, | ||
}, | ||
@@ -34,0 +34,0 @@ }; |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var SI = { | ||
const SI = { | ||
rad: { | ||
@@ -50,5 +50,5 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
@@ -55,0 +55,0 @@ }; |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var SI = { | ||
const SI = { | ||
VA: { | ||
@@ -50,5 +50,5 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
@@ -55,0 +55,0 @@ }; |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metric = { | ||
const metric = { | ||
nm2: { | ||
@@ -64,3 +64,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
in2: { | ||
@@ -102,6 +102,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -108,0 +108,0 @@ anchors: { |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var SI = { | ||
const SI = { | ||
c: { | ||
@@ -50,5 +50,5 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
@@ -55,0 +55,0 @@ }; |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var SI = { | ||
const SI = { | ||
A: { | ||
@@ -36,5 +36,5 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
@@ -41,0 +41,0 @@ }; |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var bits = { | ||
const bits = { | ||
b: { | ||
@@ -26,3 +26,3 @@ name: { | ||
}, | ||
to_anchor: 1024, | ||
to_anchor: 1e3, | ||
}, | ||
@@ -34,3 +34,3 @@ Mb: { | ||
}, | ||
to_anchor: 1048576, | ||
to_anchor: 1e6, | ||
}, | ||
@@ -42,3 +42,3 @@ Gb: { | ||
}, | ||
to_anchor: 1073741824, | ||
to_anchor: 1e9, | ||
}, | ||
@@ -50,6 +50,6 @@ Tb: { | ||
}, | ||
to_anchor: 1099511627776, | ||
to_anchor: 1e12, | ||
}, | ||
}; | ||
var bytes = { | ||
const bytes = { | ||
B: { | ||
@@ -67,3 +67,3 @@ name: { | ||
}, | ||
to_anchor: 1024, | ||
to_anchor: 1e3, | ||
}, | ||
@@ -75,3 +75,3 @@ MB: { | ||
}, | ||
to_anchor: 1048576, | ||
to_anchor: 1e6, | ||
}, | ||
@@ -83,3 +83,3 @@ GB: { | ||
}, | ||
to_anchor: 1073741824, | ||
to_anchor: 1e9, | ||
}, | ||
@@ -91,9 +91,9 @@ TB: { | ||
}, | ||
to_anchor: 1099511627776, | ||
to_anchor: 1e12, | ||
}, | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
bits: bits, | ||
bytes: bytes, | ||
bits, | ||
bytes, | ||
}, | ||
@@ -100,0 +100,0 @@ anchors: { |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metric = { | ||
const metric = { | ||
ea: { | ||
@@ -29,5 +29,5 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
metric, | ||
}, | ||
@@ -34,0 +34,0 @@ }; |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var SI = { | ||
const SI = { | ||
Wh: { | ||
@@ -78,5 +78,5 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
@@ -83,0 +83,0 @@ }; |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var SI = { | ||
const SI = { | ||
N: { | ||
@@ -36,5 +36,5 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
@@ -41,0 +41,0 @@ }; |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var SI = { | ||
const SI = { | ||
mHz: { | ||
@@ -78,5 +78,5 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
@@ -83,0 +83,0 @@ }; |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metric = { | ||
const metric = { | ||
lx: { | ||
@@ -22,3 +22,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
'ft-cd': { | ||
@@ -32,6 +32,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -38,0 +38,0 @@ anchors: { |
@@ -16,2 +16,3 @@ import { Measure } from '../convert'; | ||
import mass, { MassSystems, MassUnits } from './mass'; | ||
import massFlowRate, { MassFlowRateSystems, MassFlowRateUnits } from './massFlowRate'; | ||
import pace, { PaceSystems, PaceUnits } from './pace'; | ||
@@ -30,8 +31,8 @@ import partsPer, { PartsPerSystems, PartsPerUnits } from './partsPer'; | ||
import volumeFlowRate, { VolumeFlowRateSystems, VolumeFlowRateUnits } from './volumeFlowRate'; | ||
export declare type AllMeasuresSystems = AccelerationSystems | AngleSystems | ApparentPowerSystems | AreaSystems | ChargeSystems | CurrentSystems | DigitalSystems | EachSystems | EnergySystems | ForceSystems | FrequencySystems | IlluminanceSystems | LengthSystems | MassSystems | PaceSystems | PartsPerSystems | PiecesSystems | PowerSystems | PressureSystems | ReactiveEnergySystems | ReactivePowerSystems | SpeedSystems | TemperatureSystems | TimeSystems | VoltageSystems | VolumeSystems | VolumeFlowRateSystems; | ||
export declare type AllMeasuresUnits = AccelerationUnits | AngleUnits | ApparentPowerUnits | AreaUnits | ChargeUnits | CurrentUnits | DigitalUnits | EachUnits | EnergyUnits | ForceUnits | FrequencyUnits | IlluminanceUnits | LengthUnits | MassUnits | PaceUnits | PartsPerUnits | PiecesUnits | PowerUnits | PressureUnits | ReactiveEnergyUnits | ReactivePowerUnits | SpeedUnits | TemperatureUnits | TimeUnits | VoltageUnits | VolumeUnits | VolumeFlowRateUnits; | ||
export declare type AllMeasures = 'acceleration' | 'angle' | 'apparentPower' | 'area' | 'charge' | 'current' | 'digital' | 'each' | 'energy' | 'force' | 'frequency' | 'illuminance' | 'length' | 'mass' | 'pace' | 'partsPer' | 'pieces' | 'power' | 'pressure' | 'reactiveEnergy' | 'reactivePower' | 'speed' | 'temperature' | 'time' | 'voltage' | 'volume' | 'volumeFlowRate'; | ||
export declare type AllMeasuresSystems = AccelerationSystems | AngleSystems | ApparentPowerSystems | AreaSystems | ChargeSystems | CurrentSystems | DigitalSystems | EachSystems | EnergySystems | ForceSystems | FrequencySystems | IlluminanceSystems | LengthSystems | MassSystems | MassFlowRateSystems | PaceSystems | PartsPerSystems | PiecesSystems | PowerSystems | PressureSystems | ReactiveEnergySystems | ReactivePowerSystems | SpeedSystems | TemperatureSystems | TimeSystems | VoltageSystems | VolumeSystems | VolumeFlowRateSystems; | ||
export declare type AllMeasuresUnits = AccelerationUnits | AngleUnits | ApparentPowerUnits | AreaUnits | ChargeUnits | CurrentUnits | DigitalUnits | EachUnits | EnergyUnits | ForceUnits | FrequencyUnits | IlluminanceUnits | LengthUnits | MassUnits | MassFlowRateUnits | PaceUnits | PartsPerUnits | PiecesUnits | PowerUnits | PressureUnits | ReactiveEnergyUnits | ReactivePowerUnits | SpeedUnits | TemperatureUnits | TimeUnits | VoltageUnits | VolumeUnits | VolumeFlowRateUnits; | ||
export declare type AllMeasures = 'acceleration' | 'angle' | 'apparentPower' | 'area' | 'charge' | 'current' | 'digital' | 'each' | 'energy' | 'force' | 'frequency' | 'illuminance' | 'length' | 'mass' | 'massFlowRate' | 'pace' | 'partsPer' | 'pieces' | 'power' | 'pressure' | 'reactiveEnergy' | 'reactivePower' | 'speed' | 'temperature' | 'time' | 'voltage' | 'volume' | 'volumeFlowRate'; | ||
declare const allMeasures: Record<AllMeasures, Measure<AllMeasuresSystems, AllMeasuresUnits>>; | ||
export default allMeasures; | ||
export type { AccelerationSystems, AngleSystems, ApparentPowerSystems, AreaSystems, ChargeSystems, CurrentSystems, DigitalSystems, EachSystems, EnergySystems, ForceSystems, FrequencySystems, IlluminanceSystems, LengthSystems, MassSystems, PaceSystems, PartsPerSystems, PiecesSystems, PowerSystems, PressureSystems, ReactiveEnergySystems, ReactivePowerSystems, SpeedSystems, TemperatureSystems, TimeSystems, VoltageSystems, VolumeSystems, VolumeFlowRateSystems, AccelerationUnits, AngleUnits, ApparentPowerUnits, AreaUnits, ChargeUnits, CurrentUnits, DigitalUnits, EachUnits, EnergyUnits, ForceUnits, FrequencyUnits, IlluminanceUnits, LengthUnits, MassUnits, PaceUnits, PartsPerUnits, PiecesUnits, PowerUnits, PressureUnits, ReactiveEnergyUnits, ReactivePowerUnits, SpeedUnits, TemperatureUnits, TimeUnits, VoltageUnits, VolumeUnits, VolumeFlowRateUnits, }; | ||
export { acceleration, angle, apparentPower, area, charge, current, digital, each, energy, force, frequency, illuminance, length, mass, pace, partsPer, pieces, power, pressure, reactiveEnergy, reactivePower, speed, temperature, time, voltage, volume, volumeFlowRate, }; | ||
export { acceleration, angle, apparentPower, area, charge, current, digital, each, energy, force, frequency, illuminance, length, mass, massFlowRate, pace, partsPer, pieces, power, pressure, reactiveEnergy, reactivePower, speed, temperature, time, voltage, volume, volumeFlowRate, }; |
@@ -10,3 +10,3 @@ var __importDefault = (this && this.__importDefault) || function (mod) { | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports", "./acceleration", "./angle", "./apparentPower", "./area", "./charge", "./current", "./digital", "./each", "./energy", "./force", "./frequency", "./illuminance", "./length", "./mass", "./pace", "./partsPer", "./pieces", "./power", "./pressure", "./reactiveEnergy", "./reactivePower", "./speed", "./temperature", "./time", "./voltage", "./volume", "./volumeFlowRate"], factory); | ||
define(["require", "exports", "./acceleration", "./angle", "./apparentPower", "./area", "./charge", "./current", "./digital", "./each", "./energy", "./force", "./frequency", "./illuminance", "./length", "./mass", "./massFlowRate", "./pace", "./partsPer", "./pieces", "./power", "./pressure", "./reactiveEnergy", "./reactivePower", "./speed", "./temperature", "./time", "./voltage", "./volume", "./volumeFlowRate"], factory); | ||
} | ||
@@ -16,58 +16,60 @@ })(function (require, exports) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.volumeFlowRate = exports.volume = exports.voltage = exports.time = exports.temperature = exports.speed = exports.reactivePower = exports.reactiveEnergy = exports.pressure = exports.power = exports.pieces = exports.partsPer = exports.pace = exports.mass = exports.length = exports.illuminance = exports.frequency = exports.force = exports.energy = exports.each = exports.digital = exports.current = exports.charge = exports.area = exports.apparentPower = exports.angle = exports.acceleration = void 0; | ||
var acceleration_1 = __importDefault(require("./acceleration")); | ||
exports.volumeFlowRate = exports.volume = exports.voltage = exports.time = exports.temperature = exports.speed = exports.reactivePower = exports.reactiveEnergy = exports.pressure = exports.power = exports.pieces = exports.partsPer = exports.pace = exports.massFlowRate = exports.mass = exports.length = exports.illuminance = exports.frequency = exports.force = exports.energy = exports.each = exports.digital = exports.current = exports.charge = exports.area = exports.apparentPower = exports.angle = exports.acceleration = void 0; | ||
const acceleration_1 = __importDefault(require("./acceleration")); | ||
exports.acceleration = acceleration_1.default; | ||
var angle_1 = __importDefault(require("./angle")); | ||
const angle_1 = __importDefault(require("./angle")); | ||
exports.angle = angle_1.default; | ||
var apparentPower_1 = __importDefault(require("./apparentPower")); | ||
const apparentPower_1 = __importDefault(require("./apparentPower")); | ||
exports.apparentPower = apparentPower_1.default; | ||
var area_1 = __importDefault(require("./area")); | ||
const area_1 = __importDefault(require("./area")); | ||
exports.area = area_1.default; | ||
var charge_1 = __importDefault(require("./charge")); | ||
const charge_1 = __importDefault(require("./charge")); | ||
exports.charge = charge_1.default; | ||
var current_1 = __importDefault(require("./current")); | ||
const current_1 = __importDefault(require("./current")); | ||
exports.current = current_1.default; | ||
var digital_1 = __importDefault(require("./digital")); | ||
const digital_1 = __importDefault(require("./digital")); | ||
exports.digital = digital_1.default; | ||
var each_1 = __importDefault(require("./each")); | ||
const each_1 = __importDefault(require("./each")); | ||
exports.each = each_1.default; | ||
var energy_1 = __importDefault(require("./energy")); | ||
const energy_1 = __importDefault(require("./energy")); | ||
exports.energy = energy_1.default; | ||
var force_1 = __importDefault(require("./force")); | ||
const force_1 = __importDefault(require("./force")); | ||
exports.force = force_1.default; | ||
var frequency_1 = __importDefault(require("./frequency")); | ||
const frequency_1 = __importDefault(require("./frequency")); | ||
exports.frequency = frequency_1.default; | ||
var illuminance_1 = __importDefault(require("./illuminance")); | ||
const illuminance_1 = __importDefault(require("./illuminance")); | ||
exports.illuminance = illuminance_1.default; | ||
var length_1 = __importDefault(require("./length")); | ||
const length_1 = __importDefault(require("./length")); | ||
exports.length = length_1.default; | ||
var mass_1 = __importDefault(require("./mass")); | ||
const mass_1 = __importDefault(require("./mass")); | ||
exports.mass = mass_1.default; | ||
var pace_1 = __importDefault(require("./pace")); | ||
const massFlowRate_1 = __importDefault(require("./massFlowRate")); | ||
exports.massFlowRate = massFlowRate_1.default; | ||
const pace_1 = __importDefault(require("./pace")); | ||
exports.pace = pace_1.default; | ||
var partsPer_1 = __importDefault(require("./partsPer")); | ||
const partsPer_1 = __importDefault(require("./partsPer")); | ||
exports.partsPer = partsPer_1.default; | ||
var pieces_1 = __importDefault(require("./pieces")); | ||
const pieces_1 = __importDefault(require("./pieces")); | ||
exports.pieces = pieces_1.default; | ||
var power_1 = __importDefault(require("./power")); | ||
const power_1 = __importDefault(require("./power")); | ||
exports.power = power_1.default; | ||
var pressure_1 = __importDefault(require("./pressure")); | ||
const pressure_1 = __importDefault(require("./pressure")); | ||
exports.pressure = pressure_1.default; | ||
var reactiveEnergy_1 = __importDefault(require("./reactiveEnergy")); | ||
const reactiveEnergy_1 = __importDefault(require("./reactiveEnergy")); | ||
exports.reactiveEnergy = reactiveEnergy_1.default; | ||
var reactivePower_1 = __importDefault(require("./reactivePower")); | ||
const reactivePower_1 = __importDefault(require("./reactivePower")); | ||
exports.reactivePower = reactivePower_1.default; | ||
var speed_1 = __importDefault(require("./speed")); | ||
const speed_1 = __importDefault(require("./speed")); | ||
exports.speed = speed_1.default; | ||
var temperature_1 = __importDefault(require("./temperature")); | ||
const temperature_1 = __importDefault(require("./temperature")); | ||
exports.temperature = temperature_1.default; | ||
var time_1 = __importDefault(require("./time")); | ||
const time_1 = __importDefault(require("./time")); | ||
exports.time = time_1.default; | ||
var voltage_1 = __importDefault(require("./voltage")); | ||
const voltage_1 = __importDefault(require("./voltage")); | ||
exports.voltage = voltage_1.default; | ||
var volume_1 = __importDefault(require("./volume")); | ||
const volume_1 = __importDefault(require("./volume")); | ||
exports.volume = volume_1.default; | ||
var volumeFlowRate_1 = __importDefault(require("./volumeFlowRate")); | ||
const volumeFlowRate_1 = __importDefault(require("./volumeFlowRate")); | ||
exports.volumeFlowRate = volumeFlowRate_1.default; | ||
var allMeasures = { | ||
const allMeasures = { | ||
acceleration: acceleration_1.default, | ||
@@ -87,2 +89,3 @@ angle: angle_1.default, | ||
mass: mass_1.default, | ||
massFlowRate: massFlowRate_1.default, | ||
pace: pace_1.default, | ||
@@ -89,0 +92,0 @@ partsPer: partsPer_1.default, |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metric = { | ||
const metric = { | ||
nm: { | ||
@@ -57,3 +57,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
in: { | ||
@@ -109,6 +109,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -115,0 +115,0 @@ anchors: { |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metric = { | ||
const metric = { | ||
mcg: { | ||
@@ -50,3 +50,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
oz: { | ||
@@ -74,6 +74,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -80,0 +80,0 @@ anchors: { |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metric = { | ||
const metric = { | ||
'min/km': { | ||
@@ -29,3 +29,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
'min/mi': { | ||
@@ -46,6 +46,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -52,0 +52,0 @@ anchors: { |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var SI = { | ||
const SI = { | ||
ppm: { | ||
@@ -43,5 +43,5 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
@@ -48,0 +48,0 @@ }; |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var unit = { | ||
const unit = { | ||
pcs: { | ||
@@ -106,5 +106,5 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
unit: unit, | ||
unit, | ||
}, | ||
@@ -111,0 +111,0 @@ }; |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metric = { | ||
const metric = { | ||
W: { | ||
@@ -57,3 +57,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
'Btu/s': { | ||
@@ -81,6 +81,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -87,0 +87,0 @@ anchors: { |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metric = { | ||
const metric = { | ||
Pa: { | ||
@@ -57,3 +57,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
psi: { | ||
@@ -81,6 +81,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -87,0 +87,0 @@ anchors: { |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var SI = { | ||
const SI = { | ||
VARh: { | ||
@@ -50,5 +50,5 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
@@ -55,0 +55,0 @@ }; |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var SI = { | ||
const SI = { | ||
VAR: { | ||
@@ -50,5 +50,5 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
@@ -55,0 +55,0 @@ }; |
import { Measure } from './../index'; | ||
export declare type SpeedUnits = SpeedMetricUnits | SpeedImperialUnits; | ||
export declare type SpeedSystems = 'metric' | 'imperial'; | ||
export declare type SpeedMetricUnits = 'm/s' | 'km/h'; | ||
export declare type SpeedImperialUnits = 'mph' | 'knot' | 'ft/s' | 'ft/min'; | ||
export declare type SpeedMetricUnits = 'm/s' | 'km/h' | 'mm/h'; | ||
export declare type SpeedImperialUnits = 'mph' | 'knot' | 'ft/s' | 'ft/min' | 'in/h'; | ||
declare const measure: Measure<SpeedSystems, SpeedUnits>; | ||
export default measure; |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metric = { | ||
const metric = { | ||
'm/s': { | ||
@@ -28,4 +28,11 @@ name: { | ||
}, | ||
'mm/h': { | ||
name: { | ||
singular: 'Millimeter per hour', | ||
plural: 'Millimeters per hour', | ||
}, | ||
to_anchor: 0.000001, | ||
}, | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
mph: { | ||
@@ -59,7 +66,14 @@ name: { | ||
}, | ||
'in/h': { | ||
name: { | ||
singular: 'Inch per hour', | ||
plural: 'Inches per hour', | ||
}, | ||
to_anchor: 0.00001578, | ||
}, | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -66,0 +80,0 @@ anchors: { |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metric = { | ||
const metric = { | ||
C: { | ||
@@ -31,3 +31,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
F: { | ||
@@ -49,6 +49,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -55,0 +55,0 @@ anchors: { |
@@ -12,4 +12,4 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var daysInYear = 365.25; | ||
var SI = { | ||
const daysInYear = 365.25; | ||
const SI = { | ||
ns: { | ||
@@ -86,5 +86,5 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
@@ -91,0 +91,0 @@ }; |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var SI = { | ||
const SI = { | ||
V: { | ||
@@ -36,5 +36,5 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
SI: SI, | ||
SI, | ||
}, | ||
@@ -41,0 +41,0 @@ }; |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metric = { | ||
const metric = { | ||
mm3: { | ||
@@ -135,3 +135,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
tsp: { | ||
@@ -208,6 +208,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -214,0 +214,0 @@ anchors: { |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var metric = { | ||
const metric = { | ||
'mm3/s': { | ||
@@ -120,3 +120,3 @@ name: { | ||
}; | ||
var imperial = { | ||
const imperial = { | ||
'tsp/s': { | ||
@@ -277,6 +277,6 @@ name: { | ||
}; | ||
var measure = { | ||
const measure = { | ||
systems: { | ||
metric: metric, | ||
imperial: imperial, | ||
metric, | ||
imperial, | ||
}, | ||
@@ -283,0 +283,0 @@ anchors: { |
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -38,5 +42,5 @@ if (k2 === undefined) k2 = k; | ||
exports.Converter = exports.allMeasures = void 0; | ||
var convert_1 = __importStar(require("./convert")); | ||
const convert_1 = __importStar(require("./convert")); | ||
Object.defineProperty(exports, "Converter", { enumerable: true, get: function () { return convert_1.Converter; } }); | ||
var definitions_1 = __importDefault(require("./definitions")); | ||
const definitions_1 = __importDefault(require("./definitions")); | ||
exports.allMeasures = definitions_1.default; | ||
@@ -43,0 +47,0 @@ exports.default = convert_1.default; |
{ | ||
"name": "convert-units", | ||
"version": "3.0.0-beta.4", | ||
"version": "3.0.0-beta.5", | ||
"description": "Convert between quantities in different units", | ||
@@ -11,15 +11,15 @@ "main": "lib/cjs/index.js", | ||
"devDependencies": { | ||
"@types/jest": "^26.0.23", | ||
"@typescript-eslint/eslint-plugin": "^4.24.0", | ||
"@typescript-eslint/parser": "^4.23.0", | ||
"eslint": "^7.19.0", | ||
"eslint-config-prettier": "^4.3.0", | ||
"eslint-plugin-import": "^2.23.4", | ||
"eslint-plugin-jest": "^24.3.6", | ||
"eslint-plugin-prettier": "^3.4.0", | ||
"jest": "^27.3.1", | ||
"prettier": "2.2.1", | ||
"prettier-plugin-organize-imports": "^2.1.0", | ||
"ts-jest": "^27.0.7", | ||
"typescript": "^4.2.4" | ||
"@types/jest": "^28.1.6", | ||
"@typescript-eslint/eslint-plugin": "^5.33.0", | ||
"@typescript-eslint/parser": "^5.33.0", | ||
"eslint": "^8.21.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-jest": "^26.8.2", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"jest": "^28.1.3", | ||
"prettier": "^2.7.1", | ||
"prettier-plugin-organize-imports": "^3.0.3", | ||
"ts-jest": "^28.0.7", | ||
"typescript": "^4.7.4" | ||
}, | ||
@@ -26,0 +26,0 @@ "scripts": { |
@@ -1030,2 +1030,4 @@ convert-units | ||
* ft/s | ||
* in/h | ||
* mm/h | ||
</details> | ||
@@ -1032,0 +1034,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
274035
189
8700
1222