-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(filters): add police number filter
- Loading branch information
hirsch
committed
Sep 28, 2021
1 parent
91a0d8e
commit 912e74b
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { balPoliceNumber } from './balPoliceNumber' | ||
|
||
describe('balPoliceNumber', () => { | ||
test('should format a claim number correctly', () => { | ||
expect(balPoliceNumber('501222333')).toBe('50/1.222.333') | ||
}) | ||
test('should format null as empty string', () => { | ||
expect(balPoliceNumber(null)).toBe('') | ||
}) | ||
test('should output a number with a wrong format raw', () => { | ||
expect(balPoliceNumber('123')).toBe('123') | ||
}) | ||
test('should format a claim number with a sign postfix correctly', () => { | ||
expect(balPoliceNumber('0501222333')).toBe('50/1.222.333') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Transforms the given string into the correct police-number format. | ||
* | ||
* ```typescript | ||
* balPoliceNumber('501222333') // 50/1.222.333 | ||
* ``` | ||
*/ | ||
export function balPoliceNumber(value: string | undefined | null | number): string { | ||
if (!value) { | ||
return '' | ||
} | ||
let newValue = `${value}` | ||
if (newValue[0] !== '0') { | ||
newValue = `0${value}` | ||
} | ||
const parts = [newValue.substring(1, 3), newValue.substring(3, 4), newValue.substring(4, 7), newValue.substring(7, 10)].filter(val => val.length > 0) | ||
if (!parts || parts.length < 4) { | ||
return `${value}` | ||
} | ||
return `${parts[0]}/${parts[1]}.${parts[2]}.${parts[3]}` | ||
} |