@imaginemyride/licence-plate
v0.1.0
Published
As-you-type formatting and validation for European and neighbouring-country licence plates
Maintainers
Readme
@imaginemyride/licence-plate
As-you-type formatting and structural validation for ordinary passenger-car licence plates from 27 countries.
npm install @imaginemyride/licence-plateThe package is ESM-only, supports Node.js 24 and newer, and uses ASCII Latin letters and digits for both input and output.
Formatting
Formatter is synchronous and stateless. Pass the complete current input value on every change.
import { Formatter } from "@imaginemyride/licence-plate";
const formatter = new Formatter("FR");
formatter.formatString("a"); // "A"
formatter.formatString("ab"); // "AB-"
formatter.formatString("ab1"); // "AB-1"
formatter.formatString("ab123"); // "AB-123-"
formatter.formatString("ab123cd"); // "AB-123-CD"Separators appear as soon as every format still compatible with the input agrees that a group has ended. Ambiguous compact values are not guessed. For example, a German district may contain one to three letters, so an explicit district separator is required while the value remains ambiguous:
const formatter = new Formatter("DE");
formatter.formatString("B"); // "B"
formatter.formatString("B-"); // "B-"
formatter.formatString("B-AB1234"); // "B-AB1234"Validation
Create validators asynchronously. The factory initialises the shared WebAssembly dependency when the selected country uses it.
import { Validator, init } from "@imaginemyride/licence-plate";
await init(); // Optional eager initialisation during application start-up.
const validator = await Validator.create("FR");
validator.validateString("ab123cd"); // true
validator.validateString("AB-123-CD"); // true
validator.validateString("AB--123-CD"); // falseinit() is idempotent, and concurrent calls share the same operation. validateString() is synchronous after the factory resolves.
Supported countries
| Code | Country | Ordinary format families |
| ---- | -------------- | ---------------------------------------------------- |
| NL | Netherlands | Dutch sidecodes 1-11 |
| DE | Germany | District, serial letters and digits |
| BE | Belgium | Current numeric-prefix format |
| GB | United Kingdom | Current Great Britain format |
| FR | France | Current SIV format |
| IT | Italy | Current national format |
| GR | Greece | Current three-letter format |
| BG | Bulgaria | Current regional formats |
| RS | Serbia | Current regional formats |
| TR | Turkey | Current province formats |
| NO | Norway | Current two-letter format |
| SE | Sweden | Current numeric and final-letter formats |
| ES | Spain | Current national format |
| AL | Albania | Current national format |
| XK | Kosovo | Current regional format |
| IR | Iran | Latin-token representation of current private format |
| IQ | Iraq | Latin representation of current unified format |
| LU | Luxembourg | Current two-letter format |
| CH | Switzerland | Current canton format |
| RO | Romania | Current county and Bucharest formats |
| HU | Hungary | Current and preceding national formats |
| AT | Austria | Current district formats |
| SI | Slovenia | Current regional format families |
| SK | Slovakia | Current national format |
| HR | Croatia | Current regional formats |
| UA | Ukraine | Current regional format |
| RU | Russia | Current two- and three-digit region formats |
The exported CountryCode type and countryCodes tuple contain this exact set. Runtime calls with another country throw RangeError.
Scope
Validation confirms that a value matches a supported ordinary passenger registration format. It does not prove that a registration was issued, is active, or belongs to a particular vehicle. Issued-series and reservation data require a national registry lookup.
Diplomatic, military, temporary, dealer, motorcycle, vanity and other special plates are outside the package's scope. Historical formats are included only where the supported family is explicitly listed above.
Countries that normally print Greek, Cyrillic, Arabic or Persian characters use documented ASCII visual aliases or tokens. The formatter does not accept native-script input or perform lossy phonetic transliteration.
Licence
MIT
