489 lines
17 KiB
JavaScript
489 lines
17 KiB
JavaScript
import { __decorate, __param, __assign } from 'tslib';
|
|
import { Pipe, EventEmitter, ChangeDetectorRef, NgZone, InjectionToken, Optional, Inject, NgModule } from '@angular/core';
|
|
import * as moment from 'moment';
|
|
import { isMoment, duration, relativeTimeThreshold, unix, utc, parseZone, isDate, locale } from 'moment';
|
|
|
|
/* ngx-moment (c) 2015, 2016 Uri Shaked / MIT Licence */
|
|
var momentConstructor = moment;
|
|
var AddPipe = /** @class */ (function () {
|
|
function AddPipe() {
|
|
}
|
|
AddPipe.prototype.transform = function (value, amount, unit) {
|
|
if (typeof amount === 'undefined' ||
|
|
(typeof amount === 'number' && typeof unit === 'undefined')) {
|
|
throw new Error('AddPipe: missing required arguments');
|
|
}
|
|
return momentConstructor(value).add(amount, unit);
|
|
};
|
|
AddPipe = __decorate([
|
|
Pipe({ name: 'amAdd' })
|
|
], AddPipe);
|
|
return AddPipe;
|
|
}());
|
|
|
|
/* ngx-moment (c) 2015, 2016 Uri Shaked / MIT Licence */
|
|
var momentConstructor$1 = moment;
|
|
var CalendarPipe = /** @class */ (function () {
|
|
function CalendarPipe(cdRef, ngZone) {
|
|
var _this = this;
|
|
this.cdRef = cdRef;
|
|
this.ngZone = ngZone;
|
|
// using a single static timer for all instances of this pipe for performance reasons
|
|
CalendarPipe_1.initTimer(ngZone);
|
|
CalendarPipe_1.refs++;
|
|
// values such as Today will need to be replaced with Yesterday after midnight,
|
|
// so make sure we subscribe to an EventEmitter that we set up to emit at midnight
|
|
this.midnightSub = CalendarPipe_1.midnight.subscribe(function () {
|
|
_this.ngZone.run(function () { return _this.cdRef.markForCheck(); });
|
|
});
|
|
}
|
|
CalendarPipe_1 = CalendarPipe;
|
|
CalendarPipe.prototype.transform = function (value) {
|
|
var args = [];
|
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
args[_i - 1] = arguments[_i];
|
|
}
|
|
var formats = null;
|
|
var referenceTime = null;
|
|
for (var i = 0, len = args.length; i < len; i++) {
|
|
if (args[i] !== null) {
|
|
if (typeof args[i] === 'object' && !isMoment(args[i])) {
|
|
formats = args[i];
|
|
}
|
|
else {
|
|
referenceTime = momentConstructor$1(args[i]);
|
|
}
|
|
}
|
|
}
|
|
return momentConstructor$1(value).calendar(referenceTime, formats);
|
|
};
|
|
CalendarPipe.prototype.ngOnDestroy = function () {
|
|
if (CalendarPipe_1.refs > 0) {
|
|
CalendarPipe_1.refs--;
|
|
}
|
|
if (CalendarPipe_1.refs === 0) {
|
|
CalendarPipe_1.removeTimer();
|
|
}
|
|
this.midnightSub.unsubscribe();
|
|
};
|
|
CalendarPipe.initTimer = function (ngZone) {
|
|
// initialize the timer
|
|
if (!CalendarPipe_1.midnight) {
|
|
CalendarPipe_1.midnight = new EventEmitter();
|
|
if (typeof window !== 'undefined') {
|
|
var timeToUpdate_1 = CalendarPipe_1._getMillisecondsUntilUpdate();
|
|
CalendarPipe_1.timer = ngZone.runOutsideAngular(function () {
|
|
return window.setTimeout(function () {
|
|
// emit the current date
|
|
CalendarPipe_1.midnight.emit(new Date());
|
|
// refresh the timer
|
|
CalendarPipe_1.removeTimer();
|
|
CalendarPipe_1.initTimer(ngZone);
|
|
}, timeToUpdate_1);
|
|
});
|
|
}
|
|
}
|
|
};
|
|
CalendarPipe.removeTimer = function () {
|
|
if (CalendarPipe_1.timer) {
|
|
window.clearTimeout(CalendarPipe_1.timer);
|
|
CalendarPipe_1.timer = null;
|
|
CalendarPipe_1.midnight = null;
|
|
}
|
|
};
|
|
CalendarPipe._getMillisecondsUntilUpdate = function () {
|
|
var now = momentConstructor$1();
|
|
var tomorrow = momentConstructor$1().startOf('day').add(1, 'days');
|
|
var timeToMidnight = tomorrow.valueOf() - now.valueOf();
|
|
return timeToMidnight + 1000; // 1 second after midnight
|
|
};
|
|
var CalendarPipe_1;
|
|
/**
|
|
* Internal reference counter, so we can clean up when no instances are in use
|
|
*/
|
|
CalendarPipe.refs = 0;
|
|
CalendarPipe.timer = null;
|
|
CalendarPipe.midnight = null;
|
|
CalendarPipe.ctorParameters = function () { return [
|
|
{ type: ChangeDetectorRef },
|
|
{ type: NgZone }
|
|
]; };
|
|
CalendarPipe = CalendarPipe_1 = __decorate([
|
|
Pipe({ name: 'amCalendar', pure: false })
|
|
], CalendarPipe);
|
|
return CalendarPipe;
|
|
}());
|
|
|
|
/* ngx-moment (c) 2015, 2016 Uri Shaked / MIT Licence */
|
|
var momentConstructor$2 = moment;
|
|
var DateFormatPipe = /** @class */ (function () {
|
|
function DateFormatPipe() {
|
|
}
|
|
DateFormatPipe.prototype.transform = function (value) {
|
|
var args = [];
|
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
args[_i - 1] = arguments[_i];
|
|
}
|
|
if (!value) {
|
|
return '';
|
|
}
|
|
return momentConstructor$2(value).format(args[0]);
|
|
};
|
|
DateFormatPipe = __decorate([
|
|
Pipe({ name: 'amDateFormat' })
|
|
], DateFormatPipe);
|
|
return DateFormatPipe;
|
|
}());
|
|
|
|
/* ngx-moment (c) 2015, 2016 Uri Shaked / MIT Licence */
|
|
var momentConstructor$3 = moment;
|
|
var DifferencePipe = /** @class */ (function () {
|
|
function DifferencePipe() {
|
|
}
|
|
DifferencePipe.prototype.transform = function (value, otherValue, unit, precision) {
|
|
var date = momentConstructor$3(value);
|
|
var date2 = otherValue !== null ? momentConstructor$3(otherValue) : momentConstructor$3();
|
|
return date.diff(date2, unit, precision);
|
|
};
|
|
DifferencePipe = __decorate([
|
|
Pipe({ name: 'amDifference' })
|
|
], DifferencePipe);
|
|
return DifferencePipe;
|
|
}());
|
|
|
|
var NGX_MOMENT_OPTIONS = new InjectionToken('NGX_MOMENT_OPTIONS');
|
|
|
|
var DurationPipe = /** @class */ (function () {
|
|
function DurationPipe(momentOptions) {
|
|
this.allowedUnits = ['ss', 's', 'm', 'h', 'd', 'M'];
|
|
this._applyOptions(momentOptions);
|
|
}
|
|
DurationPipe.prototype.transform = function (value) {
|
|
var args = [];
|
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
args[_i - 1] = arguments[_i];
|
|
}
|
|
if (typeof args === 'undefined' || args.length !== 1) {
|
|
throw new Error('DurationPipe: missing required time unit argument');
|
|
}
|
|
return duration(value, args[0]).humanize();
|
|
};
|
|
DurationPipe.prototype._applyOptions = function (momentOptions) {
|
|
var _this = this;
|
|
if (!momentOptions) {
|
|
return;
|
|
}
|
|
if (!!momentOptions.relativeTimeThresholdOptions) {
|
|
var units = Object.keys(momentOptions.relativeTimeThresholdOptions);
|
|
var filteredUnits = units.filter(function (unit) { return _this.allowedUnits.indexOf(unit) !== -1; });
|
|
filteredUnits.forEach(function (unit) {
|
|
relativeTimeThreshold(unit, momentOptions.relativeTimeThresholdOptions[unit]);
|
|
});
|
|
}
|
|
};
|
|
DurationPipe.ctorParameters = function () { return [
|
|
{ type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [NGX_MOMENT_OPTIONS,] }] }
|
|
]; };
|
|
DurationPipe = __decorate([
|
|
Pipe({ name: 'amDuration' }),
|
|
__param(0, Optional()), __param(0, Inject(NGX_MOMENT_OPTIONS))
|
|
], DurationPipe);
|
|
return DurationPipe;
|
|
}());
|
|
|
|
/* ngx-moment (c) 2015, 2016 Uri Shaked / MIT Licence */
|
|
var FromUnixPipe = /** @class */ (function () {
|
|
function FromUnixPipe() {
|
|
}
|
|
FromUnixPipe.prototype.transform = function (value) {
|
|
var args = [];
|
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
args[_i - 1] = arguments[_i];
|
|
}
|
|
return typeof value === 'string' ? unix(parseInt(value, 10)) : unix(value);
|
|
};
|
|
FromUnixPipe = __decorate([
|
|
Pipe({ name: 'amFromUnix' })
|
|
], FromUnixPipe);
|
|
return FromUnixPipe;
|
|
}());
|
|
|
|
var momentConstructor$4 = moment;
|
|
var ParsePipe = /** @class */ (function () {
|
|
function ParsePipe() {
|
|
}
|
|
ParsePipe.prototype.transform = function (value, formats) {
|
|
return momentConstructor$4(value, formats);
|
|
};
|
|
ParsePipe = __decorate([
|
|
Pipe({ name: 'amParse' })
|
|
], ParsePipe);
|
|
return ParsePipe;
|
|
}());
|
|
|
|
/* ngx-moment (c) 2015, 2016 Uri Shaked / MIT Licence */
|
|
var FromUtcPipe = /** @class */ (function () {
|
|
function FromUtcPipe() {
|
|
}
|
|
FromUtcPipe.prototype.transform = function (value, formats) {
|
|
var args = [];
|
|
for (var _i = 2; _i < arguments.length; _i++) {
|
|
args[_i - 2] = arguments[_i];
|
|
}
|
|
return formats ? utc(value, formats) : utc(value);
|
|
};
|
|
FromUtcPipe = __decorate([
|
|
Pipe({ name: 'amFromUtc' })
|
|
], FromUtcPipe);
|
|
return FromUtcPipe;
|
|
}());
|
|
|
|
var momentConstructor$5 = moment;
|
|
var IsAfterPipe = /** @class */ (function () {
|
|
function IsAfterPipe() {
|
|
}
|
|
IsAfterPipe.prototype.transform = function (value, otherValue, unit) {
|
|
return momentConstructor$5(value).isAfter(momentConstructor$5(otherValue), unit);
|
|
};
|
|
IsAfterPipe = __decorate([
|
|
Pipe({
|
|
name: 'amIsAfter',
|
|
})
|
|
], IsAfterPipe);
|
|
return IsAfterPipe;
|
|
}());
|
|
|
|
var momentConstructor$6 = moment;
|
|
var IsBeforePipe = /** @class */ (function () {
|
|
function IsBeforePipe() {
|
|
}
|
|
IsBeforePipe.prototype.transform = function (value, otherValue, unit) {
|
|
return momentConstructor$6(value).isBefore(momentConstructor$6(otherValue), unit);
|
|
};
|
|
IsBeforePipe = __decorate([
|
|
Pipe({
|
|
name: 'amIsBefore',
|
|
})
|
|
], IsBeforePipe);
|
|
return IsBeforePipe;
|
|
}());
|
|
|
|
var momentConstructor$7 = moment;
|
|
var LocalTimePipe = /** @class */ (function () {
|
|
function LocalTimePipe() {
|
|
}
|
|
LocalTimePipe.prototype.transform = function (value) {
|
|
return momentConstructor$7(value).local();
|
|
};
|
|
LocalTimePipe = __decorate([
|
|
Pipe({ name: 'amLocal' })
|
|
], LocalTimePipe);
|
|
return LocalTimePipe;
|
|
}());
|
|
|
|
// See https://github.com/ng-packagr/ng-packagr/issues/217 for why this is needed:
|
|
var momentConstructor$8 = moment;
|
|
var LocalePipe = /** @class */ (function () {
|
|
function LocalePipe() {
|
|
}
|
|
LocalePipe.prototype.transform = function (value, locale) {
|
|
return momentConstructor$8(value).locale(locale);
|
|
};
|
|
LocalePipe = __decorate([
|
|
Pipe({ name: 'amLocale' })
|
|
], LocalePipe);
|
|
return LocalePipe;
|
|
}());
|
|
|
|
var ParseZonePipe = /** @class */ (function () {
|
|
function ParseZonePipe() {
|
|
}
|
|
ParseZonePipe.prototype.transform = function (value) {
|
|
return parseZone(value);
|
|
};
|
|
ParseZonePipe = __decorate([
|
|
Pipe({ name: 'amParseZone' })
|
|
], ParseZonePipe);
|
|
return ParseZonePipe;
|
|
}());
|
|
|
|
/* ngx-moment (c) 2015, 2016 Uri Shaked / MIT Licence */
|
|
var momentConstructor$9 = moment;
|
|
var SubtractPipe = /** @class */ (function () {
|
|
function SubtractPipe() {
|
|
}
|
|
SubtractPipe.prototype.transform = function (value, amount, unit) {
|
|
if (typeof amount === 'undefined' ||
|
|
(typeof amount === 'number' && typeof unit === 'undefined')) {
|
|
throw new Error('SubtractPipe: missing required arguments');
|
|
}
|
|
return momentConstructor$9(value).subtract(amount, unit);
|
|
};
|
|
SubtractPipe = __decorate([
|
|
Pipe({ name: 'amSubtract' })
|
|
], SubtractPipe);
|
|
return SubtractPipe;
|
|
}());
|
|
|
|
/* ngx-moment (c) 2015, 2016 Uri Shaked / MIT Licence */
|
|
var momentConstructor$a = moment;
|
|
var TimeAgoPipe = /** @class */ (function () {
|
|
function TimeAgoPipe(cdRef, ngZone) {
|
|
this.cdRef = cdRef;
|
|
this.ngZone = ngZone;
|
|
}
|
|
TimeAgoPipe.prototype.format = function (m) {
|
|
return m.from(momentConstructor$a(), this.lastOmitSuffix);
|
|
};
|
|
TimeAgoPipe.prototype.transform = function (value, omitSuffix, formatFn) {
|
|
if (this.hasChanged(value, omitSuffix)) {
|
|
this.lastTime = this.getTime(value);
|
|
this.lastValue = value;
|
|
this.lastOmitSuffix = omitSuffix;
|
|
this.lastLocale = this.getLocale(value);
|
|
this.formatFn = formatFn || this.format.bind(this);
|
|
this.removeTimer();
|
|
this.createTimer();
|
|
this.lastText = this.formatFn(momentConstructor$a(value));
|
|
}
|
|
else {
|
|
this.createTimer();
|
|
}
|
|
return this.lastText;
|
|
};
|
|
TimeAgoPipe.prototype.ngOnDestroy = function () {
|
|
this.removeTimer();
|
|
};
|
|
TimeAgoPipe.prototype.createTimer = function () {
|
|
var _this = this;
|
|
if (this.currentTimer) {
|
|
return;
|
|
}
|
|
var momentInstance = momentConstructor$a(this.lastValue);
|
|
var timeToUpdate = this.getSecondsUntilUpdate(momentInstance) * 1000;
|
|
this.currentTimer = this.ngZone.runOutsideAngular(function () {
|
|
if (typeof window !== 'undefined') {
|
|
return window.setTimeout(function () {
|
|
_this.lastText = _this.formatFn(momentConstructor$a(_this.lastValue));
|
|
_this.currentTimer = null;
|
|
_this.ngZone.run(function () { return _this.cdRef.markForCheck(); });
|
|
}, timeToUpdate);
|
|
}
|
|
else {
|
|
return null;
|
|
}
|
|
});
|
|
};
|
|
TimeAgoPipe.prototype.removeTimer = function () {
|
|
if (this.currentTimer) {
|
|
window.clearTimeout(this.currentTimer);
|
|
this.currentTimer = null;
|
|
}
|
|
};
|
|
TimeAgoPipe.prototype.getSecondsUntilUpdate = function (momentInstance) {
|
|
var howOld = Math.abs(momentConstructor$a().diff(momentInstance, 'minute'));
|
|
if (howOld < 1) {
|
|
return 1;
|
|
}
|
|
else if (howOld < 60) {
|
|
return 30;
|
|
}
|
|
else if (howOld < 180) {
|
|
return 300;
|
|
}
|
|
else {
|
|
return 3600;
|
|
}
|
|
};
|
|
TimeAgoPipe.prototype.hasChanged = function (value, omitSuffix) {
|
|
return (this.getTime(value) !== this.lastTime ||
|
|
this.getLocale(value) !== this.lastLocale ||
|
|
omitSuffix !== this.lastOmitSuffix);
|
|
};
|
|
TimeAgoPipe.prototype.getTime = function (value) {
|
|
if (isDate(value)) {
|
|
return value.getTime();
|
|
}
|
|
else if (isMoment(value)) {
|
|
return value.valueOf();
|
|
}
|
|
else {
|
|
return momentConstructor$a(value).valueOf();
|
|
}
|
|
};
|
|
TimeAgoPipe.prototype.getLocale = function (value) {
|
|
return isMoment(value) ? value.locale() : locale();
|
|
};
|
|
TimeAgoPipe.ctorParameters = function () { return [
|
|
{ type: ChangeDetectorRef },
|
|
{ type: NgZone }
|
|
]; };
|
|
TimeAgoPipe = __decorate([
|
|
Pipe({ name: 'amTimeAgo', pure: false })
|
|
], TimeAgoPipe);
|
|
return TimeAgoPipe;
|
|
}());
|
|
|
|
var momentConstructor$b = moment;
|
|
var UtcPipe = /** @class */ (function () {
|
|
function UtcPipe() {
|
|
}
|
|
UtcPipe.prototype.transform = function (value) {
|
|
return momentConstructor$b(value).utc();
|
|
};
|
|
UtcPipe = __decorate([
|
|
Pipe({ name: 'amUtc' })
|
|
], UtcPipe);
|
|
return UtcPipe;
|
|
}());
|
|
|
|
var ANGULAR_MOMENT_PIPES = [
|
|
AddPipe,
|
|
CalendarPipe,
|
|
DateFormatPipe,
|
|
DifferencePipe,
|
|
DurationPipe,
|
|
FromUnixPipe,
|
|
ParsePipe,
|
|
SubtractPipe,
|
|
TimeAgoPipe,
|
|
UtcPipe,
|
|
FromUtcPipe,
|
|
LocalTimePipe,
|
|
LocalePipe,
|
|
ParseZonePipe,
|
|
IsBeforePipe,
|
|
IsAfterPipe,
|
|
];
|
|
var MomentModule = /** @class */ (function () {
|
|
function MomentModule() {
|
|
}
|
|
MomentModule_1 = MomentModule;
|
|
MomentModule.forRoot = function (options) {
|
|
return {
|
|
ngModule: MomentModule_1,
|
|
providers: [
|
|
{
|
|
provide: NGX_MOMENT_OPTIONS,
|
|
useValue: __assign({}, options),
|
|
},
|
|
],
|
|
};
|
|
};
|
|
var MomentModule_1;
|
|
MomentModule = MomentModule_1 = __decorate([
|
|
NgModule({
|
|
declarations: ANGULAR_MOMENT_PIPES,
|
|
exports: ANGULAR_MOMENT_PIPES,
|
|
})
|
|
], MomentModule);
|
|
return MomentModule;
|
|
}());
|
|
|
|
/**
|
|
* Generated bundle index. Do not edit.
|
|
*/
|
|
|
|
export { AddPipe, CalendarPipe, DateFormatPipe, DifferencePipe, DurationPipe, FromUnixPipe, FromUtcPipe, IsAfterPipe, IsBeforePipe, LocalTimePipe, LocalePipe, MomentModule, NGX_MOMENT_OPTIONS, ParsePipe, ParseZonePipe, SubtractPipe, TimeAgoPipe, UtcPipe };
|
|
//# sourceMappingURL=ngx-moment.js.map
|