This repository was archived by the owner on Feb 23, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +67
-2
lines changed Expand file tree Collapse file tree 5 files changed +67
-2
lines changed Original file line number Diff line number Diff line change 9
9
* [ ` random ` ] ( #random )
10
10
* [ ` pow ` ] ( #pow )
11
11
* [ ` sqrt ` ] ( #sqrt )
12
+ * [ ` abs ` ] ( #abs )
12
13
13
14
You can check the module import [ ` here ` ] ( ./modules.md ) .
14
15
@@ -188,3 +189,19 @@ import { PowPipe } from 'angular-pipes';
188
189
{{ 2 | pow }} <!-- 4 -->
189
190
{{ 2 | pow: 3 }} <!-- 8 -->
190
191
```
192
+
193
+ #### abs
194
+
195
+ Returns the absolute of a number.
196
+
197
+ ##### File
198
+
199
+ ``` typescript
200
+ import { AbsPipe } from ' angular-pipes' ;
201
+ ```
202
+
203
+ ##### Usage
204
+
205
+ ``` html
206
+ {{ -2 | abs }} <!-- 2 -->
207
+ ```
Original file line number Diff line number Diff line change
1
+ import { AbsPipe } from './abs.pipe' ;
2
+
3
+
4
+
5
+ describe ( 'AbsPipe' , ( ) => {
6
+
7
+ let pipe : AbsPipe ;
8
+
9
+ beforeEach ( ( ) => {
10
+ pipe = new AbsPipe ( ) ;
11
+ } ) ;
12
+
13
+ it ( 'Should return 2' , ( ) => {
14
+
15
+ expect ( pipe . transform ( 2 ) ) . toEqual ( 2 ) ;
16
+ } ) ;
17
+
18
+ it ( 'Should return 2' , ( ) => {
19
+
20
+ expect ( pipe . transform ( - 2 ) ) . toEqual ( 2 ) ;
21
+ } ) ;
22
+
23
+ it ( 'Should return NaN' , ( ) => {
24
+ expect ( pipe . transform ( 'a' ) ) . toEqual ( 'NaN' ) ;
25
+ } ) ;
26
+
27
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { Pipe , PipeTransform } from '@angular/core' ;
2
+ import { isNumberFinite } from '../utils/utils' ;
3
+
4
+ @Pipe ( {
5
+ name : 'abs'
6
+ } )
7
+ export class AbsPipe implements PipeTransform {
8
+
9
+ transform ( input : any ) : any {
10
+
11
+ if ( ! isNumberFinite ( input ) ) {
12
+ return 'NaN' ;
13
+ }
14
+
15
+ return Math . abs ( input ) ;
16
+ }
17
+ }
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import { RadiansPipe } from './radians.pipe';
9
9
import { RandomPipe } from './random.pipe' ;
10
10
import { SqrtPipe } from './sqrt.pipe' ;
11
11
import { PowPipe } from './pow.pipe' ;
12
+ import { AbsPipe } from './abs.pipe' ;
12
13
13
14
@NgModule ( {
14
15
declarations : [
@@ -20,7 +21,8 @@ import { PowPipe } from './pow.pipe';
20
21
RadiansPipe ,
21
22
RandomPipe ,
22
23
SqrtPipe ,
23
- PowPipe
24
+ PowPipe ,
25
+ AbsPipe
24
26
] ,
25
27
exports : [
26
28
BytesPipe ,
@@ -31,7 +33,8 @@ import { PowPipe } from './pow.pipe';
31
33
RadiansPipe ,
32
34
RandomPipe ,
33
35
SqrtPipe ,
34
- PowPipe
36
+ PowPipe ,
37
+ AbsPipe
35
38
]
36
39
} )
37
40
export class NgMathPipesModule { }
Original file line number Diff line number Diff line change @@ -78,6 +78,7 @@ export { RadiansPipe } from './math/radians.pipe';
78
78
export { RandomPipe } from './math/random.pipe' ;
79
79
export { SqrtPipe } from './math/sqrt.pipe' ;
80
80
export { PowPipe } from './math/pow.pipe' ;
81
+ export { AbsPipe } from './math/abs.pipe' ;
81
82
82
83
export { KeysPipe } from './object/keys.pipe' ;
83
84
export { ToArrayPipe } from './object/to-array.pipe' ;
You can’t perform that action at this time.
0 commit comments