Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(isLicensePlate): Introduction with locales for Germany, Liechtenstein, Portugal and Albania #1495

Merged
merged 14 commits into from
Dec 17, 2020

Conversation

firlus
Copy link
Contributor

@firlus firlus commented Oct 21, 2020

A validator to check if a car license plate is valid or not.
Use cases might include applications where a user might has to register with his car and its license plate as an unique identifier.

Checklist

  • PR contains only changes related; no stray files, etc.
  • README updated (where applicable)
  • Tests written (where applicable)

@firlus
Copy link
Contributor Author

firlus commented Oct 21, 2020

This is related to #1490

@codecov
Copy link

codecov bot commented Oct 21, 2020

Codecov Report

Merging #1495 (37df91c) into master (738cf60) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master     #1495   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           99       100    +1     
  Lines         1778      1796   +18     
=========================================
+ Hits          1778      1796   +18     
Impacted Files Coverage Δ
src/index.js 100.00% <100.00%> (ø)
src/lib/isLicensePlate.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 738cf60...37df91c. Read the comment docs.

profnandaa
profnandaa previously approved these changes Oct 22, 2020
Copy link
Member

@profnandaa profnandaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for the most part. Will let an extra review from either @ezkemboi @tux-tn or @rubiin ; since this is a new validator.

const validFormat = regex.test(str);
// Rule 2: First section (1-3 letters until sepatator) must be a valid county code
const countyCodes = [
'AW', 'AIC', 'FDB', 'UL', 'ABG', 'SLN', 'AK', 'SAW', 'GA', 'KLZ', 'AÖ',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A regex to cover all these will be a little complex but can we try as opposed to listing manually?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do that!

@profnandaa
Copy link
Member

Also fix the coverage issue.

@firlus firlus changed the title feat(isLicensePlate): Introduction with locales for Germany, Liechtenstein and Albania feat(isLicensePlate): Introduction with locales for Germany, Liechtenstein, Portugal and Albania Oct 22, 2020
validator.js Outdated
var plateSections = str.split(/[ -]/g);
var validFormat = regex.test(str); // Rule 2: First section (1-3 letters until sepatator) must be a valid county code

var countyCodes = ['AW', 'AIC', 'FDB', 'UL', 'ABG', 'SLN', 'AK', 'SAW', 'GA', 'KLZ', 'AÖ', 'LF', 'AZ', 'AM', 'AS', 'BUL', 'ESB', 'NAB', 'SUL', 'WST', 'ABI', 'AZE', 'BTF', 'KÖT', 'ZE', 'AN', 'DKB', 'FEU', 'ROT', 'AB', 'ALZ', 'A', 'SMÜ', 'WER', 'AUR', 'NOR', 'DÜW', 'KG', 'BRK', 'HAB', 'KH', 'TÖL', 'WOR', 'BAD', 'BA', 'BAR', 'BER', 'EW', 'BZ', 'BIW', 'HY', 'KM', 'BT', 'EBS', 'KEM', 'MÜB', 'PEG', 'BGL', 'BGD', 'REI', 'HP', 'B', 'WIL', 'BKS', 'BC', 'BI', 'BIR', 'BO', 'WAT', 'FN', 'TT', 'ÜB', 'BN', 'BOR', 'AH', 'BOH', 'BOT', 'BRB', 'BS', 'FR', 'HB', 'BLK', 'HHM', 'NEB', 'NMB', 'WSF', 'ZZ', 'BB', 'LEO', 'BK', 'BÖ', 'HDL', 'OC', 'OK', 'WMS', 'WZL', 'BÜS', 'CW', 'CE', 'CHA', 'KÖZ', 'ROD', 'WÜM', 'C', 'CLP', 'CO', 'NEC', 'COC', 'ZEL', 'COE', 'LH', 'CB', 'CUX', 'DAH', 'LDS', 'KW', 'LC', 'LN', 'DA', 'DI', 'DEG', 'DEL', 'DE', 'RSL', 'DH', 'SY', 'DLG', 'DGF', 'LAN', 'HEI', 'MED', 'DON', 'NÖ', 'KIB', 'ROK', 'DO', 'DD', 'DU', 'DN', 'JÜL', 'MON', 'SLE', 'D', 'EBE', 'EIC', 'HIG', 'WBS', 'EI', 'BIT', 'PRÜ', 'EA', 'EE', 'FI', 'LIB', 'EMD', 'EM', 'EL', 'EN', 'WIT', 'PF', 'ED', 'EF', 'ER', 'ERH', 'HÖS', 'ERZ', 'ANA', 'ASZ', 'AU', 'MAB', 'MEK', 'STL', 'SZB', 'ZP', 'E', 'ES', 'NT', 'EU', 'FL', 'FO', 'FT', 'FF', 'F', 'FS', 'FDS', 'HCH', 'HOR', 'WOL', 'FRG', 'GRA', 'WOS', 'FRI', 'FD', 'FFB', 'FÜ', 'GAP', 'GE', 'G', 'GER', 'GI', 'GF', 'GS', 'BRL', 'CLZ', 'GTH', 'NOH', 'HGW', 'GRZ', 'ZR', 'GG', 'GP', 'GR', 'LÖB', 'NOL', 'NY', 'WSW', 'ZI', 'GÖ', 'DUD', 'HMÜ', 'OHA', 'GZ', 'KRU', 'GT', 'HA', 'HAL', 'HH', 'HM', 'HAM', 'HU', 'WL', 'HZ', 'HBS', 'QLB', 'WR', 'HVL', 'NAU', 'RN', 'HAS', 'EBN', 'GEO', 'HOH', 'HK', 'HD', 'HDH', 'HN', 'HS', 'ERK', 'GK', 'HE', 'HF', 'HER', 'WAN', 'HEF', 'ROF', 'RZ', 'HBN', 'HI', 'ALF', 'HSK', 'HG', 'USI', 'HO', 'NAI', 'REH', 'SAN', 'KÜN', 'ÖHR', 'HOL', 'HX', 'WAR', 'IK', 'ARN', 'IL', 'IN', 'J', 'JL', 'BRG', 'GNT', 'KL', 'KA', 'KS', 'HOG', 'WOH', 'KF', 'KEH', 'MAI', 'PAR', 'RID', 'ROL', 'KE', 'KI', 'KT', 'KLE', 'GEL', 'KO', 'KN', 'KR', 'KC', 'KU', 'KUS', 'KYF', 'ART', 'SDH', 'K', 'LDK', 'DIL', 'LD', 'LL', 'LA', 'MAL', 'VIB', 'LER', 'L', 'BNA', 'GHA', 'GRM', 'MTL', 'WUR', 'LEV', 'OP', 'LIF', 'STE', 'LM', 'WEL', 'LI', 'LIP', 'LB', 'VAI', 'LU', 'LUP', 'HGN', 'LBZ', 'LWL', 'PCH', 'STB', 'LÖ', 'HL', 'DAN', 'LG', 'MD', 'MKK', 'GN', 'SLÜ', 'MSP', 'TBB', 'MGH', 'MTK', 'MZ', 'BIN', 'MA', 'MSH', 'EIL', 'HET', 'ML', 'SGH', 'MR', 'BID', 'MYK', 'MY', 'MSE', 'AT', 'DM', 'MC', 'MST', 'MÜR', 'NZ', 'RM', 'WRN', 'MEI', 'GRH', 'RG', 'RIE', 'MM', 'MZG', 'ME', 'MB', 'MIL', 'OBB', 'MI', 'FG', 'BED', 'DL', 'FLÖ', 'HC', 'MW', 'RL', 'MOL', 'FRW', 'SEE', 'SRB', 'MK', 'MG', 'MÜ', 'WS', 'MH', 'M', 'AIB', 'MS', 'MOS', 'BCH', 'NU', 'ILL', 'NB', 'ND', 'SOB', 'NM', 'NMS', 'NK', 'NEA', 'SEF', 'UFF', 'NEW', 'VOH', 'NW', 'NR', 'NI', 'NF', 'NDH', 'TDO', 'DZ', 'EB', 'OZ', 'TG', 'TO', 'NWM', 'GDB', 'GVM', 'WIS', 'NOM', 'EIN', 'GAN', 'N', 'LAU', 'HEB', 'OA', 'GM', 'OB', 'OHV', 'OSL', 'CA', 'SFB', 'ERB', 'LOS', 'BSK', 'EH', 'FW', 'OF', 'OL', 'OE', 'OG', 'BH', 'KEL', 'LR', 'OS', 'BSB', 'MEL', 'WTL', 'AA', 'GD', 'OAL', 'FÜS', 'MOD', 'OHZ', 'OH', 'OPR', 'KY', 'NP', 'WK', 'PB', 'BÜR', 'PA', 'PE', 'PAF', 'PI', 'PS', 'PLÖ', 'P', 'PM', 'PR', 'RA', 'RV', 'RE', 'CAS', 'GLA', 'REG', 'VIT', 'R', 'H', 'SB', 'WN', 'RS', 'RD', 'ECK', 'RT', 'BM', 'SIM', 'GOA', 'NE', 'GV', 'EMS', 'DIZ', 'GOH', 'RP', 'SU', 'RÜD', 'SWA', 'GL', 'NES', 'KÖN', 'MET', 'RO', 'LRO', 'BÜZ', 'DBR', 'GÜ', 'ROS', 'TET', 'HRO', 'ROW', 'BRV', 'RH', 'HIP', 'PAN', 'EG', 'GRI', 'RW', 'SHK', 'EIS', 'SRO', 'SOK', 'LBS', 'PN', 'SCZ', 'SK', 'MER', 'MQ', 'QFT', 'SLF', 'RU', 'SLS', 'HOM', 'SZ', 'SLK', 'ASL', 'BBG', 'SBK', 'SFT', 'SHG', 'RI', 'SL', 'SM', 'MGN', 'SC', 'HR', 'FZ', 'MEG', 'ZIG', 'SAD', 'NEN', 'OVI', 'VS', 'SW', 'SN', 'SHA', 'CR', 'SE', 'SI', 'BLB', 'SIG', 'SO', 'LP', 'SG', 'SON', 'NH', 'SP', 'SPN', 'FOR', 'GUB', 'SPB', 'IGB', 'WND', 'STD', 'STA', 'IZ', 'ST', 'BF', 'TE', 'SDL', 'HV', 'OBG', 'OD', 'HST', 'SR', 'BOG', 'S', 'AC', 'SHL', 'PIR', 'DW', 'FTL', 'SEB', 'SÖM', 'SÜW', 'ZW', 'TF', 'TIR', 'TS', 'TR', 'SAB', 'TUT', 'TÜ', 'UM', 'ANG', 'PZ', 'SDT', 'TP', 'UE', 'UN', 'LÜN', 'UH', 'LSZ', 'MHL', 'MN', 'VEC', 'VER', 'VIE', 'KK', 'VB', 'V', 'AE', 'OVL', 'PL', 'RC', 'VG', 'ANK', 'GW', 'OVP', 'PW', 'SBG', 'UEM', 'UER', 'WLG', 'VR', 'GMN', 'NVP', 'RDG', 'RÜG', 'DAU', 'VK', 'KB', 'FKB', 'WA', 'WT', 'WAF', 'BE', 'WAK', 'SLZ', 'WEN', 'WM', 'SOG', 'WE', 'AP', 'APD', 'WUG', 'GUN', 'ESW', 'WIZ', 'WES', 'DIN', 'MO', 'BRA', 'WW', 'FB', 'BÜD', 'WZ', 'WI', 'WHV', 'HWI', 'WB', 'GHC', 'JE', 'WTM', 'WF', 'WOB', 'WO', 'WUN', 'MAK', 'SEL', 'W', 'WÜ', 'OCH', 'BL', 'Z', 'GC', 'HOT', 'WDA'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can list this alphabetically, and maybe line-by-line for better readability.

import assertString from './util/assertString';

const validators = {
'de-DE': str => /^((AW|UL|AK|GA|AÖ|LF|AZ|AM|AS|ZE|AN|AB|A|KG|KH|BA|EW|BZ|HY|KM|BT|HP|B|BC|BI|BO|FN|TT|ÜB|BN|AH|BS|FR|HB|ZZ|BB|BK|BÖ|OC|OK|CW|CE|C|CO|LH|CB|KW|LC|LN|DA|DI|DE|DH|SY|NÖ|DO|DD|DU|DN|D|EI|EA|EE|FI|EM|EL|EN|PF|ED|EF|ER|AU|ZP|E|ES|NT|EU|FL|FO|FT|FF|F|FS|FD|FÜ|GE|G|GI|GF|GS|ZR|GG|GP|GR|NY|ZI|GÖ|GZ|GT|HA|HH|HM|HU|WL|HZ|WR|RN|HK|HD|HN|HS|GK|HE|HF|RZ|HI|HG|HO|HX|IK|IL|IN|J|JL|KL|KA|KS|KF|KE|KI|KT|KO|KN|KR|KC|KU|K|LD|LL|LA|L|OP|LM|LI|LB|LU|LÖ|HL|LG|MD|GN|MZ|MA|ML|MR|MY|AT|DM|MC|NZ|RM|RG|MM|ME|MB|MI|FG|DL|HC|MW|RL|MK|MG|MÜ|WS|MH|M|MS|NU|NB|ND|NM|NK|NW|NR|NI|NF|DZ|EB|OZ|TG|TO|N|OA|GM|OB|CA|EH|FW|OF|OL|OE|OG|BH|LR|OS|AA|GD|OH|KY|NP|WK|PB|PA|PE|PI|PS|P|PM|PR|RA|RV|RE|R|H|SB|WN|RS|RD|RT|BM|NE|GV|RP|SU|GL|RO|GÜ|RH|EG|RW|PN|SK|MQ|RU|SZ|RI|SL|SM|SC|HR|FZ|VS|SW|SN|CR|SE|SI|SO|LP|SG|NH|SP|IZ|ST|BF|TE|HV|OD|SR|S|AC|DW|ZW|TF|TS|TR|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Ö|MOL|FRW|SEE|SRB|AIB|MOS|BCH|ILL|SOB|NMS|NEA|SEF|UFF|NEW|VOH|NDH|TDO|NWM|GDB|GVM|WIS|NOM|EIN|GAN|LAU|HEB|OHV|OSL|SFB|ERB|LOS|BSK|KEL|BSB|MEL|WTL|OAL|FÜS|MOD|OHZ|OPR|BÜR|PAF|PLÖ|CAS|GLA|REG|VIT|ECK|SIM|GOA|EMS|DIZ|GOH|RÜD|SWA|NES|KÖN|MET|LRO|BÜZ|DBR|ROS|TET|HRO|ROW|BRV|HIP|PAN|GRI|SHK|EIS|SRO|SOK|LBS|SCZ|MER|QFT|SLF|SLS|HOM|SLK|ASL|BBG|SBK|SFT|SHG|MGN|MEG|ZIG|SAD|NEN|OVI|SHA|BLB|SIG|SON|SPN|FOR|GUB|SPB|IGB|WND|STD|STA|SDL|OBG|HST|BOG|SHL|PIR|FTL|SEB|SÖM|SÜW|TIR|SAB|TUT|ANG|SDT|LÜN|LSZ|MHL|VEC|VER|VIE|OVL|ANK|OVP|SBG|UEM|UER|WLG|GMN|NVP|RDG|RÜG|DAU|FKB|WAF|WAK|SLZ|WEN|SOG|APD|WUG|GUN|ESW|WIZ|WES|DIN|BRA|BÜD|WHV|HWI|GHC|WTM|WOB|WUN|MAK|SEL|OCH|HOT|WDA)[- ]?(([A-Z][- ]?\d{1,4})|([A-Z]{2}[- ]?\d{1,3})))[- ]?(E|H)?$/.test(str),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also put the items alphabetically; if we find ways of simplifying the regex further later, it's okay -- but we can have those for now.

@profnandaa
Copy link
Member

@tux-tn @ezkemboi -- pls have a look.

@profnandaa
Copy link
Member

@firlus -- sorry for the delay on this one. Could you fix the merge conflict and we should land this soonest.

@profnandaa profnandaa added the 🧹 needs-update For PRs that need to be updated before landing label Nov 29, 2020
@firlus
Copy link
Contributor Author

firlus commented Dec 16, 2020

@profnandaa sorry for the late response, I will try to solve the merge conflict and fix the coverage issue so that this becomes mergable

@firlus
Copy link
Contributor Author

firlus commented Dec 16, 2020

I am unsure whether I should also include the auto-generated files...

@profnandaa
Copy link
Member

Thanks, looks good now. Just fix the conflict and we should be good to go.

@firlus
Copy link
Contributor Author

firlus commented Dec 17, 2020

Here we go @profnandaa

@profnandaa profnandaa merged commit edcd161 into validatorjs:master Dec 17, 2020
profnandaa pushed a commit that referenced this pull request Feb 15, 2021
* chore: prevent git from ignoring src/index.js file

* chore: remove unused exclusion from nyc config

* chore: replace travis-ci with github actions

* chore: fix issue with github workflow config

* chore: fix condition for coverage generation and sending

* chore: treat node version as int

* docs: replace travis with github actions badge

* chore: add npm publish github action

* chore: remove auto-generated files

* chore: improve github actions styles

* chore: use correct repo url to prevent unecessary redirect

* chore: lint package.json file

* chore: add new line at end of file

* feat(isMobilePhone): update de-CH, add fr-CH, it-CH locales (#1554)

* fix(isMobilePhone): update de-CH locale (#1549)
feat(isMobilePhone): add fr-CH locale (#1549)
feat(isMobilePhone): add it-CH locale (#1549)

* fix(isMobilePhone): update de-CH, fr-CH and it-CH locale in validator.min.js(#1549)

* fix(isMobilePhone): update fr-CH and it-CH locale aliases (#1549)

Co-authored-by: Ashutosh Kumar <[email protected]>

* feat(isLicensePlate): new validator 🎉 (#1495)

* Added isLicensePlate check with german locale

* de-LI (Liechtenstein) validator

* Added albanian number plates

* reversed changes in index.js

* reversed changes in index.js

* Refactored de-DE into one big regex, expanded tests fot de-DE

* added pt-PT locale

* Fixed coverage problem

* feat(isLicensePlate): clean build

* coverage is now 100%

* Update README.md

* Update README.md

* fix(isTaxID): fix el-GR locale when checksum is 10 (#1529)

Add correct tax identifier to demonstrate issue and fix.

Thanks to: Panos Papadopoulos

* feat(isMobileNumber): add support new telco numbers for VN locale (#1575)

* Support new VN mobile phone 087 (https://didong.itelecom.vn/)

* Add test for new telco number

Co-authored-by: Kyle Dinh <[email protected]>

* chore: set a fixed ubuntu version instead of relying on latest

Co-authored-by: Ashutosh Kumar <[email protected]>
Co-authored-by: Ashutosh Kumar <[email protected]>
Co-authored-by: Michael Firlus <[email protected]>
Co-authored-by: Diomidis Spinellis <[email protected]>
Co-authored-by: Kyle Dinh <[email protected]>
Co-authored-by: Kyle Dinh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-more-review 🧹 needs-update For PRs that need to be updated before landing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants