Skip to content

Commit

Permalink
Merge pull request #7 from niels-bosman/feature/forbidden-words
Browse files Browse the repository at this point in the history
Feature/forbidden words
  • Loading branch information
niels-bosman authored Sep 10, 2021
2 parents 7f7ef97 + f4d0833 commit 7ee080a
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 20 deletions.
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.5.2",
"version": "2.0.0",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down Expand Up @@ -35,8 +35,11 @@
"repository": "git+https://github.com/niels-bosman/license-plate.git",
"keywords": [
"License plate",
"Formatter",
"Dutch"
"Kenteken",
"Formatting",
"Formatteren",
"Dutch",
"Nederlands"
],
"bugs": {
"url": "https://github.com/niels-bosman/license-plate/issues"
Expand Down
22 changes: 11 additions & 11 deletions src/forbidden-words.ts → src/data/letter-combinations.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/**
* All forbidden words in license plates.
*
* @type {RegExp[]}
* @type {string[]}
*/
const forbiddenWords: string[] = [
'GVD',
'KKK',
'KVT',
'LPF',
'NSB',
'PKK',
'PSV',
'TBS',
'SS',
'SD',
'GVD',
'KKK',
'KVT',
'LPF',
'NSB',
'PKK',
'PSV',
'TBS',
'SS',
'SD',
];

export default forbiddenWords;
File renamed without changes.
26 changes: 21 additions & 5 deletions src/license-plate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sidecodes from './sidecodes';
import forbiddenWords from './forbidden-words';
import sidecodes from './data/sidecodes';
import forbiddenWords from './data/letter-combinations';

export default class LicensePlate {
/**
Expand Down Expand Up @@ -84,13 +84,29 @@ export default class LicensePlate {
}

/**
* Checks whether the given license plate includes
* some of the forbidden letter combinations
* Checks whether the given license plate included some of the forbidden letter combinations.
*
* Starting from sidecode 7, political abbreviations from political parties were excluded,
* except VVD, they were excluded starting from sidecode 8.
*
* Sources:
* https://nl.wikipedia.org/wiki/Nederlands_kenteken
* https://www.rdw.nl/particulier/voertuigen/auto/de-kentekenplaat/cijfers-en-letters-op-de-kentekenplaat
*
* @return {boolean}
* @private
*/
private forbidden(): boolean {
return forbiddenWords.some((letterCombination: string) => this.licensePlate.includes(letterCombination));
let forbidden = forbiddenWords;

if (this.sidecode() >= 7) {
forbidden = [...forbidden, 'PVV', 'SGP'];
}

if (this.sidecode() >= 8) {
forbidden = [...forbidden, 'VVD'];
}

return forbidden.some((letterCombination: string) => this.licensePlate.includes(letterCombination));
}
}
34 changes: 34 additions & 0 deletions test/license-plate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,38 @@ describe('License Plate', () => {
expect(new LicensePlate('x-99-sss').valid()).toBeFalsy();
expect(new LicensePlate('x-99-sds').valid()).toBeFalsy();
});

it('Should not detect VVD in license plates that are under sidecode 7', () => {
expect(new LicensePlate('14-VVD-4').valid()).toBeTruthy();
});

it('Should detect political parties in license plates that have sidecode of 7 or higher', () => {
expect(new LicensePlate('99-PVV-9').valid()).toBeFalsy();
expect(new LicensePlate('9-PVV-99').valid()).toBeFalsy();
expect(new LicensePlate('PVV-99-X').valid()).toBeFalsy();
expect(new LicensePlate('X-99-PVV').valid()).toBeFalsy();

expect(new LicensePlate('99-SGP-9').valid()).toBeFalsy();
expect(new LicensePlate('9-SGP-99').valid()).toBeFalsy();
expect(new LicensePlate('SGP-99-X').valid()).toBeFalsy();
expect(new LicensePlate('X-99-SGP').valid()).toBeFalsy();
});

it('Should detect political party VVD tp be invalid starting from sidecode 8', () => {
expect(new LicensePlate('9-VVD-99').valid()).toBeFalsy();
expect(new LicensePlate('VVD-99-X').valid()).toBeFalsy();
expect(new LicensePlate('X-99-VVD').valid()).toBeFalsy();
});

it('Should not detect forbidden words that are not at the same spot', () => {
expect(new LicensePlate('99-ak-kk').valid()).toBeTruthy();
expect(new LicensePlate('99-ag-vd').valid()).toBeTruthy();
expect(new LicensePlate('99-ak-vt').valid()).toBeTruthy();
expect(new LicensePlate('99-al-pf').valid()).toBeTruthy();
expect(new LicensePlate('99-an-sb').valid()).toBeTruthy();
expect(new LicensePlate('99-ap-kk').valid()).toBeTruthy();
expect(new LicensePlate('99-ap-sv').valid()).toBeTruthy();
expect(new LicensePlate('99-as-sf').valid()).toBeTruthy();
expect(new LicensePlate('99-as-df').valid()).toBeTruthy();
});
});
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8526,4 +8526,4 @@
"string-width" "^4.2.0"
"which-module" "^2.0.0"
"y18n" "^4.0.0"
"yargs-parser" "^18.1.2"
"yargs-parser" "^18.1.2"

0 comments on commit 7ee080a

Please sign in to comment.