mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-14 00:26:21 +00:00
Implement isNumber pipe
This commit is contained in:
13
src-ui/src/app/pipes/is-number.pipe.spec.ts
Normal file
13
src-ui/src/app/pipes/is-number.pipe.spec.ts
Normal file
@@ -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()
|
||||
})
|
||||
})
|
10
src-ui/src/app/pipes/is-number.pipe.ts
Normal file
10
src-ui/src/app/pipes/is-number.pipe.ts
Normal file
@@ -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