73 lines
No EOL
3 KiB
JavaScript
73 lines
No EOL
3 KiB
JavaScript
"use strict";
|
|
var __extends = (this && this.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
var AbstractTextFormatter = /** @class */ (function () {
|
|
function AbstractTextFormatter(regularExpression) {
|
|
this._regularExpression = regularExpression;
|
|
}
|
|
AbstractTextFormatter.prototype.format = function (lang, input) {
|
|
var matches;
|
|
var result = input;
|
|
while ((matches = this._regularExpression.exec(input)) != null) {
|
|
result = result.replace(matches[0], this.internalFormat(lang, matches));
|
|
}
|
|
;
|
|
return result;
|
|
};
|
|
return AbstractTextFormatter;
|
|
}());
|
|
var DateFormatter = /** @class */ (function (_super) {
|
|
__extends(DateFormatter, _super);
|
|
function DateFormatter() {
|
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
}
|
|
DateFormatter.prototype.internalFormat = function (lang, matches) {
|
|
var date = new Date(Date.parse(matches[1]));
|
|
var format = matches[2] != undefined ? matches[2].toLowerCase() : "compact";
|
|
if (format != "compact") {
|
|
return date.toLocaleDateString(lang, { day: "numeric", weekday: format, month: format, year: "numeric" });
|
|
}
|
|
else {
|
|
return date.toLocaleDateString();
|
|
}
|
|
};
|
|
return DateFormatter;
|
|
}(AbstractTextFormatter));
|
|
var TimeFormatter = /** @class */ (function (_super) {
|
|
__extends(TimeFormatter, _super);
|
|
function TimeFormatter() {
|
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
}
|
|
TimeFormatter.prototype.internalFormat = function (lang, matches) {
|
|
var date = new Date(Date.parse(matches[1]));
|
|
return date.toLocaleTimeString(lang, { hour: 'numeric', minute: '2-digit' });
|
|
};
|
|
return TimeFormatter;
|
|
}(AbstractTextFormatter));
|
|
function formatText(lang, text) {
|
|
var formatters = [
|
|
new DateFormatter(/\{{2}DATE\((\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:Z|(?:(?:-|\+)\d{2}:\d{2})))(?:, ?(COMPACT|LONG|SHORT))?\)\}{2}/g),
|
|
new TimeFormatter(/\{{2}TIME\((\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:Z|(?:(?:-|\+)\d{2}:\d{2})))\)\}{2}/g)
|
|
];
|
|
var result = text;
|
|
for (var i = 0; i < formatters.length; i++) {
|
|
result = formatters[i].format(lang, result);
|
|
}
|
|
return result;
|
|
}
|
|
exports.formatText = formatText;
|
|
//# sourceMappingURL=text-formatters.js.map
|