conversion
Version:
a javascript library for unit conversions and organizations
14 lines (11 loc) • 370 B
JavaScript
const getUnit = (units) => (symbol) => {
const unit = units[symbol];
if (typeof unit === 'undefined') {
const possibleUnits = Object.keys(units).join(',');
const errorMessage = `${symbol}' is not a unit`;
const hint = `possible units: [${possibleUnits}]`;
throw new Error(`'${errorMessage}, ${hint}`);
}
return unit;
};
export default getUnit;