@phensley/cldr-core
Version:
Core library for @phensley/cldr
37 lines • 1.52 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var types_1 = require("../../types");
var UnitsInternalImpl = /** @class */ (function () {
function UnitsInternalImpl(internals) {
this.internals = internals;
var schema = internals.schema;
this.unitsSchema = schema.Units;
this.numbersSchema = schema.Numbers;
}
UnitsInternalImpl.prototype.getDisplayName = function (bundle, name, length) {
return this.getUnitInfo(length).displayName.get(bundle, name);
};
UnitsInternalImpl.prototype.format = function (bundle, renderer, q, options, params) {
var n = types_1.coerceDecimal(q.value);
var _a = this.internals.numbers.formatDecimal(bundle, renderer, n, options, params), num = _a[0], plural = _a[1];
if (q.unit === undefined) {
return num;
}
var info = this.getUnitInfo(options.length || '');
var pattern = info.unitPattern.get(bundle, plural, q.unit);
return renderer.wrap(this.internals.wrapper, pattern, num);
};
UnitsInternalImpl.prototype.getUnitInfo = function (length) {
switch (length) {
case 'narrow':
return this.unitsSchema.narrow;
case 'short':
return this.unitsSchema.short;
default:
return this.unitsSchema.long;
}
};
return UnitsInternalImpl;
}());
exports.UnitsInternalImpl = UnitsInternalImpl;
//# sourceMappingURL=internal.js.map
;