UNPKG

@js-sugar/angular

Version:

JS-Sugar core package (Angular)

82 lines (77 loc) 3.39 kB
import * as i0 from '@angular/core'; import { InjectionToken, Pipe, Optional, Inject, NgModule } from '@angular/core'; import { DateTime, Calendars } from '@js-sugar/date'; import { format } from '@js-sugar/date/plugins/format'; import { parseIso } from '@js-sugar/date/plugins/parse-iso'; const JSS_DATE_PIPE_OPTIONS = new InjectionToken('DATE_PIPE_DEFAULT_TIMEZONE'); class JssDatePipe { constructor(options) { this.options = options; } transform(value, formatStr) { var _a, _b; if (typeof formatStr === 'string') { switch (formatStr) { case 'short': formatStr = 'M/d/YY, HH:mm'; break; case 'shortDate': formatStr = 'M/d/YY'; break; } } else { formatStr = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.format) !== null && _b !== void 0 ? _b : 'M/d/YY, HH:mm'; } let date; if (value == null) { return ''; } else if (typeof value === 'string') { date = parseIso(value); } else if (value instanceof DateTime) { date = value; } else { throw Error('Invalid date'); } if (Calendars.default) { date = date.to(Calendars.default); } return format(date, formatStr); } } JssDatePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.1", ngImport: i0, type: JssDatePipe, deps: [{ token: JSS_DATE_PIPE_OPTIONS, optional: true }], target: i0.ɵɵFactoryTarget.Pipe }); JssDatePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "14.1.1", ngImport: i0, type: JssDatePipe, name: "jssDate" }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.1", ngImport: i0, type: JssDatePipe, decorators: [{ type: Pipe, args: [{ name: 'jssDate' }] }], ctorParameters: function () { return [{ type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [JSS_DATE_PIPE_OPTIONS] }] }]; } }); class JssDateModule { } JssDateModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.1", ngImport: i0, type: JssDateModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); JssDateModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.1.1", ngImport: i0, type: JssDateModule, declarations: [JssDatePipe], exports: [JssDatePipe] }); JssDateModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.1.1", ngImport: i0, type: JssDateModule }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.1", ngImport: i0, type: JssDateModule, decorators: [{ type: NgModule, args: [{ declarations: [ JssDatePipe ], exports: [ JssDatePipe ] }] }] }); export { JSS_DATE_PIPE_OPTIONS, JssDateModule, JssDatePipe }; //# sourceMappingURL=js-sugar-angular-date.mjs.map