mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-10-07 00:27:12 +00:00
Implement isNumber pipe
This commit is contained in:
1 parent
0b4e8141b0
commit
3dda02660c
8 files changed
+33
-3
No files matched your search
@@ -0,0 +1,13 @@
|
||||
import { IsNumberPipe } from './is-number.pipe'
|
||||
|
||||
describe('IsNumberPipe', () => {
|
||||
it('should detect numbers', () => {
|
||||
const pipe = new IsNumberPipe()
|
||||
expect(pipe.transform(0)).toBeTruthy()
|
||||
expect(pipe.transform(123)).toBeTruthy()
|
||||
expect(pipe.transform('123')).toBeFalsy()
|
||||
expect(pipe.transform(null)).toBeFalsy()
|
||||
expect(pipe.transform(undefined)).toBeFalsy()
|
||||
expect(pipe.transform(NaN)).toBeFalsy()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core'
|
||||
|
||||
@Pipe({
|
||||
name: 'isNumber',
|
||||
})
|
||||
export class IsNumberPipe implements PipeTransform {
|
||||
transform(value: any): boolean {
|
||||
return typeof value === 'number' && !isNaN(value)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user