Skip to content

Commit

Permalink
style: reformat all code with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
urish committed Jun 12, 2020
1 parent f580d53 commit 10fe5c5
Show file tree
Hide file tree
Showing 31 changed files with 122 additions and 111 deletions.
2 changes: 1 addition & 1 deletion src/add.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
19 changes: 13 additions & 6 deletions src/add.pipe.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
10 changes: 6 additions & 4 deletions src/calendar.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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),
);
});
});
});
10 changes: 8 additions & 2 deletions src/calendar.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
/* 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';

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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/date-format.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
6 changes: 4 additions & 2 deletions src/date-format.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
/* 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: '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]);
}
}
6 changes: 2 additions & 4 deletions src/difference.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -35,6 +34,5 @@ describe('DifferencePipe', () => {
const testDate = new Date(2013, 0, 22, 4, 46, 54);
expect(String(pipe.transform(today, testDate))).toContain('-');
});

});
});
15 changes: 8 additions & 7 deletions src/difference.pipe.ts
Original file line number Diff line number Diff line change
@@ -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);
}
Expand Down
12 changes: 7 additions & 5 deletions src/duration.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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');
Expand Down
8 changes: 4 additions & 4 deletions src/duration.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { NGX_MOMENT_OPTIONS, NgxMomentOptions } from './moment-options';

@Pipe({ name: 'amDuration' })
export class DurationPipe implements PipeTransform {

allowedUnits: Array<string> = ['ss', 's', 'm', 'h', 'd', 'M'];

constructor(@Optional() @Inject(NGX_MOMENT_OPTIONS) momentOptions?: NgxMomentOptions) {
Expand All @@ -26,11 +25,12 @@ export class DurationPipe implements PipeTransform {

if (!!momentOptions.relativeTimeThresholdOptions) {
const units: Array<string> = Object.keys(momentOptions.relativeTimeThresholdOptions);
const filteredUnits: Array<string> = units.filter(unit => this.allowedUnits.indexOf(unit) !== -1);
filteredUnits.forEach(unit => {
const filteredUnits: Array<string> = units.filter(
(unit) => this.allowedUnits.indexOf(unit) !== -1,
);
filteredUnits.forEach((unit) => {
moment.relativeTimeThreshold(unit, momentOptions.relativeTimeThresholdOptions[unit]);
});
}
}

}
2 changes: 1 addition & 1 deletion src/from-unix.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/from-unix.pipe.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
4 changes: 0 additions & 4 deletions src/from-utc.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { DateFormatPipe } from './date-format.pipe';
import { FromUtcPipe } from './from-utc.pipe';

describe('UtcPipe', () => {

describe('#transform', () => {

let utcDatePipe: FromUtcPipe;

beforeEach(() => {
Expand Down Expand Up @@ -92,7 +90,5 @@ describe('UtcPipe', () => {
expect(utcDate).toEqual(expect.any(moment));
expect(utcDate.isValid()).toBe(false);
});

});

});
4 changes: 2 additions & 2 deletions src/from-utc.pipe.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
3 changes: 1 addition & 2 deletions src/is-after.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/is-after.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
3 changes: 1 addition & 2 deletions src/is-before.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/is-before.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
4 changes: 0 additions & 4 deletions src/local.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { DateFormatPipe } from './date-format.pipe';
import { LocalTimePipe } from './local.pipe';

describe('LocalPipe', () => {

describe('#transform', () => {

let localPipe: LocalTimePipe;

beforeEach(() => {
Expand Down Expand Up @@ -53,7 +51,5 @@ describe('LocalPipe', () => {
const localOutput = localPipe.transform(datetimeString);
expect(amDateFormat.transform(localOutput, momentFormatString)).toEqual('2016-01');
});

});

});
6 changes: 3 additions & 3 deletions src/local.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
12 changes: 6 additions & 6 deletions src/locale.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { DateFormatPipe } from './date-format.pipe';
import { LocalePipe } from './locale.pipe';

describe('LocalePipe', () => {

describe('#transform', () => {

let localePipe: LocalePipe;

beforeEach(() => {
Expand Down Expand Up @@ -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',
);
});

});

});
Loading

0 comments on commit 10fe5c5

Please sign in to comment.