UNPKG

@phensley/cldr-core

Version:
91 lines 3.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var GeneralInternalsImpl = /** @class */ (function () { function GeneralInternalsImpl(internals) { this.internals = internals; var schema = internals.schema; this.layout = schema.Layout; this.names = schema.Names; this.listPatterns = schema.ListPatterns; } GeneralInternalsImpl.prototype.characterOrder = function (bundle) { return this.layout.characterOrder.get(bundle); }; GeneralInternalsImpl.prototype.lineOrder = function (bundle) { return this.layout.lineOrder.get(bundle); }; GeneralInternalsImpl.prototype.formatList = function (bundle, items, type) { var arrow = this.selectListPattern(type); var pattern = arrow.mapping(bundle); var len = items.length; if (len < 2) { return len === 1 ? items[0] : ''; } var wrapper = this.internals.wrapper; if (len === 2) { return wrapper.format(pattern.two, items); } // We have at least 3 items. Format from tail to head. var res = wrapper.format(pattern.end, [items[len - 2], items[len - 1]]); len -= 2; while (len-- > 1) { res = wrapper.format(pattern.middle, [items[len], res]); } return wrapper.format(pattern.start, [items[0], res]); }; GeneralInternalsImpl.prototype.formatListToParts = function (bundle, items, type) { var parts = items.map(function (i) { return ([{ type: 'item', value: i }]); }); return this.formatListToPartsImpl(bundle, parts, type); }; GeneralInternalsImpl.prototype.getScriptDisplayName = function (bundle, code) { var id = code; return this.names.scripts.displayName.get(bundle, id); }; GeneralInternalsImpl.prototype.getRegionDisplayName = function (bundle, code, alt) { if (alt === void 0) { alt = 'none'; } var id = code; var name = this.names.regions.displayName.get(bundle, alt, id); // Fall back if preferred form is not available return name === '' ? this.names.regions.displayName.get(bundle, 'none', id) : name; }; GeneralInternalsImpl.prototype.formatListToPartsImpl = function (bundle, items, type) { var arrow = this.selectListPattern(type); var pattern = arrow.mapping(bundle); var len = items.length; if (len < 2) { return len === 1 ? items[0] : []; } var wrapper = this.internals.wrapper; if (len === 2) { return wrapper.formatParts(pattern.two, [items[0], items[1]]); } // We have at least 3 items. Format from tail to head. var res = wrapper.formatParts(pattern.end, [items[len - 2], items[len - 1]]); len -= 2; while (len-- > 1) { res = wrapper.formatParts(pattern.middle, [items[len], res]); } return wrapper.formatParts(pattern.start, [items[0], res]); }; GeneralInternalsImpl.prototype.selectListPattern = function (type) { var p = this.listPatterns; switch (type) { case 'unit-long': return p.unitLong; case 'unit-narrow': return p.unitNarrow; case 'unit-short': return p.unitShort; case 'or': return p.or; case 'and-short': return p.andShort; case 'and': default: return p.and; } }; return GeneralInternalsImpl; }()); exports.GeneralInternalsImpl = GeneralInternalsImpl; //# sourceMappingURL=internal.js.map