Skip to content

Commit

Permalink
add polish street pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikołaj Jarmuła committed Jan 16, 2024
1 parent 9a5e1f3 commit 2b7cefd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
11 changes: 11 additions & 0 deletions lib/main/patterns-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,14 @@ export const isStreetPattern = (value: string): boolean => {
* @param {string} value - value to check.
* @returns {boolean}
*/

export const isPolishStreetPattern = (value: string): boolean => {
const pattern = '[a-zA-Z\\u00C0-\\u017F]+\\s\\d.*$'
return !!value.match(pattern)
}
/**
* Checks if value matches <street><number> pattern
* <pre> /[a-zA-Z\\u00C0-\\u017F]+\\s\\d.*$/ </pre>
* @param {string} value - value to check.
* @returns {boolean}
*/
12 changes: 11 additions & 1 deletion test/patterns-functions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
isNamePattern,
isNipPattern,
isNumericPattern,
isPasswordPattern,
isPasswordPattern, isPolishStreetPattern,
isPostalCodePattern,
isStreetPattern,
} from '../lib'
Expand Down Expand Up @@ -134,4 +134,14 @@ describe('pattern functions', () => {
expect(isStreetPattern('Pyk?')).toBeFalsy()
expect(isStreetPattern('*Cyk*Cyk*Cyk*')).toBeFalsy()
})

it('isPolishStreetPattern should validate correctly', () => {
expect(isPolishStreetPattern('Klonowa 32')).toBeTruthy()
expect(isPolishStreetPattern('klonowa 32')).toBeTruthy()
expect(isPolishStreetPattern('KLONOWA 32')).toBeTruthy()
expect(isPolishStreetPattern('ul. Klonował 32')).toBeTruthy()
expect(isPolishStreetPattern('32 Klonowa')).toBeFalsy()
expect(isPolishStreetPattern('Klonowa')).toBeFalsy()
expect(isPolishStreetPattern('32')).toBeFalsy()
})
})

0 comments on commit 2b7cefd

Please sign in to comment.