Skip to content

Commit

Permalink
feat(module:core): add pipe module
Browse files Browse the repository at this point in the history
  • Loading branch information
chensimeng committed Feb 27, 2020
1 parent ca02a07 commit a39edb7
Show file tree
Hide file tree
Showing 47 changed files with 1,192 additions and 25 deletions.
20 changes: 0 additions & 20 deletions components/core/pipe/nz-pipe.module.ts

This file was deleted.

2 changes: 1 addition & 1 deletion components/core/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ export * from './responsive/public-api';
export * from './trans-button/public-api';
export * from './highlight/public-api';
export * from './config/public-api';
export * from './pipe/public-api';
export * from '../pipe/public-api';
13 changes: 13 additions & 0 deletions components/core/util/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,16 @@ export function ensureNumberInRange(num: number, min: number, max: number): numb
return num;
}
}

// tslint:disable-next-line:no-any
export function isNumberFinite(value: any): boolean {
return typeof value === 'number' && isFinite(value);
}

export function toDecimal(value: number, decimal: number): number {
return Math.round(value * Math.pow(10, decimal)) / Math.pow(10, decimal);
}

export function sum(input: number[], initial: number = 0): number {
return input.reduce((previous: number, current: number) => previous + current, initial);
}
2 changes: 1 addition & 1 deletion components/modal/nz-modal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';

import { NzButtonComponent, NzButtonModule } from 'ng-zorro-antd/button';
import { dispatchFakeEvent, dispatchKeyboardEvent } from 'ng-zorro-antd/core';
import { NzToCssUnitPipe } from 'ng-zorro-antd/core/pipe/nz-css-unit.pipe';
import { NzI18nService } from 'ng-zorro-antd/i18n';
import { NzIconTestModule } from 'ng-zorro-antd/icon/testing';
import { NzToCssUnitPipe } from 'ng-zorro-antd/pipe/nz-css-unit.pipe';
import en_US from '../i18n/languages/en_US';

import { NZ_MODAL_CONFIG } from './nz-modal-config';
Expand Down
14 changes: 14 additions & 0 deletions components/pipe/demo/bytes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
order: 1
title:
zh-CN: nzBytes
en-US: nzBytes
---

## zh-CN

存储单位的换算增加可读性

## en-US

Conversion of storage units increases readability
17 changes: 17 additions & 0 deletions components/pipe/demo/bytes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Component } from '@angular/core';

@Component({
selector: 'nz-demo-pipe-bytes',
template: `
<ul>
<li>{{ 200 | nzBytes }}</li>
<li>{{ 1024 | nzBytes }}</li>
<li>{{ 1048576 | nzBytes }}</li>
<li>{{ 1024 | nzBytes: 0:'KB' }}</li>
<li>{{ 1073741824 | nzBytes }}</li>
<li>{{ 1099511627776 | nzBytes }}</li>
<li>{{ 1073741824 | nzBytes: 0:'B':'MB' }}</li>
</ul>
`
})
export class NzDemoPipeBytesComponent {}
14 changes: 14 additions & 0 deletions components/pipe/demo/css-unit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
order: 2
title:
zh-CN: nzToCssUnit
en-US: nzToCssUnit
---

## zh-CN

Css 单位补全

## en-US

Css unit completion
11 changes: 11 additions & 0 deletions components/pipe/demo/css-unit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Component } from '@angular/core';

@Component({
selector: 'nz-demo-pipe-css-unit',
template: `
<div>{{ 200 | nzToCssUnit }}</div>
<div>{{ 200 | nzToCssUnit: 'pt' }}</div>
<div>{{ '200px' | nzToCssUnit: 'pt' }}</div>
`
})
export class NzDemoPipeCssUnitComponent {}
14 changes: 14 additions & 0 deletions components/pipe/demo/ellipsis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
order: 3
title:
zh-CN: nzEllipsis
en-US: nzEllipsis
---

## zh-CN

截断字符串,用指定的字符串结尾

## en-US

Truncate the string, ending with the specified string
12 changes: 12 additions & 0 deletions components/pipe/demo/ellipsis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Component } from '@angular/core';

@Component({
selector: 'nz-demo-pipe-ellipsis',
template: `
{{ 'Hello World' | nzEllipsis: 4 }}<br />
{{ 'Hello World' | nzEllipsis: 4:'':true }}<br />
{{ 'Hello World' | nzEllipsis: 4:'...':true }}<br />
{{ 'Hello World, how is it going?' | nzEllipsis: 14:'...':true }}
`
})
export class NzDemoPipeEllipsisComponent {}
14 changes: 14 additions & 0 deletions components/pipe/demo/math.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
order: 4
title:
zh-CN: nzMath
en-US: nzMath
---

## zh-CN

数组的Sum、Min、Max、Average等聚合操作

## en-US

Sum, Min, Max, Average and other operations on arrays
12 changes: 12 additions & 0 deletions components/pipe/demo/math.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Component } from '@angular/core';

@Component({
selector: 'nz-demo-pipe-math',
template: `
{{ [7, 8, 2, 3] | nzMath: 'min' }}<br />
{{ [7, 8, 2, 3] | nzMath: 'max' }}<br />
{{ [7, 8, 2, 3] | nzMath: 'sum' }}<br />
{{ [7, 8, 2, 3] | nzMath: 'avg' }}<br />
`
})
export class NzDemoPipeMathComponent {}
3 changes: 3 additions & 0 deletions components/pipe/demo/module
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { NzPipesModule } from 'ng-zorro-antd/pipe';

export const moduleList = [ NzPipesModule ];
15 changes: 15 additions & 0 deletions components/pipe/demo/safe-null.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
order: 5
title:
zh-CN: nzSafeNull
en-US: nzSafeNull
---

## zh-CN

转换 Null 和 Undefined 为指定字符串

## en-US

Convert Null and Undefined to the specified string

12 changes: 12 additions & 0 deletions components/pipe/demo/safe-null.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Component } from '@angular/core';

@Component({
selector: 'nz-demo-pipe-safe-null',
template: `
<ul>
<li>使用量:{{ 1000 | nzSafeNull }}</li>
<li>比例:34/{{ null | nzSafeNull: '-' }}</li>
</ul>
`
})
export class NzDemoPipeSafeNullComponent {}
15 changes: 15 additions & 0 deletions components/pipe/demo/sanitizer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
order: 6
title:
zh-CN: nzSanitizer
en-US: nzSanitizer
---

## zh-CN

DomSanitizer 防止跨站点脚本安全漏洞

## en-US

DomSanitizer prevents cross-site scripting vulnerabilities

23 changes: 23 additions & 0 deletions components/pipe/demo/sanitizer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Component } from '@angular/core';

@Component({
selector: 'nz-demo-pipe-sanitizer',
template: `
<div [innerHTML]="htmlSnippet | nzSanitizer: 'html'"></div>
<div [innerHTML]="scriptSnippet | nzSanitizer: 'script'"></div>
<div [style]="styleSnippet | nzSanitizer: 'style'">我不会报警</div>
<hr />
<div><img [src]="urlSnippet | nzSanitizer: 'url'" /></div>
<hr />
<div>
<iframe [src]="resourceUrlSnippet | nzSanitizer: 'resourceUrl'"></iframe>
</div>
`
})
export class NzDemoPipeSanitizerComponent {
htmlSnippet: string = '<p>hello world</p>';
scriptSnippet: string = '<script>function testScript(){alert("我不会报错!")}</script>';
styleSnippet: string = "{'height': '20px'}";
urlSnippet: string = 'https://ng.ant.design/assets/img/logo.svg';
resourceUrlSnippet: string = 'https://ng.ant.design/docs/introduce/zh';
}
14 changes: 14 additions & 0 deletions components/pipe/demo/some.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
order: 7
title:
zh-CN: nzSome
en-US: nzSome
---

## zh-CN

集合中的至少一项通过,则返回true。

## en-US

Returns true if at least one of the item in the collections pass the method.
14 changes: 14 additions & 0 deletions components/pipe/demo/some.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Component } from '@angular/core';

@Component({
selector: 'nz-demo-pipe-some',
template: `
{{ [5, 6, 7, 8, 9] | nzSome: method }}<br />
{{ [6, 7, 8, 9, 10] | nzSome: method }}<br />
`
})
export class NzDemoPipeSomeComponent {
method = (item: number) => {
return item === 5;
};
}
14 changes: 14 additions & 0 deletions components/pipe/demo/time-range.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
order: 9
title:
zh-CN: nzTimeRange
en-US: nzTimeRange
---

## zh-CN

返回指定时间格式

## en-US

Returns the specified time format
18 changes: 18 additions & 0 deletions components/pipe/demo/time-range.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component } from '@angular/core';

@Component({
selector: 'nz-demo-pipe-time-range',
template: `
{{ diff | nzTimeRange: format1 }}<br />
{{ diff | nzTimeRange: format2 }}<br />
{{ diff | nzTimeRange: format3 }}<br />
{{ diff1 | nzTimeRange }}<br />
`
})
export class NzDemoPipeTimeRangeComponent {
diff = 1000 * 60 * 60 * 24 * 2 + 1000 * 30;
diff1 = 0;
format1 = 'HH:mm:ss';
format2 = 'HH:mm';
format3 = 'D 天 H 时 m 分 s 秒';
}
14 changes: 14 additions & 0 deletions components/pipe/demo/trim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
order: 8
title:
zh-CN: nzTrim
en-US: nzTrim
---

## zh-CN

去除字符串左右指定字符

## en-US

Strip left and right string
11 changes: 11 additions & 0 deletions components/pipe/demo/trim.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Component } from '@angular/core';

@Component({
selector: 'nz-demo-pipe-trim',
template: `
{{ 'hello' | nzTrim }}<br />
{{ 'hello ' | nzTrim }}<br />
{{ ' hello ' | nzTrim }}<br />
`
})
export class NzDemoPipeTrimComponent {}
Loading

0 comments on commit a39edb7

Please sign in to comment.