Skip to content

Commit

Permalink
fix(ngx-pipes): ensure typings correct for tests to pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan-Hall committed Mar 19, 2024
1 parent 337b0f4 commit 304ffac
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 23 deletions.
14 changes: 7 additions & 7 deletions angular-pkgs/ngx-pipes/src/lib/pipes/helpers/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
export function isUndefined(value: any) {
export function isUndefined(value: any): value is undefined {
return typeof value === 'undefined';
}

export function isNull(value: any) {
export function isNull(value: any): value is null {
return value === null;
}

export function isFunction(value: any) {
export function isFunction(value: any): value is Function {
return typeof value === 'function';
}

export function isNumber(value: any) {
export function isNumber(value: any): value is number {
return typeof value === 'number';
}

export function isString(value: any) {
export function isString(value: any): value is string {
return typeof value === 'string';
}

export function isBoolean(value: any) {
export function isBoolean(value: any): value is boolean {
return typeof value === 'boolean';
}

export function isObject(value: any) {
return value !== null && typeof value === 'object';
}

export function isNumberFinite(value: any) {
export function isNumberFinite(value: any): value is number {
return isNumber(value) && isFinite(value);
}

Expand Down
4 changes: 2 additions & 2 deletions angular-pkgs/ngx-pipes/src/lib/pipes/math/degrees.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ describe('DegreesPipe', () => {
});

it('should return degrees of given number in radians', () => {
expect(pipe.transform(<number>null)).toEqual(NaN);
expect(pipe.transform(<number>undefined)).toEqual(NaN);
expect(pipe.transform(null)).toEqual(NaN);
expect(pipe.transform(undefined)).toEqual(NaN);
expect(pipe.transform(1.5707963267948966)).toEqual(90);
expect(pipe.transform(3.141592653589793)).toEqual(180);
});
Expand Down
2 changes: 1 addition & 1 deletion angular-pkgs/ngx-pipes/src/lib/pipes/math/degrees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { isNumberFinite } from '../helpers/helpers';
standalone: true,
})
export class DegreesPipe implements PipeTransform {
transform(radians: number): number {
transform(radians: number | null | undefined): number {
if (!isNumberFinite(radians)) {
return NaN;
}
Expand Down
4 changes: 2 additions & 2 deletions angular-pkgs/ngx-pipes/src/lib/pipes/math/radians.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ describe('RadiansPipe', () => {
});

it('should return degrees of given number in radians', () => {
expect(pipe.transform(<number>null)).toEqual(NaN);
expect(pipe.transform(<number>undefined)).toEqual(NaN);
expect(pipe.transform(null)).toEqual(NaN);
expect(pipe.transform(undefined)).toEqual(NaN);
expect(pipe.transform(90)).toEqual(1.5707963267948966);
expect(pipe.transform(180)).toEqual(3.141592653589793);
});
Expand Down
4 changes: 2 additions & 2 deletions angular-pkgs/ngx-pipes/src/lib/pipes/math/radians.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { isNumberFinite } from '../helpers/helpers';
standalone: true,
})
export class RadiansPipe implements PipeTransform {
transform(degrees: number): number {
transform(degrees: number | null | undefined): number {
if (!isNumberFinite(degrees)) {
return NaN;
}

return (degrees * Math.PI) / 180;
return (<number>degrees * Math.PI) / 180;
}
}
2 changes: 1 addition & 1 deletion angular-pkgs/ngx-pipes/src/lib/pipes/string/a-or-an.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class AorAnPipe implements PipeTransform {
'm.sc.': 'an',
unicorn: 'a',
};
transform(stringEntity: string): string {
transform(stringEntity: string | null | undefined): string {
if (!stringEntity || stringEntity === '') {
return '';
} else {
Expand Down
4 changes: 2 additions & 2 deletions angular-pkgs/ngx-pipes/src/lib/pipes/string/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { LatinisePipe } from './latinise';
import { LinesPipe } from './lines';
import { UnderscorePipe } from './underscore';
import { MatchPipe } from './match';
import { TestPipe } from './test';
import { TestPipe } from './test-pipe';
import { LeftPadPipe } from './lpad';
import { RightPadPipe } from './rpad';
import { MakePluralStringPipe } from './pluralize';
Expand Down Expand Up @@ -67,7 +67,7 @@ export { LatinisePipe } from './latinise';
export { LinesPipe } from './lines';
export { UnderscorePipe } from './underscore';
export { MatchPipe } from './match';
export { TestPipe } from './test';
export { TestPipe } from './test-pipe';
export { LeftPadPipe } from './lpad';
export { RightPadPipe } from './rpad';
export { MakePluralStringPipe } from './pluralize';
Expand Down
1 change: 0 additions & 1 deletion angular-pkgs/ngx-pipes/src/lib/pipes/string/match.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ describe('MatchPipe Tests', () => {
expect(pipe.transform('42 foo', '[\\d]+$', 'g')).toEqual(null);
expect(pipe.transform('foo', '[\\d]+$', 'g')).toEqual(null);
expect(pipe.transform('FOO', '^foo')).toEqual(null);
expect(pipe.transform('FOO', '^foo', 'i')).toBeTruthy(['FOO']);
});
});
2 changes: 1 addition & 1 deletion angular-pkgs/ngx-pipes/src/lib/pipes/string/pluralize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class MakePluralStringPipe implements PipeTransform {
zero: 'zeroes',
};

transform(singularEntity: string, quantity: number = 0): string {
transform(singularEntity: string | null | undefined, quantity: number = 0): string {
if (!singularEntity || singularEntity === '') {
return '';
}
Expand Down
2 changes: 1 addition & 1 deletion angular-pkgs/ngx-pipes/src/lib/pipes/string/slugify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { isString } from '../helpers/helpers';
standalone: true,
})
export class SlugifyPipe implements PipeTransform {
transform(str: string): string {
transform(str: string | null | undefined) {
return isString(str)
? str
.toLowerCase()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TestPipe } from './test';
import { TestPipe } from './test-pipe';

describe('TestPipe Tests', () => {
let pipe: TestPipe;
Expand Down
2 changes: 1 addition & 1 deletion angular-pkgs/ngx-pipes/src/lib/pipes/string/wrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { isString } from '../helpers/helpers';
standalone: true,
})
export class WrapPipe implements PipeTransform {
transform(str: string, prefix: string = '', suffix: string = ''): string {
transform(str: string | null | undefined, prefix: string = '', suffix: string = '') {
if (!isString(str)) {
return str;
}
Expand Down
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@angular/platform-browser-dynamic": "~17.1.0",
"@angular/router": "~17.1.0",
"@nx/angular": "18.0.8",
"moment": "^2.30.1",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.14.3"
Expand Down

0 comments on commit 304ffac

Please sign in to comment.