From 10fe5c518947b7c95b54d6d161b2b0b2b822c4f5 Mon Sep 17 00:00:00 2001 From: Uri Shaked Date: Fri, 12 Jun 2020 12:39:02 +0300 Subject: [PATCH] style: reformat all code with prettier --- src/add.pipe.spec.ts | 2 +- src/add.pipe.ts | 19 +++++++++++++------ src/calendar.pipe.spec.ts | 10 ++++++---- src/calendar.pipe.ts | 10 ++++++++-- src/date-format.pipe.spec.ts | 2 +- src/date-format.pipe.ts | 6 ++++-- src/difference.pipe.spec.ts | 6 ++---- src/difference.pipe.ts | 15 ++++++++------- src/duration.pipe.spec.ts | 12 +++++++----- src/duration.pipe.ts | 8 ++++---- src/from-unix.pipe.spec.ts | 2 +- src/from-unix.pipe.ts | 4 ++-- src/from-utc.pipe.spec.ts | 4 ---- src/from-utc.pipe.ts | 4 ++-- src/is-after.pipe.spec.ts | 3 +-- src/is-after.pipe.ts | 10 +++++----- src/is-before.pipe.spec.ts | 3 +-- src/is-before.pipe.ts | 10 +++++----- src/local.pipe.spec.ts | 4 ---- src/local.pipe.ts | 6 +++--- src/locale.pipe.spec.ts | 12 ++++++------ src/moment-options.ts | 4 +++- src/moment.module.ts | 15 ++++++++------- src/parse-zone.pipe.spec.ts | 4 ---- src/parse.pipe.spec.ts | 4 ---- src/parse.pipe.ts | 2 +- src/subtract.pipe.spec.ts | 6 ++++-- src/subtract.pipe.ts | 19 +++++++++++++------ src/time-ago.pipe.spec.ts | 1 - src/time-ago.pipe.ts | 22 +++++++++++++--------- src/utc.pipe.spec.ts | 4 ---- 31 files changed, 122 insertions(+), 111 deletions(-) diff --git a/src/add.pipe.spec.ts b/src/add.pipe.spec.ts index 99856c9..98e0e77 100644 --- a/src/add.pipe.spec.ts +++ b/src/add.pipe.spec.ts @@ -5,7 +5,7 @@ import { AddPipe } from './add.pipe'; describe('AddPipe', () => { let pipe: AddPipe; - beforeEach(() => pipe = new AddPipe()); + beforeEach(() => (pipe = new AddPipe())); describe('#transform', () => { it('should throw when provided no arguments', () => { diff --git a/src/add.pipe.ts b/src/add.pipe.ts index 4d47c87..59ddc55 100644 --- a/src/add.pipe.ts +++ b/src/add.pipe.ts @@ -1,16 +1,23 @@ /* ngx-moment (c) 2015, 2016 Uri Shaked / MIT Licence */ -import {Pipe, PipeTransform} from '@angular/core'; +import { Pipe, PipeTransform } from '@angular/core'; import * as moment from 'moment'; const momentConstructor = moment; @Pipe({ name: 'amAdd' }) export class AddPipe implements PipeTransform { - transform(value: moment.MomentInput, amount: moment.DurationInputArg1, unit?: moment.DurationInputArg2): any { - if (typeof amount === 'undefined' || (typeof amount === 'number' && typeof unit === 'undefined')) { - throw new Error('AddPipe: missing required arguments'); - } - return momentConstructor(value).add(amount, unit); + transform( + value: moment.MomentInput, + amount: moment.DurationInputArg1, + unit?: moment.DurationInputArg2, + ): any { + if ( + typeof amount === 'undefined' || + (typeof amount === 'number' && typeof unit === 'undefined') + ) { + throw new Error('AddPipe: missing required arguments'); } + return momentConstructor(value).add(amount, unit); + } } diff --git a/src/calendar.pipe.spec.ts b/src/calendar.pipe.spec.ts index e307ada..62c3438 100644 --- a/src/calendar.pipe.spec.ts +++ b/src/calendar.pipe.spec.ts @@ -1,10 +1,10 @@ import 'reflect-metadata'; import * as moment from 'moment'; -import {NgZone} from '@angular/core'; -import {CalendarPipe} from './calendar.pipe'; +import { NgZone } from '@angular/core'; +import { CalendarPipe } from './calendar.pipe'; class NgZoneMock { - runOutsideAngular (fn: Function) { + runOutsideAngular(fn: Function) { return fn(); } run(fn: Function) { @@ -35,7 +35,9 @@ describe('CalendarPipe', () => { const testDate = moment(); const referenceTime = moment().clone().add(1, 'day'); const formats = { lastDay: '[Last day at] h:mm A' }; - expect(pipe.transform(testDate, formats, referenceTime)).toBe(pipe.transform(testDate, referenceTime, formats)); + expect(pipe.transform(testDate, formats, referenceTime)).toBe( + pipe.transform(testDate, referenceTime, formats), + ); }); }); }); diff --git a/src/calendar.pipe.ts b/src/calendar.pipe.ts index 2246825..912aacf 100644 --- a/src/calendar.pipe.ts +++ b/src/calendar.pipe.ts @@ -1,6 +1,13 @@ /* ngx-moment (c) 2015, 2016 Uri Shaked / MIT Licence */ -import { Pipe, ChangeDetectorRef, PipeTransform, EventEmitter, OnDestroy, NgZone } from '@angular/core'; +import { + Pipe, + ChangeDetectorRef, + PipeTransform, + EventEmitter, + OnDestroy, + NgZone, +} from '@angular/core'; import * as moment from 'moment'; import { Subscription } from 'rxjs'; @@ -8,7 +15,6 @@ const momentConstructor = moment; @Pipe({ name: 'amCalendar', pure: false }) export class CalendarPipe implements PipeTransform, OnDestroy { - /** * Internal reference counter, so we can clean up when no instances are in use */ diff --git a/src/date-format.pipe.spec.ts b/src/date-format.pipe.spec.ts index 9401f80..3cd8545 100644 --- a/src/date-format.pipe.spec.ts +++ b/src/date-format.pipe.spec.ts @@ -1,5 +1,5 @@ import * as moment from 'moment'; -import {DateFormatPipe} from './date-format.pipe'; +import { DateFormatPipe } from './date-format.pipe'; describe('DateFormatPipe', () => { describe('#transform', () => { diff --git a/src/date-format.pipe.ts b/src/date-format.pipe.ts index f88415b..5333b4d 100644 --- a/src/date-format.pipe.ts +++ b/src/date-format.pipe.ts @@ -1,6 +1,6 @@ /* ngx-moment (c) 2015, 2016 Uri Shaked / MIT Licence */ -import {Pipe, PipeTransform} from '@angular/core'; +import { Pipe, PipeTransform } from '@angular/core'; import * as moment from 'moment'; const momentConstructor = moment; @@ -8,7 +8,9 @@ const momentConstructor = moment; @Pipe({ name: 'amDateFormat' }) export class DateFormatPipe implements PipeTransform { transform(value: moment.MomentInput, ...args: any[]): string { - if (!value) { return ''; } + if (!value) { + return ''; + } return momentConstructor(value).format(args[0]); } } diff --git a/src/difference.pipe.spec.ts b/src/difference.pipe.spec.ts index ebc60af..5971db8 100644 --- a/src/difference.pipe.spec.ts +++ b/src/difference.pipe.spec.ts @@ -1,12 +1,11 @@ -import {DifferencePipe} from './difference.pipe'; +import { DifferencePipe } from './difference.pipe'; describe('DifferencePipe', () => { let pipe: DifferencePipe; - beforeEach(() => pipe = new DifferencePipe()); + beforeEach(() => (pipe = new DifferencePipe())); describe('#transform', () => { - it('should take the difference of two dates in milliseconds', () => { const today = new Date(2012, 0, 22, 0, 0, 0); const testDate = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 13, 33, 33); @@ -35,6 +34,5 @@ describe('DifferencePipe', () => { const testDate = new Date(2013, 0, 22, 4, 46, 54); expect(String(pipe.transform(today, testDate))).toContain('-'); }); - }); }); diff --git a/src/difference.pipe.ts b/src/difference.pipe.ts index f29e8a3..4832da0 100644 --- a/src/difference.pipe.ts +++ b/src/difference.pipe.ts @@ -1,19 +1,20 @@ /* ngx-moment (c) 2015, 2016 Uri Shaked / MIT Licence */ -import {Pipe, PipeTransform} from '@angular/core'; +import { Pipe, PipeTransform } from '@angular/core'; import * as moment from 'moment'; const momentConstructor = moment; @Pipe({ name: 'amDifference' }) export class DifferencePipe implements PipeTransform { - transform(value: moment.MomentInput, - otherValue: moment.MomentInput, - unit?: moment.unitOfTime.Diff, - precision?: boolean): number { - + transform( + value: moment.MomentInput, + otherValue: moment.MomentInput, + unit?: moment.unitOfTime.Diff, + precision?: boolean, + ): number { const date = momentConstructor(value); - const date2 = (otherValue !== null) ? momentConstructor(otherValue) : momentConstructor(); + const date2 = otherValue !== null ? momentConstructor(otherValue) : momentConstructor(); return date.diff(date2, unit, precision); } diff --git a/src/duration.pipe.spec.ts b/src/duration.pipe.spec.ts index 373e3d8..6fec305 100644 --- a/src/duration.pipe.spec.ts +++ b/src/duration.pipe.spec.ts @@ -4,11 +4,13 @@ import { NgxMomentOptions } from './moment-options'; describe('DurationPipe', () => { let pipe: DurationPipe; - beforeEach(() => pipe = new DurationPipe()); + beforeEach(() => (pipe = new DurationPipe())); describe('#transform', () => { it('should throw when provided no arguments', () => { - expect(() => pipe.transform(128)).toThrow('DurationPipe: missing required time unit argument'); + expect(() => pipe.transform(128)).toThrow( + 'DurationPipe: missing required time unit argument', + ); }); it('should convert a duration to a human-readable string', () => { @@ -27,11 +29,11 @@ describe('DurationPipe', () => { describe('ctor with NgxMomentOptions', () => { const momentOptions: NgxMomentOptions = { relativeTimeThresholdOptions: { - 'm': 59 - } + m: 59, + }, }; - beforeEach(() => pipe = new DurationPipe(momentOptions)); + beforeEach(() => (pipe = new DurationPipe(momentOptions))); it(`should convert '50 minutes' to '50 minutes' when relativeTimeThreshold for 'm' unit is set to 59`, () => { expect(pipe.transform(50, 'minutes')).toEqual('50 minutes'); diff --git a/src/duration.pipe.ts b/src/duration.pipe.ts index 12c1321..38da2f8 100644 --- a/src/duration.pipe.ts +++ b/src/duration.pipe.ts @@ -5,7 +5,6 @@ import { NGX_MOMENT_OPTIONS, NgxMomentOptions } from './moment-options'; @Pipe({ name: 'amDuration' }) export class DurationPipe implements PipeTransform { - allowedUnits: Array = ['ss', 's', 'm', 'h', 'd', 'M']; constructor(@Optional() @Inject(NGX_MOMENT_OPTIONS) momentOptions?: NgxMomentOptions) { @@ -26,11 +25,12 @@ export class DurationPipe implements PipeTransform { if (!!momentOptions.relativeTimeThresholdOptions) { const units: Array = Object.keys(momentOptions.relativeTimeThresholdOptions); - const filteredUnits: Array = units.filter(unit => this.allowedUnits.indexOf(unit) !== -1); - filteredUnits.forEach(unit => { + const filteredUnits: Array = units.filter( + (unit) => this.allowedUnits.indexOf(unit) !== -1, + ); + filteredUnits.forEach((unit) => { moment.relativeTimeThreshold(unit, momentOptions.relativeTimeThresholdOptions[unit]); }); } } - } diff --git a/src/from-unix.pipe.spec.ts b/src/from-unix.pipe.spec.ts index d95b50a..766f32f 100644 --- a/src/from-unix.pipe.spec.ts +++ b/src/from-unix.pipe.spec.ts @@ -1,5 +1,5 @@ import * as moment from 'moment'; -import {FromUnixPipe} from './from-unix.pipe'; +import { FromUnixPipe } from './from-unix.pipe'; describe('FromUnixPipe', () => { describe('#transform', () => { diff --git a/src/from-unix.pipe.ts b/src/from-unix.pipe.ts index 8a5570f..f6cee4a 100644 --- a/src/from-unix.pipe.ts +++ b/src/from-unix.pipe.ts @@ -1,11 +1,11 @@ /* ngx-moment (c) 2015, 2016 Uri Shaked / MIT Licence */ -import {Pipe, PipeTransform} from '@angular/core'; +import { Pipe, PipeTransform } from '@angular/core'; import * as moment from 'moment'; @Pipe({ name: 'amFromUnix' }) export class FromUnixPipe implements PipeTransform { transform(value: number | string, ...args: string[]): any { - return (typeof value === 'string') ? moment.unix(parseInt(value, 10)) : moment.unix(value); + return typeof value === 'string' ? moment.unix(parseInt(value, 10)) : moment.unix(value); } } diff --git a/src/from-utc.pipe.spec.ts b/src/from-utc.pipe.spec.ts index 2b69e2d..22734bd 100644 --- a/src/from-utc.pipe.spec.ts +++ b/src/from-utc.pipe.spec.ts @@ -3,9 +3,7 @@ import { DateFormatPipe } from './date-format.pipe'; import { FromUtcPipe } from './from-utc.pipe'; describe('UtcPipe', () => { - describe('#transform', () => { - let utcDatePipe: FromUtcPipe; beforeEach(() => { @@ -92,7 +90,5 @@ describe('UtcPipe', () => { expect(utcDate).toEqual(expect.any(moment)); expect(utcDate.isValid()).toBe(false); }); - }); - }); diff --git a/src/from-utc.pipe.ts b/src/from-utc.pipe.ts index 657efff..2d89fcc 100644 --- a/src/from-utc.pipe.ts +++ b/src/from-utc.pipe.ts @@ -1,11 +1,11 @@ /* ngx-moment (c) 2015, 2016 Uri Shaked / MIT Licence */ -import {Pipe, PipeTransform} from '@angular/core'; +import { Pipe, PipeTransform } from '@angular/core'; import * as moment from 'moment'; @Pipe({ name: 'amFromUtc' }) export class FromUtcPipe implements PipeTransform { - transform(value: moment.MomentInput, formats?: string|string[], ...args: string[]): any { + transform(value: moment.MomentInput, formats?: string | string[], ...args: string[]): any { return formats ? moment.utc(value, formats) : moment.utc(value); } } diff --git a/src/is-after.pipe.spec.ts b/src/is-after.pipe.spec.ts index 695cf8b..88ff4a3 100644 --- a/src/is-after.pipe.spec.ts +++ b/src/is-after.pipe.spec.ts @@ -4,10 +4,9 @@ import { IsAfterPipe } from './is-after.pipe'; describe('IsAfterPipe', () => { let pipe: IsAfterPipe; - beforeEach(() => pipe = new IsAfterPipe()); + beforeEach(() => (pipe = new IsAfterPipe())); describe('#transform', () => { - it('should return true if value is after otherValue', () => { const test = new Date(2018, 11, 15, 0, 0, 0); const testDate1 = new Date(2018, 11, 13, 0, 0, 0); diff --git a/src/is-after.pipe.ts b/src/is-after.pipe.ts index 21ec1d9..083bb08 100644 --- a/src/is-after.pipe.ts +++ b/src/is-after.pipe.ts @@ -5,14 +5,14 @@ import { Pipe, PipeTransform } from '@angular/core'; const momentConstructor = moment; @Pipe({ - name: 'amIsAfter' + name: 'amIsAfter', }) export class IsAfterPipe implements PipeTransform { - - transform(value: moment.MomentInput, + transform( + value: moment.MomentInput, otherValue: moment.MomentInput, - unit?: moment.unitOfTime.StartOf): boolean { + unit?: moment.unitOfTime.StartOf, + ): boolean { return momentConstructor(value).isAfter(momentConstructor(otherValue), unit); } - } diff --git a/src/is-before.pipe.spec.ts b/src/is-before.pipe.spec.ts index 3cd9a72..b2bfc44 100644 --- a/src/is-before.pipe.spec.ts +++ b/src/is-before.pipe.spec.ts @@ -3,10 +3,9 @@ import { IsBeforePipe } from './is-before.pipe'; describe('IsBeforePipe', () => { let pipe: IsBeforePipe; - beforeEach(() => pipe = new IsBeforePipe()); + beforeEach(() => (pipe = new IsBeforePipe())); describe('#transform', () => { - it('should return true if value is before otherValue', () => { const test = new Date(2018, 11, 13, 0, 0, 0); const testDate1 = new Date(2018, 11, 15, 0, 0, 0); diff --git a/src/is-before.pipe.ts b/src/is-before.pipe.ts index 608c34e..7f0e552 100644 --- a/src/is-before.pipe.ts +++ b/src/is-before.pipe.ts @@ -5,14 +5,14 @@ import { Pipe, PipeTransform } from '@angular/core'; const momentConstructor = moment; @Pipe({ - name: 'amIsBefore' + name: 'amIsBefore', }) export class IsBeforePipe implements PipeTransform { - - transform(value: moment.MomentInput, + transform( + value: moment.MomentInput, otherValue: moment.MomentInput, - unit?: moment.unitOfTime.StartOf): boolean { + unit?: moment.unitOfTime.StartOf, + ): boolean { return momentConstructor(value).isBefore(momentConstructor(otherValue), unit); } - } diff --git a/src/local.pipe.spec.ts b/src/local.pipe.spec.ts index cc91a7a..d33d3c9 100644 --- a/src/local.pipe.spec.ts +++ b/src/local.pipe.spec.ts @@ -3,9 +3,7 @@ import { DateFormatPipe } from './date-format.pipe'; import { LocalTimePipe } from './local.pipe'; describe('LocalPipe', () => { - describe('#transform', () => { - let localPipe: LocalTimePipe; beforeEach(() => { @@ -53,7 +51,5 @@ describe('LocalPipe', () => { const localOutput = localPipe.transform(datetimeString); expect(amDateFormat.transform(localOutput, momentFormatString)).toEqual('2016-01'); }); - }); - }); diff --git a/src/local.pipe.ts b/src/local.pipe.ts index e55b696..02f0dbe 100644 --- a/src/local.pipe.ts +++ b/src/local.pipe.ts @@ -5,7 +5,7 @@ const momentConstructor = moment; @Pipe({ name: 'amLocal' }) export class LocalTimePipe implements PipeTransform { - transform(value: moment.MomentInput): moment.Moment { - return momentConstructor(value).local(); - } + transform(value: moment.MomentInput): moment.Moment { + return momentConstructor(value).local(); + } } diff --git a/src/locale.pipe.spec.ts b/src/locale.pipe.spec.ts index f51704b..b4f1ffb 100644 --- a/src/locale.pipe.spec.ts +++ b/src/locale.pipe.spec.ts @@ -3,9 +3,7 @@ import { DateFormatPipe } from './date-format.pipe'; import { LocalePipe } from './locale.pipe'; describe('LocalePipe', () => { - describe('#transform', () => { - let localePipe: LocalePipe; beforeEach(() => { @@ -33,10 +31,12 @@ describe('LocalePipe', () => { const momentFormatString2 = 'MMMM Do YYYY, HH:mm:ss'; const parseOutput1 = localePipe.transform(datetimeString, langKeyString1); const parseOutput2 = localePipe.transform(datetimeString, langKeyString2); - expect(amDateFormat.transform(parseOutput1, momentFormatString1)).toEqual('January 24th 2016, 2:23:45 pm'); - expect(amDateFormat.transform(parseOutput2, momentFormatString2)).toEqual('Januar 24. 2016, 14:23:45'); + expect(amDateFormat.transform(parseOutput1, momentFormatString1)).toEqual( + 'January 24th 2016, 2:23:45 pm', + ); + expect(amDateFormat.transform(parseOutput2, momentFormatString2)).toEqual( + 'Januar 24. 2016, 14:23:45', + ); }); - }); - }); diff --git a/src/moment-options.ts b/src/moment-options.ts index 8c5a66d..a13da22 100644 --- a/src/moment-options.ts +++ b/src/moment-options.ts @@ -1,6 +1,8 @@ import { InjectionToken } from '@angular/core'; -export const NGX_MOMENT_OPTIONS: InjectionToken = new InjectionToken('NGX_MOMENT_OPTIONS'); +export const NGX_MOMENT_OPTIONS: InjectionToken = new InjectionToken< + NgxMomentOptions +>('NGX_MOMENT_OPTIONS'); export interface NgxMomentOptions { /** diff --git a/src/moment.module.ts b/src/moment.module.ts index f35aea1..c7c6ad4 100644 --- a/src/moment.module.ts +++ b/src/moment.module.ts @@ -34,12 +34,12 @@ const ANGULAR_MOMENT_PIPES = [ LocalePipe, ParseZonePipe, IsBeforePipe, - IsAfterPipe + IsAfterPipe, ]; @NgModule({ declarations: ANGULAR_MOMENT_PIPES, - exports: ANGULAR_MOMENT_PIPES + exports: ANGULAR_MOMENT_PIPES, }) export class MomentModule { static forRoot(options?: NgxMomentOptions): ModuleWithProviders { @@ -47,11 +47,12 @@ export class MomentModule { ngModule: MomentModule, providers: [ { - provide: NGX_MOMENT_OPTIONS, useValue: { - ...options - } - } - ] + provide: NGX_MOMENT_OPTIONS, + useValue: { + ...options, + }, + }, + ], }; } } diff --git a/src/parse-zone.pipe.spec.ts b/src/parse-zone.pipe.spec.ts index 668f5ea..ea4e9e4 100644 --- a/src/parse-zone.pipe.spec.ts +++ b/src/parse-zone.pipe.spec.ts @@ -2,9 +2,7 @@ import * as moment from 'moment'; import { ParseZonePipe } from './parse-zone.pipe'; describe('ParseZonePipe', () => { - describe('#transform', () => { - let parseZonePipe: ParseZonePipe; beforeEach(() => { @@ -37,7 +35,5 @@ describe('ParseZonePipe', () => { const parsedDate = parseZonePipe.transform(date); expect(parsedDate.utcOffset()).toEqual(offset); }); - }); - }); diff --git a/src/parse.pipe.spec.ts b/src/parse.pipe.spec.ts index 43d98a5..fd9fd7e 100644 --- a/src/parse.pipe.spec.ts +++ b/src/parse.pipe.spec.ts @@ -3,9 +3,7 @@ import { DateFormatPipe } from './date-format.pipe'; import { ParsePipe } from './parse.pipe'; describe('ParsePipe', () => { - describe('#transform', () => { - let parsePipe: ParsePipe; beforeEach(() => { @@ -44,7 +42,5 @@ describe('ParsePipe', () => { expect(parsedMoment.month()).toBe(8); expect(parsedMoment.date()).toBe(13); }); - }); - }); diff --git a/src/parse.pipe.ts b/src/parse.pipe.ts index c4649ff..cd2d1f9 100644 --- a/src/parse.pipe.ts +++ b/src/parse.pipe.ts @@ -5,7 +5,7 @@ const momentConstructor = moment; @Pipe({ name: 'amParse' }) export class ParsePipe implements PipeTransform { - transform(value: moment.MomentInput, formats: string|string[]): moment.Moment { + transform(value: moment.MomentInput, formats: string | string[]): moment.Moment { return momentConstructor(value, formats); } } diff --git a/src/subtract.pipe.spec.ts b/src/subtract.pipe.spec.ts index 798d143..0320b1b 100644 --- a/src/subtract.pipe.spec.ts +++ b/src/subtract.pipe.spec.ts @@ -4,11 +4,13 @@ import { SubtractPipe } from './subtract.pipe'; describe('SubtractPipe', () => { let pipe: SubtractPipe; - beforeEach(() => pipe = new SubtractPipe()); + beforeEach(() => (pipe = new SubtractPipe())); describe('#transform', () => { it('should throw when provided no arguments', () => { - expect(() => (pipe.transform as any)(128)).toThrow('SubtractPipe: missing required arguments'); + expect(() => (pipe.transform as any)(128)).toThrow( + 'SubtractPipe: missing required arguments', + ); }); it('should subtract two hours', () => { diff --git a/src/subtract.pipe.ts b/src/subtract.pipe.ts index 3550f26..b20fad6 100644 --- a/src/subtract.pipe.ts +++ b/src/subtract.pipe.ts @@ -1,16 +1,23 @@ /* ngx-moment (c) 2015, 2016 Uri Shaked / MIT Licence */ -import {Pipe, PipeTransform} from '@angular/core'; +import { Pipe, PipeTransform } from '@angular/core'; import * as moment from 'moment'; const momentConstructor = moment; @Pipe({ name: 'amSubtract' }) export class SubtractPipe implements PipeTransform { - transform(value: moment.MomentInput, amount: moment.DurationInputArg1, unit?: moment.DurationInputArg2): any { - if (typeof amount === 'undefined' || (typeof amount === 'number' && typeof unit === 'undefined')) { - throw new Error('SubtractPipe: missing required arguments'); - } - return momentConstructor(value).subtract(amount, unit); + transform( + value: moment.MomentInput, + amount: moment.DurationInputArg1, + unit?: moment.DurationInputArg2, + ): any { + if ( + typeof amount === 'undefined' || + (typeof amount === 'number' && typeof unit === 'undefined') + ) { + throw new Error('SubtractPipe: missing required arguments'); } + return momentConstructor(value).subtract(amount, unit); + } } diff --git a/src/time-ago.pipe.spec.ts b/src/time-ago.pipe.spec.ts index c750774..44d6d97 100644 --- a/src/time-ago.pipe.spec.ts +++ b/src/time-ago.pipe.spec.ts @@ -23,7 +23,6 @@ function fakeDate(defaultDate: string | number) { describe('TimeAgoPipe', () => { describe('#transform', () => { - beforeEach(() => { moment.locale('en-gb'); jest.useFakeTimers(); diff --git a/src/time-ago.pipe.ts b/src/time-ago.pipe.ts index d0850bb..1084d80 100644 --- a/src/time-ago.pipe.ts +++ b/src/time-ago.pipe.ts @@ -1,11 +1,11 @@ /* ngx-moment (c) 2015, 2016 Uri Shaked / MIT Licence */ -import {Pipe, ChangeDetectorRef, PipeTransform, OnDestroy, NgZone} from '@angular/core'; +import { Pipe, ChangeDetectorRef, PipeTransform, OnDestroy, NgZone } from '@angular/core'; import * as moment from 'moment'; const momentConstructor = moment; -@Pipe({name: 'amTimeAgo', pure: false}) +@Pipe({ name: 'amTimeAgo', pure: false }) export class TimeAgoPipe implements PipeTransform, OnDestroy { private currentTimer: number | null; @@ -16,14 +16,17 @@ export class TimeAgoPipe implements PipeTransform, OnDestroy { private lastText: string; private formatFn: (m: moment.Moment) => string; - constructor(private cdRef: ChangeDetectorRef, private ngZone: NgZone) { - } + constructor(private cdRef: ChangeDetectorRef, private ngZone: NgZone) {} format(m: moment.Moment) { return m.from(momentConstructor(), this.lastOmitSuffix); } - transform(value: moment.MomentInput, omitSuffix?: boolean, formatFn?: (m: moment.Moment) => string): string { + transform( + value: moment.MomentInput, + omitSuffix?: boolean, + formatFn?: (m: moment.Moment) => string, + ): string { if (this.hasChanged(value, omitSuffix)) { this.lastTime = this.getTime(value); this.lastValue = value; @@ -33,7 +36,6 @@ export class TimeAgoPipe implements PipeTransform, OnDestroy { this.removeTimer(); this.createTimer(); this.lastText = this.formatFn(momentConstructor(value)); - } else { this.createTimer(); } @@ -88,9 +90,11 @@ export class TimeAgoPipe implements PipeTransform, OnDestroy { } private hasChanged(value: moment.MomentInput, omitSuffix?: boolean): boolean { - return this.getTime(value) !== this.lastTime - || this.getLocale(value) !== this.lastLocale - || omitSuffix !== this.lastOmitSuffix; + return ( + this.getTime(value) !== this.lastTime || + this.getLocale(value) !== this.lastLocale || + omitSuffix !== this.lastOmitSuffix + ); } private getTime(value: moment.MomentInput): number { diff --git a/src/utc.pipe.spec.ts b/src/utc.pipe.spec.ts index 313e740..0469869 100644 --- a/src/utc.pipe.spec.ts +++ b/src/utc.pipe.spec.ts @@ -3,9 +3,7 @@ import { DateFormatPipe } from './date-format.pipe'; import { UtcPipe } from './utc.pipe'; describe('UtcPipe', () => { - describe('#transform', () => { - let utcDatePipe: UtcPipe; beforeEach(() => { @@ -53,7 +51,5 @@ describe('UtcPipe', () => { const utcOutput = utcDatePipe.transform(datetimeString); expect(amDateFormat.transform(utcOutput, momentFormatString)).toEqual('2016-01-01'); }); - }); - });