@phensley/cldr-core
Version:
Core library for @phensley/cldr
50 lines • 1.82 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var cache_1 = require("../../utils/cache");
var wrapper_1 = require("../../parsing/patterns/wrapper");
var WrapperInternalsImpl = /** @class */ (function () {
function WrapperInternalsImpl(cacheSize) {
if (cacheSize === void 0) { cacheSize = 50; }
this.wrapperPatternCache = new cache_1.Cache(wrapper_1.parseWrapperPattern, cacheSize);
}
WrapperInternalsImpl.prototype.format = function (format, args) {
var pattern = this.wrapperPatternCache.get(format);
var res = '';
for (var _i = 0, pattern_1 = pattern; _i < pattern_1.length; _i++) {
var node = pattern_1[_i];
if (typeof node === 'string') {
res += node;
}
else {
var s = args[node];
if (s) {
res += s;
}
}
}
return res;
};
WrapperInternalsImpl.prototype.formatParts = function (format, args) {
var pattern = this.wrapperPatternCache.get(format);
var res = [];
for (var _i = 0, pattern_2 = pattern; _i < pattern_2.length; _i++) {
var node = pattern_2[_i];
if (typeof node === 'string') {
res.push({ type: 'literal', value: node });
}
else {
var arg = args[node];
if (arg !== undefined) {
res = res.concat(arg);
}
}
}
return res;
};
WrapperInternalsImpl.prototype.parseWrapper = function (raw) {
return this.wrapperPatternCache.get(raw);
};
return WrapperInternalsImpl;
}());
exports.WrapperInternalsImpl = WrapperInternalsImpl;
//# sourceMappingURL=internal.js.map
;