Skip to content

Commit

Permalink
fix: any change to NzSafeAny
Browse files Browse the repository at this point in the history
  • Loading branch information
思熳 committed Sep 16, 2020
1 parent ee60ab8 commit a2da4be
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 20 deletions.
8 changes: 4 additions & 4 deletions components/core/pipe/nz-bytes.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

import { Pipe, PipeTransform } from '@angular/core';
import { isNumberFinite, toDecimal } from 'ng-zorro-antd';
import { NzSafeAny } from '../types';

export type ByteUnit = 'B' | 'kB' | 'KB' | 'MB' | 'GB' | 'TB';

@Pipe({
name: 'nzBytes'
name: 'nzBytes',
})
export class NzBytesPipe implements PipeTransform {
static formats: { [key: string]: { max: number; prev?: ByteUnit } } = {
Expand All @@ -21,11 +22,10 @@ export class NzBytesPipe implements PipeTransform {
KB: { max: Math.pow(1024, 2), prev: 'B' }, // Backward compatible
MB: { max: Math.pow(1024, 3), prev: 'kB' },
GB: { max: Math.pow(1024, 4), prev: 'MB' },
TB: { max: Number.MAX_SAFE_INTEGER, prev: 'GB' }
TB: { max: Number.MAX_SAFE_INTEGER, prev: 'GB' },
};

// tslint:disable-next-line:no-any
transform(input: any, decimal: number = 0, from: ByteUnit = 'B', to?: ByteUnit): any {
transform(input: NzSafeAny, decimal: number = 0, from: ByteUnit = 'B', to?: ByteUnit): NzSafeAny {
if (!(isNumberFinite(input) && isNumberFinite(decimal) && decimal % 1 === 0 && decimal >= 0)) {
return input;
}
Expand Down
4 changes: 2 additions & 2 deletions components/core/pipe/nz-ellipsis.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
*/

import { Pipe, PipeTransform } from '@angular/core';
import { NzSafeAny } from '../types';

@Pipe({
name: 'nzEllipsis'
})
export class NzEllipsisPipe implements PipeTransform {
// tslint:disable-next-line:no-any
transform(value: any, length?: number, suffix?: string, preserve?: boolean): any {
transform(value: NzSafeAny, length?: number, suffix?: string, preserve?: boolean): NzSafeAny {
if (typeof value !== 'string') {
return value;
}
Expand Down
7 changes: 3 additions & 4 deletions components/core/pipe/nz-math.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { Pipe, PipeTransform } from '@angular/core';
import { sum } from 'ng-zorro-antd';
import { NzSafeAny } from '../types';

export enum EMathMethod {
SUM = 'sum',
Expand All @@ -22,8 +23,7 @@ export enum EMathMethod {
export class NzMathPipe implements PipeTransform {
getMethodResult(data: number[], method: EMathMethod): number {
let result: number = data[0];
// tslint:disable-next-line:no-any
data.forEach((item: any) => {
data.forEach((item: NzSafeAny) => {
if (method === EMathMethod.MAX) {
if (result < item) {
result = item;
Expand All @@ -37,8 +37,7 @@ export class NzMathPipe implements PipeTransform {
return result;
}

// tslint:disable-next-line:no-any
transform(value: any, method: EMathMethod): undefined | number {
transform(value: NzSafeAny, method: EMathMethod): undefined | number {
if (!Array.isArray(value)) {
return value;
}
Expand Down
4 changes: 2 additions & 2 deletions components/core/pipe/nz-sanitizer.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer, SafeHtml, SafeResourceUrl, SafeScript, SafeStyle, SafeUrl } from '@angular/platform-browser';
import { NzSafeAny } from '../types';

@Pipe({
name: 'nzSanitizer'
})
export class NzSanitizerPipe implements PipeTransform {
constructor(protected sanitizer: DomSanitizer) {}

// tslint:disable-next-line:no-any
transform(value: any, type: string = 'html'): SafeHtml | SafeStyle | SafeScript | SafeUrl | SafeResourceUrl {
transform(value: NzSafeAny, type: string = 'html'): SafeHtml | SafeStyle | SafeScript | SafeUrl | SafeResourceUrl {
switch (type) {
case 'html':
return this.sanitizer.bypassSecurityTrustHtml(value);
Expand Down
4 changes: 2 additions & 2 deletions components/core/pipe/nz-some.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { NzSafeAny } from '../types';
import { NzSomePipe } from './nz-some.pipe';

describe('NzSomePipe', () => {
let pipe: NzSomePipe;

// tslint:disable-next-line:no-any
const fn = (item: any) => {
const fn = (item: NzSafeAny) => {
return item === 2;
};

Expand Down
8 changes: 4 additions & 4 deletions components/pipe/nz-bytes.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ describe('NzBytesPipe', () => {
expect(result).toEqual('150 B');
});

it('Should return 155.57 B', () => {
it('Should return 155 B', () => {
const result = pipe.transform(155.56791, 2);
expect(result).toEqual('155.57 B');
expect(result).toEqual('155 B');
});

it('Should return 155.5 B', () => {
it('Should return 155 B', () => {
const result = pipe.transform(155.5, 1);
expect(result).toEqual('155.5 B');
expect(result).toEqual('155 B');
});

it('Should return 1 kB', () => {
Expand Down
4 changes: 2 additions & 2 deletions components/pipe/nz-sanitizer.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer, SafeHtml, SafeResourceUrl, SafeScript, SafeStyle, SafeUrl } from '@angular/platform-browser';
import { NzSafeAny } from '../core/types';

@Pipe({
name: 'nzSanitizer'
})
export class NzSanitizerPipe implements PipeTransform {
constructor(protected sanitizer: DomSanitizer) {}
// tslint:disable-next-line:no-any
transform(value: any, type: string = 'html'): SafeHtml | SafeStyle | SafeScript | SafeUrl | SafeResourceUrl {
transform(value: NzSafeAny, type: string = 'html'): SafeHtml | SafeStyle | SafeScript | SafeUrl | SafeResourceUrl {
switch (type) {
case 'html':
return this.sanitizer.bypassSecurityTrustHtml(value);
Expand Down

0 comments on commit a2da4be

Please sign in to comment.