Skip to content

Add postal-code-formats to Test Data Management - #248

Open
vinceblock99 wants to merge 1 commit into
TheJambo:masterfrom
vinceblock99:add-postal-code-formats
Open

vinceblock99 wants to merge 1 commit into
TheJambo:masterfrom
vinceblock99:add-postal-code-formats

Conversation

@vinceblock99

Copy link
Copy Markdown
Contributor

Adds postal-code-formats under Test Data Management.

What it is. An open (MIT) dataset of postal code formats, validation regexes and 9,000 real sample codes for 31 countries — as JSON, as CSV, as one plain-text sample file per country, and as a zero-dependency npm package.

Why it belongs on this list. Two things testers keep needing and usually hand-roll:

  • Fixtures. data/samples/<ISO2>.txt holds real codes, one per line. They are useful precisely because they are not uniform — Sweden's carry a space, Poland's a hyphen, Portugal's four digits then three, and the US file includes the leading-zero codes that break any form storing a postal code as an integer.
  • A validation table you can trust. Most postal-code regexes in circulation descend from a Wikipedia scrape or from Google's unmaintained libaddressinput metadata, and nothing tells you when one has quietly gone wrong. Every pattern here is tested against every real sample code for its country in CI, so a pattern and the data cannot drift apart silently.

It also records two things a plain format table leaves out, both of which are bugs in real address forms: which countries have no postal code at all (Hong Kong is present with has_postal_code: false — a required postal field cannot be completed honestly there), and which sample codes are whole codes versus the published geographic half of one (Canada, the UK, Ireland and the Netherlands).

validate() returns undefined rather than false for a country outside the dataset, so an uncovered country cannot silently reject a correct address.

Disclosure: I maintain this package, and I am also the author of the FakeNamely entry already in this section. This is a separate artifact — a dataset and library rather than a hosted generator — and it stands on its own without that site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant