worldwide 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +1 -1
- data/.security/deepsec/worldwide.md +89 -0
- data/.security/deepsec.yml +20 -0
- data/AGENTS.md +58 -2
- data/CHANGELOG.md +11 -0
- data/Gemfile.lock +1 -1
- data/data/regions/CA.yml +21 -17
- data/data/regions/CH.yml +1 -1
- data/data/regions/EE.yml +1 -1
- data/data/regions/LI.yml +1 -1
- data/data/regions/SK.yml +1 -1
- data/lib/worldwide/regions_loader.rb +12 -4
- data/lib/worldwide/version.rb +1 -1
- data/lib/worldwide/zip.rb +5 -4
- data/worldwide.gemspec +1 -1
- metadata +3 -2
- data/CLAUDE.md +0 -158
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a9425539f53b1dc3b36b3c7c60aebff3f6f95dcd7fe04f2934bf9ab0effcde9b
|
|
4
|
+
data.tar.gz: 51c4fc57650a18d10982698fa37e919e30833952dabfb34eb53ab56d316b6c75
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8b36e4a211b05936d9c0f58d6f33d1f957da552dfbcbc6a20c35488ad2490cc74fd007ec0e43add3ffcfd603d6741742249f4545e8b9d818a0fb6d608c0fad7f
|
|
7
|
+
data.tar.gz: 675fb75c3fe7771c5195dc534bbe9b83f989ebff93b7827c2d72a645d1eb347f05453a42ed5add5fdc4f868f809d43eb11190450c568a49cd61cc033d5c556c4
|
data/.github/workflows/ci.yml
CHANGED
|
@@ -22,7 +22,7 @@ jobs:
|
|
|
22
22
|
- name: Check out code
|
|
23
23
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
24
24
|
- name: Set up Ruby ${{ matrix.ruby }}
|
|
25
|
-
uses: ruby/setup-ruby@
|
|
25
|
+
uses: ruby/setup-ruby@be3c7df29b3349ec6bcfc6b4792f1cf9f5237d18 # v1.343.0
|
|
26
26
|
with:
|
|
27
27
|
ruby-version: ${{ matrix.ruby }}
|
|
28
28
|
bundler-cache: true
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# worldwide
|
|
2
|
+
|
|
3
|
+
## What this codebase does
|
|
4
|
+
|
|
5
|
+
`worldwide` is a public Ruby gem (Ruby 3.2+) for localization and mailing-address handling. It also
|
|
6
|
+
ships a small TypeScript package in `lang/typescript/` (`@shopify/worldwide`). The gem has no web
|
|
7
|
+
server, no database, no network client at runtime and no authentication. It is a library that a host
|
|
8
|
+
application calls with strings that its own users typed.
|
|
9
|
+
|
|
10
|
+
- `lib/worldwide/`: regions and subdivisions (`regions.rb`, `region.rb`, `regions_loader.rb`), postal
|
|
11
|
+
codes (`zip.rb`), address checks (`address.rb`, `address_validator.rb`), phone numbers (`phone.rb`),
|
|
12
|
+
locales and plural rules (`locale.rb`, `locales.rb`, `plurals.rb`, `cldr.rb`), currencies, numbers,
|
|
13
|
+
dates and time zones, and the `ruby-i18n` setup (`config.rb`, `ruby_i18n_config.rb`).
|
|
14
|
+
- `lang/typescript/src/`: splits and joins extended address fields. `lang/typescript/rollup-plugin-regions-yaml/`
|
|
15
|
+
turns the region YAML files into one bundle at build time.
|
|
16
|
+
- `rake/`: maintainer tasks that pull Unicode CLDR data and postal-code data into `data/`. They run on
|
|
17
|
+
a maintainer's machine, never inside a host application.
|
|
18
|
+
- `.github/workflows/`: CI, a changeset-based npm release, and a CLA check.
|
|
19
|
+
|
|
20
|
+
## Auth shape
|
|
21
|
+
|
|
22
|
+
There is no authentication or authorization in this repository, so do not report a missing auth check.
|
|
23
|
+
The trust boundaries are different:
|
|
24
|
+
|
|
25
|
+
- **Caller input**: every public method that takes a country code, province code, zip, phone number,
|
|
26
|
+
locale or free-text address field treats it as untrusted text. Entry points are `Worldwide.region`,
|
|
27
|
+
`Worldwide::Regions#region`, `Worldwide::Zip.normalize`, `Worldwide::Zip.find_country`,
|
|
28
|
+
`Worldwide::AddressValidator.errors`, `Worldwide::Phone.new`, `Worldwide::Locale#name` and the
|
|
29
|
+
TypeScript `splitAddress1`, `splitAddress2`, `concatenateAddress1` and `concatenateAddress2`.
|
|
30
|
+
- **Repository data**: files under `data/` are trusted input, generated by the rake tasks and reviewed
|
|
31
|
+
in PRs. Loading code must read them from the fixed roots in `Worldwide::Paths`.
|
|
32
|
+
- **CI identity**: `npm-release.yml` holds `id-token: write`, `contents: write` and a repository token.
|
|
33
|
+
|
|
34
|
+
## Threat model
|
|
35
|
+
|
|
36
|
+
The most likely harm is to a host application that passes untrusted text into this library. Rank by impact:
|
|
37
|
+
|
|
38
|
+
1. **Code or file access driven by input**: any `eval`, `send`, `constantize`, `Regexp.new`, file read
|
|
39
|
+
or YAML load whose argument can contain caller input. Values that name a file or a method must be
|
|
40
|
+
checked against a known list first (`Worldwide::Locales`, `Worldwide::Regions`).
|
|
41
|
+
2. **Denial of service**: a regular expression, loop or normalization step whose cost grows faster than
|
|
42
|
+
linearly with the length of a caller string. Postal-code regexes come from region data and run on user
|
|
43
|
+
input in `Region#passes_country_zip_regexp?`, `Zip.normalize` and the TypeScript regex split.
|
|
44
|
+
3. **Wrong validation result**: an address or phone number that is accepted or rejected wrongly
|
|
45
|
+
because of Unicode handling (full-width digits, zero-width characters, `RESERVED_DELIMITER`).
|
|
46
|
+
4. **Supply chain**: a workflow, dependency or pulled data file that changes what ships to RubyGems or npm.
|
|
47
|
+
5. **Unsafe deserialization**: `YAML.load_file` or `Marshal` on data that is not under `data/`.
|
|
48
|
+
|
|
49
|
+
## Project-specific patterns to flag
|
|
50
|
+
|
|
51
|
+
- **Input in a lookup key**: `Regions#region` upcases the code and uses it as a hash key. Flag new
|
|
52
|
+
lookups that build a file path, a constant name or a method name from `code:`, `cldr:` or `name:`.
|
|
53
|
+
- **YAML loading**: the code reads YAML from the roots in `Worldwide::Paths`, mostly with
|
|
54
|
+
`YAML.safe_load_file`. Flag `YAML.load`, `unsafe_load` or `load_file` calls added for data that could
|
|
55
|
+
come from outside `data/` (`regions_loader.rb`, `currency.rb`, `locales.rb`).
|
|
56
|
+
- **Dynamic code loading**: `Plurals.load_locale_rule` reads a rules file by locale code and evaluates
|
|
57
|
+
it. Flag any other `eval`, `instance_eval`, `class_eval` or `send` with a computed name, and any change
|
|
58
|
+
that lets the locale string reach that path without `Worldwide::Cldr.fallbacks`.
|
|
59
|
+
- **Regex built from data**: `Zip.regex_for` and `Region#passes_country_zip_regexp?` call `Regexp.new`
|
|
60
|
+
on `zip_regex` or `partial_zip_regex`. Flag a new regex with nested quantifiers or alternation of
|
|
61
|
+
overlapping patterns, and any regex built by interpolating caller text without `Regexp.escape`.
|
|
62
|
+
- **Phone parsing**: `Phone#parse_number` and `split_extension` pass caller text to `Phonelib`. Flag
|
|
63
|
+
changes that skip `transliterate` or accept a number of unbounded length.
|
|
64
|
+
- **I18n interpolation and exceptions**: `missing_interpolation_argument_handler` and
|
|
65
|
+
`I18nExceptionHandler` decide what a missing key renders. Flag a handler that echoes caller text into
|
|
66
|
+
output that a host may treat as HTML, or that raises with caller text in the message.
|
|
67
|
+
- **Workflows**: flag any new `pull_request_target`, an action pinned to a tag instead of a commit SHA,
|
|
68
|
+
`${{ github.event.* }}` used inside a `run:` script, or a secret passed to a step that runs PR code.
|
|
69
|
+
- **Rake pullers**: `Postal::Puller#download` and `Cldr::Puller` fetch remote data. Flag URLs built
|
|
70
|
+
from environment variables or arguments without a fixed host, and files written outside `data/` or
|
|
71
|
+
`rake/postal/vendor/`.
|
|
72
|
+
|
|
73
|
+
## Known false-positives
|
|
74
|
+
|
|
75
|
+
- `data/**`: country, region and CLDR reference data, and the generated `plurals.rb` rule files that
|
|
76
|
+
`Plurals.load_locale_rule` reads. Strings that look like secrets, tokens, emails or regexes here are
|
|
77
|
+
postal formats, names and sample values. The scan leaves this folder out.
|
|
78
|
+
- `test/**` and `*.test.ts`: fixtures use synthetic addresses and phone numbers, and call internals with
|
|
79
|
+
`send` on purpose.
|
|
80
|
+
- `Region#send(:private_method)` and `Zip` calls to `country.send(:valid_normalized_zip?, ...)`: the
|
|
81
|
+
receiver is always a `Region` and the method name is a literal in the source.
|
|
82
|
+
- `Regexp.new` over `zip_regex` or `partial_zip_regex`, and `new RegExp` in the TypeScript
|
|
83
|
+
`getAddress1Regex`, when the pattern comes from the region YAML files and not from the caller.
|
|
84
|
+
- `yaml.load` in `rollup-plugin-regions-yaml/index.ts`: it parses the repository's own region files at
|
|
85
|
+
build time, not caller input.
|
|
86
|
+
- `.github/workflows/cla.yml`: it runs on `pull_request_target` and uses a first-party action pinned to
|
|
87
|
+
a tag. It checks out no PR code and runs no PR-controlled script, so the trigger alone is not a finding.
|
|
88
|
+
- `rake/**` and `bin/**`: maintainer tooling that a person runs by hand. `worldwide.gemspec` leaves
|
|
89
|
+
`rake/`, `test/` and `lang/typescript/` out of the packaged gem.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# deepsec security review of this repository: devx deepsec run (see devx deepsec help).
|
|
2
|
+
# Context for the model: .security/deepsec/<project>.md.
|
|
3
|
+
projects:
|
|
4
|
+
worldwide:
|
|
5
|
+
# The gem's own code is `lib/`, the TypeScript package in `lang/typescript/src/` and its build
|
|
6
|
+
# plugin, the release workflows and the maintainer rake tasks. The region, CLDR and locale
|
|
7
|
+
# files under `data/` are reference data, and the test suites hold synthetic fixtures, so neither is reviewed.
|
|
8
|
+
priority:
|
|
9
|
+
- lib/worldwide/
|
|
10
|
+
- lang/typescript/src/
|
|
11
|
+
- lang/typescript/rollup-plugin-regions-yaml/
|
|
12
|
+
- .github/workflows/
|
|
13
|
+
- rake/
|
|
14
|
+
ignore:
|
|
15
|
+
- data/**
|
|
16
|
+
- test/**
|
|
17
|
+
- "**/*.test.ts"
|
|
18
|
+
- lang/typescript/pnpm-lock.yaml
|
|
19
|
+
- CHANGELOG.md
|
|
20
|
+
- lang/typescript/CHANGELOG.md
|
data/AGENTS.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Contributing to Worldwide
|
|
2
2
|
|
|
3
|
-
Worldwide is a public Ruby gem for localization and address handling. It also contains the public `@shopify/worldwide` TypeScript package.
|
|
3
|
+
Worldwide is a public Ruby gem for localization and address handling: region and country data, address validation, normalization and formatting, postal codes, currencies, numbers, names, lists, dates and time zones, and phone numbers. It also contains the public `@shopify/worldwide` TypeScript package, which splits and joins extended address fields.
|
|
4
4
|
|
|
5
5
|
## Keep contributions public
|
|
6
6
|
|
|
@@ -16,8 +16,31 @@ Worldwide is a public Ruby gem for localization and address handling. It also co
|
|
|
16
16
|
| Region labels and translations | `data/regions/<CC>/`, `data/cldr/`, `data/other/` |
|
|
17
17
|
| CLDR corrections | [`rake/cldr/patch.rb`](rake/cldr/patch.rb), [`rake/tasks/cldr.rake`](rake/tasks/cldr.rake) |
|
|
18
18
|
| Postal prefix imports | [`rake/postal/README.md`](rake/postal/README.md) |
|
|
19
|
+
| Currencies, numbers, names, lists, times, punctuation | `lib/worldwide/currency.rb`, `numbers.rb`, `names.rb`, `lists.rb`, `time_formatter.rb`, `punctuation.rb` |
|
|
20
|
+
| Phone numbers | `lib/worldwide/phone.rb`, which wraps `phonelib` |
|
|
21
|
+
| Locale and `I18n` setup | `lib/worldwide/locale.rb`, `locales.rb`, `config.rb`, `ruby_i18n_config.rb` |
|
|
19
22
|
| TypeScript address code | [`lang/typescript/`](lang/typescript/) |
|
|
20
23
|
|
|
24
|
+
## How the gem is organized
|
|
25
|
+
|
|
26
|
+
The gem is data-driven. Its data lives in `data/`:
|
|
27
|
+
|
|
28
|
+
- `data/regions/`: one YAML file per country or territory, with its zones, address formats and postal code rules.
|
|
29
|
+
- `data/cldr/`: Unicode CLDR data, generated by the CLDR rake tasks (see [Update CLDR data](#update-cldr-data)).
|
|
30
|
+
- `data/world.yml`: the region hierarchy (continents and subregions); `data/country_codes.yml`: alpha-3 and numeric codes.
|
|
31
|
+
- `data/extant_outcodes.yml`: the GB outcodes that exist, which `Zip.outcode` uses to guess the outcode of a partial postcode.
|
|
32
|
+
|
|
33
|
+
The `Worldwide` module is the entry point: `Worldwide.region(code:)` (or `cldr:` or `name:`), `Worldwide.address(...)`, `Worldwide.currency(code:)`, `Worldwide.locale(code:)`, and `Worldwide.numbers`, `names` and `lists`. `Region` covers countries, territories, provinces and states, and validates at both the country and the zone level. `Address` validates, normalizes and formats an address, with `AddressValidator`. `Zip` normalizes and validates postal codes.
|
|
34
|
+
|
|
35
|
+
The runtime dependencies are `activesupport`, `i18n` and `phonelib`. `ruby-cldr` is only for the CLDR rake tasks.
|
|
36
|
+
|
|
37
|
+
## Code conventions
|
|
38
|
+
|
|
39
|
+
- Start every Ruby file with `# frozen_string_literal: true`. Style follows `rubocop-shopify`.
|
|
40
|
+
- Load YAML data lazily, and cache it in an instance variable.
|
|
41
|
+
- Accept a `locale:` argument that defaults to `I18n.locale`.
|
|
42
|
+
- Put tests under `test/worldwide/`, mirroring `lib/worldwide/`. They use Minitest with `mocha` for mocks and `minitest-focus`.
|
|
43
|
+
|
|
21
44
|
## Make the change easy to review
|
|
22
45
|
|
|
23
46
|
- Keep the change to one behavior or one related group of countries. Split unrelated cleanup and dependency updates into separate PRs.
|
|
@@ -28,17 +51,24 @@ Worldwide is a public Ruby gem for localization and address handling. It also co
|
|
|
28
51
|
|
|
29
52
|
## Run checks
|
|
30
53
|
|
|
54
|
+
### Ruby
|
|
55
|
+
|
|
31
56
|
Use `.ruby-version` for local setup. Check [`worldwide.gemspec`](worldwide.gemspec) for the supported Ruby minimum and [Ruby CI](.github/workflows/ci.yml) for the test matrix. Do not assume the oldest Ruby in CI is the supported minimum.
|
|
32
57
|
|
|
33
58
|
```sh
|
|
34
59
|
bundle install
|
|
35
60
|
bundle exec ruby -Itest test/worldwide/regions/pa_test.rb # example focused test
|
|
61
|
+
bundle exec ruby -Itest test/worldwide/region_test.rb -n test_method_name # one test
|
|
36
62
|
bin/test
|
|
37
|
-
bin/style
|
|
63
|
+
bin/style # bundle exec rubocop; pass -a to autocorrect
|
|
38
64
|
```
|
|
39
65
|
|
|
66
|
+
`bundle exec rake` runs the tests and RuboCop together. `bin/console` opens a console with the gem loaded.
|
|
67
|
+
|
|
40
68
|
Run `bin/test-cldr-rake-tasks` from a clean checkout to check that the full CLDR pipeline reproduces the committed data. The script downloads data and reports unexpected changes to the working tree.
|
|
41
69
|
|
|
70
|
+
### TypeScript
|
|
71
|
+
|
|
42
72
|
For changes that affect TypeScript, use the Node and pnpm versions in [TypeScript CI](.github/workflows/ci-typescript.yml):
|
|
43
73
|
|
|
44
74
|
```sh
|
|
@@ -50,6 +80,32 @@ pnpm test
|
|
|
50
80
|
pnpm build
|
|
51
81
|
```
|
|
52
82
|
|
|
83
|
+
`pnpm format` formats the package, and `pnpm test:watch` reruns the tests on change.
|
|
84
|
+
|
|
85
|
+
## Update CLDR data
|
|
86
|
+
|
|
87
|
+
Do not edit `data/cldr/` by hand. To import a new CLDR release, run these tasks in order:
|
|
88
|
+
|
|
89
|
+
1. `bundle exec rake cldr:data:clean` removes the existing CLDR files.
|
|
90
|
+
2. `bundle exec rake cldr:data:import` downloads CLDR (the version in `data/cldr.yml`) into `vendor/` and converts it to YAML. It takes several minutes. `VERSION=42` picks another release, and `COMPONENTS=Units,Calendars` imports only some components.
|
|
91
|
+
3. `bundle exec rake cldr:data:patch` applies the fixes in [`rake/cldr/patch.rb`](rake/cldr/patch.rb) and writes `data/cldr/`.
|
|
92
|
+
4. `bundle exec rake cldr:data:generate` generates locale data such as date and time formats and missing plurals.
|
|
93
|
+
5. `bundle exec rake cldr:data:generate_paths` writes the file indices.
|
|
94
|
+
|
|
95
|
+
### Patch a CLDR value
|
|
96
|
+
|
|
97
|
+
To fix a CLDR value, add a `patch_subdivisions` or `patch_file` call to `rake/cldr/patch.rb`, run `bundle exec rake cldr:data:patch`, and commit the patch with the data it changes. For example:
|
|
98
|
+
|
|
99
|
+
```ruby
|
|
100
|
+
# Remove ² markers from Spanish subdivisions in Portuguese
|
|
101
|
+
patch_subdivisions(:pt, [
|
|
102
|
+
[:esna, "Navarra²", "Navarra"],
|
|
103
|
+
[:esri, "La Rioja²", "La Rioja"],
|
|
104
|
+
])
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Report the issue upstream at https://unicode-org.atlassian.net when it applies to CLDR itself. `vendor/` is ignored by git; do not commit it.
|
|
108
|
+
|
|
53
109
|
## Open the PR
|
|
54
110
|
|
|
55
111
|
- Use the [PR template](.github/pull_request_template.md). State the problem, why you chose this fix, which behavior changes, and what you tested. Include public sources, a small reproduction, or a before-and-after example when useful.
|
data/CHANGELOG.md
CHANGED
|
@@ -29,6 +29,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
|
29
29
|
|
|
30
30
|
---
|
|
31
31
|
|
|
32
|
+
## [3.1.0] - 2026-11-27
|
|
33
|
+
|
|
34
|
+
- Correct the time zones for Nunavut postal codes in Kitikmeot, Kivalliq, Resolute and Arctic Bay. [#685](https://github.com/Shopify/worldwide/pull/685)
|
|
35
|
+
- `Zip.normalize` keeps the hyphen of Moldova (MD) postal codes. `MD-2025`, `MD2025`, `MD 2025`, `md-2025`, `2025MD` and `2025-MD` all become `MD-2025`; before, every form except `2025MD` became `MD2025`. A bare `2025` stays `2025`. [#694](https://github.com/Shopify/worldwide/pull/694)
|
|
36
|
+
- Switzerland's and Liechtenstein's `tax_rate` is 0.081, their standard VAT rate since 2024-01-01; both were 0.077. [#723](https://github.com/Shopify/worldwide/pull/723)
|
|
37
|
+
- Estonia's `tax_rate` is 0.24 (standard VAT rate since 2025-07-01) and Slovakia's 0.23 (since 2025-01-01); both were 0.2. [#710](https://github.com/Shopify/worldwide/pull/710)
|
|
38
|
+
- Strings, arrays and hashes that regions read from `data/regions/*.yml` and `data/country_codes.yml` are now frozen, and equal strings are shared between regions. This also applies to what `Zip.normalize` returns for single-postcode countries and to the codes `Address#normalize` sets. `dup` a value before modifying it in place. [#716](https://github.com/Shopify/worldwide/pull/716)
|
|
39
|
+
- Loading the regions takes about 35% less time and allocates about 330,000 fewer objects. [#715](https://github.com/Shopify/worldwide/pull/715)
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
32
43
|
## [3.0.0] - 2026-11-19
|
|
33
44
|
|
|
34
45
|
- **Breaking:** Greenland, Kyiv and Yangon now use `America/Nuuk`, `Europe/Kyiv` and `Asia/Yangon`, as in Rails 8.1. This applies to the `GL` region's `timezones`, `DeprecatedTimeZoneMapper.to_rails`, the time zone labels and `Worldwide::TimeZone.all`. To match a saved `America/Godthab`, `Europe/Kiev` or `Asia/Rangoon`, pass it through `DeprecatedTimeZoneMapper.to_supported` first. Greenland's label now shows `(GMT-02:00)`. [#687](https://github.com/Shopify/worldwide/pull/687)
|
data/Gemfile.lock
CHANGED
data/data/regions/CA.yml
CHANGED
|
@@ -437,6 +437,8 @@ timezones:
|
|
|
437
437
|
- G0G 2P
|
|
438
438
|
- G0G 2R
|
|
439
439
|
- G0G 2W
|
|
440
|
+
America/Cambridge_Bay:
|
|
441
|
+
- X0B
|
|
440
442
|
America/Edmonton:
|
|
441
443
|
- S0M 0A4
|
|
442
444
|
- S0M 0A8
|
|
@@ -491,7 +493,6 @@ timezones:
|
|
|
491
493
|
- V0E 2L
|
|
492
494
|
- V1A
|
|
493
495
|
- V1C
|
|
494
|
-
- X0B
|
|
495
496
|
- X0E
|
|
496
497
|
- X0G
|
|
497
498
|
- X1
|
|
@@ -509,6 +510,22 @@ timezones:
|
|
|
509
510
|
- G0C 0E9
|
|
510
511
|
- G0C 2R
|
|
511
512
|
- G4T
|
|
513
|
+
America/Iqaluit:
|
|
514
|
+
- X0A 0A0
|
|
515
|
+
- X0A 0B3
|
|
516
|
+
America/Rankin_Inlet:
|
|
517
|
+
- X0C 0A0
|
|
518
|
+
- X0C 0A1
|
|
519
|
+
- X0C 0A3
|
|
520
|
+
- X0C 0A4
|
|
521
|
+
- X0C 0A5
|
|
522
|
+
- X0C 0A6
|
|
523
|
+
- X0C 0A7
|
|
524
|
+
- X0C 0B
|
|
525
|
+
- X0C 0E
|
|
526
|
+
- X0C 0G
|
|
527
|
+
- X0C 0H
|
|
528
|
+
- X0C 0J
|
|
512
529
|
America/Regina:
|
|
513
530
|
- S0A
|
|
514
531
|
- S0C
|
|
@@ -614,6 +631,9 @@ timezones:
|
|
|
614
631
|
- S9A
|
|
615
632
|
- S9H
|
|
616
633
|
- S9X
|
|
634
|
+
America/Resolute:
|
|
635
|
+
- X0A 0A2
|
|
636
|
+
- X0A 0V
|
|
617
637
|
America/St_Johns:
|
|
618
638
|
- A0A
|
|
619
639
|
- A0B
|
|
@@ -1092,19 +1112,3 @@ timezones:
|
|
|
1092
1112
|
- S0P 0A1
|
|
1093
1113
|
- S0P 0A2
|
|
1094
1114
|
- S0P 0B
|
|
1095
|
-
- X0A 0A0
|
|
1096
|
-
- X0A 0A2
|
|
1097
|
-
- X0A 0B3
|
|
1098
|
-
- X0A 0V
|
|
1099
|
-
- X0C 0A0
|
|
1100
|
-
- X0C 0A1
|
|
1101
|
-
- X0C 0A3
|
|
1102
|
-
- X0C 0A4
|
|
1103
|
-
- X0C 0A5
|
|
1104
|
-
- X0C 0A6
|
|
1105
|
-
- X0C 0A7
|
|
1106
|
-
- X0C 0B
|
|
1107
|
-
- X0C 0E
|
|
1108
|
-
- X0C 0G
|
|
1109
|
-
- X0C 0H
|
|
1110
|
-
- X0C 0J
|
data/data/regions/CH.yml
CHANGED
data/data/regions/EE.yml
CHANGED
data/data/regions/LI.yml
CHANGED
data/data/regions/SK.yml
CHANGED
|
@@ -11,11 +11,13 @@ module Worldwide
|
|
|
11
11
|
def load_regions
|
|
12
12
|
@regions_by_cldr_code = {}
|
|
13
13
|
@regions_by_iso_code = {}
|
|
14
|
+
@regions_by_hierarchy_code = {}
|
|
14
15
|
|
|
15
16
|
# Load country/region definitions out of the data/regions/??.yml files
|
|
16
17
|
@regions = Dir["#{Worldwide::Paths::REGIONS_ROOT}/*.yml"].map do |filename|
|
|
17
18
|
load_territory(filename)
|
|
18
19
|
end.flatten
|
|
20
|
+
@regions.each { |region| index_for_hierarchy(region) }
|
|
19
21
|
|
|
20
22
|
# Load hierarchies out of world.yml, and construct regions to match the specified hierarchies
|
|
21
23
|
apply_hierarchy(parent: nil, code: WORLD_CODE, children: world_yml[WORLD_CODE])
|
|
@@ -81,6 +83,7 @@ module Worldwide
|
|
|
81
83
|
)
|
|
82
84
|
end
|
|
83
85
|
@regions << current_region
|
|
86
|
+
index_for_hierarchy(current_region)
|
|
84
87
|
end
|
|
85
88
|
|
|
86
89
|
current_region.parents << parent if Util.present?(parent)
|
|
@@ -211,12 +214,17 @@ module Worldwide
|
|
|
211
214
|
|
|
212
215
|
def country_codes
|
|
213
216
|
@country_codes ||=
|
|
214
|
-
YAML.safe_load_file("#{Worldwide::Paths::DATA_ROOT}/country_codes.yml")["country_codes"]
|
|
217
|
+
YAML.safe_load_file("#{Worldwide::Paths::DATA_ROOT}/country_codes.yml", freeze: true)["country_codes"]
|
|
215
218
|
end
|
|
216
219
|
|
|
217
220
|
def find_region(code:)
|
|
218
|
-
|
|
219
|
-
|
|
221
|
+
@regions_by_hierarchy_code[code.to_s.upcase]
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
def index_for_hierarchy(region)
|
|
225
|
+
[region.cldr_code.upcase, region.iso_code, region.numeric_three, region.alpha_three].compact.each do |code|
|
|
226
|
+
@regions_by_hierarchy_code[code] ||= region
|
|
227
|
+
end
|
|
220
228
|
end
|
|
221
229
|
|
|
222
230
|
def continent?(code)
|
|
@@ -224,7 +232,7 @@ module Worldwide
|
|
|
224
232
|
end
|
|
225
233
|
|
|
226
234
|
def load_territory(filename)
|
|
227
|
-
spec = YAML.safe_load_file(filename)
|
|
235
|
+
spec = YAML.safe_load_file(filename, freeze: true)
|
|
228
236
|
code = spec["code"]
|
|
229
237
|
|
|
230
238
|
region = Region.new(
|
data/lib/worldwide/version.rb
CHANGED
data/lib/worldwide/zip.rb
CHANGED
|
@@ -928,16 +928,17 @@ module Worldwide
|
|
|
928
928
|
end
|
|
929
929
|
end
|
|
930
930
|
|
|
931
|
-
# Moldova post prefers codes to be written "MD-nnnn"
|
|
932
|
-
#
|
|
931
|
+
# Moldova post prefers codes to be written "MD-nnnn". By this point every hyphen and space is
|
|
932
|
+
# gone, so put the hyphen back whenever the MD prefix is present, including the nnnnMD form
|
|
933
|
+
# that some people write. A bare nnnn stays as entered.
|
|
933
934
|
def normalize_for_md(zip:)
|
|
934
935
|
return zip if zip.nil?
|
|
935
936
|
|
|
936
|
-
m = zip.match(
|
|
937
|
+
m = zip.match(/\A(?:MD(\d{4})|(\d{4})MD)\z/)
|
|
937
938
|
if m.nil?
|
|
938
939
|
zip
|
|
939
940
|
else
|
|
940
|
-
"MD-#{m[1]}"
|
|
941
|
+
"MD-#{m[1] || m[2]}"
|
|
941
942
|
end
|
|
942
943
|
end
|
|
943
944
|
|
data/worldwide.gemspec
CHANGED
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
|
18
18
|
spec.metadata["changelog_uri"] = "https://github.com/Shopify/worldwide/blob/main/CHANGELOG.md"
|
|
19
19
|
|
|
20
20
|
spec.files = %x(git ls-files -z).split("\x0").reject do |f|
|
|
21
|
-
f.match(%r{^(rake|test|spec|features|lang
|
|
21
|
+
f.match(%r{^(rake|test|spec|features|lang)/})
|
|
22
22
|
end
|
|
23
23
|
spec.bindir = "exe"
|
|
24
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: worldwide
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shopify
|
|
@@ -75,10 +75,11 @@ files:
|
|
|
75
75
|
- .gitignore
|
|
76
76
|
- .rubocop.yml
|
|
77
77
|
- .ruby-version
|
|
78
|
+
- .security/deepsec.yml
|
|
79
|
+
- .security/deepsec/worldwide.md
|
|
78
80
|
- .vscode/settings.json
|
|
79
81
|
- AGENTS.md
|
|
80
82
|
- CHANGELOG.md
|
|
81
|
-
- CLAUDE.md
|
|
82
83
|
- Gemfile
|
|
83
84
|
- Gemfile.lock
|
|
84
85
|
- LICENSE.md
|
data/CLAUDE.md
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
# CLAUDE.md
|
|
2
|
-
|
|
3
|
-
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
The `worldwide` gem provides internationalization and localization APIs for Ruby, including address validation/formatting, currency handling, date/time formatting, region/country data, phone validation, and more. It also includes a TypeScript/JavaScript package at `lang/typescript`.
|
|
8
|
-
|
|
9
|
-
## Build and Development Commands
|
|
10
|
-
|
|
11
|
-
### Ruby Gem
|
|
12
|
-
- Install dependencies: `bundle install`
|
|
13
|
-
- Run tests: `bundle exec rake test`
|
|
14
|
-
- Run single test file: `bundle exec ruby -Itest test/path/to/test_file.rb`
|
|
15
|
-
- Run single test method: `bundle exec ruby -Itest test/path/to/test_file.rb -n test_method_name`
|
|
16
|
-
- Lint: `bundle exec rubocop`
|
|
17
|
-
- Auto-fix lint issues: `bundle exec rubocop -a`
|
|
18
|
-
- Run tests and linting: `bundle exec rake` (default task)
|
|
19
|
-
- Console: `bin/console` or `bundle exec rake console`
|
|
20
|
-
|
|
21
|
-
### TypeScript Package
|
|
22
|
-
- Navigate to TypeScript directory: `cd lang/typescript`
|
|
23
|
-
- Install dependencies: `pnpm install`
|
|
24
|
-
- Build: `pnpm build`
|
|
25
|
-
- Run tests: `pnpm test`
|
|
26
|
-
- Watch tests: `pnpm test:watch`
|
|
27
|
-
- Lint: `pnpm lint`
|
|
28
|
-
- Type check: `pnpm typecheck`
|
|
29
|
-
- Format: `pnpm format`
|
|
30
|
-
|
|
31
|
-
### Rake Tasks
|
|
32
|
-
- Update CLDR data: See `rake/tasks/cldr.rake` and "Updating CLDR Data" section below
|
|
33
|
-
|
|
34
|
-
## Updating CLDR Data
|
|
35
|
-
|
|
36
|
-
The gem uses Unicode CLDR (Common Locale Data Repository) for internationalization data. To update CLDR data, run these rake tasks **in order**:
|
|
37
|
-
|
|
38
|
-
1. **Clean old data**: `bundle exec rake cldr:data:clean`
|
|
39
|
-
- Removes pre-existing CLDR files to prepare for fresh import
|
|
40
|
-
|
|
41
|
-
2. **Import from Unicode**: `bundle exec rake cldr:data:import`
|
|
42
|
-
- Downloads CLDR data from unicode.org (version specified in `data/cldr.yml`)
|
|
43
|
-
- Converts XML to YAML format
|
|
44
|
-
- Stores raw data in `vendor/cldr/` and processed data in `vendor/ruby-cldr/`
|
|
45
|
-
- Takes several minutes; downloads ~50MB of data
|
|
46
|
-
- Optional: `VERSION=42` to download a specific CLDR version
|
|
47
|
-
- Optional: `COMPONENTS=Units,Calendars` to import specific components only
|
|
48
|
-
|
|
49
|
-
3. **Apply patches**: `bundle exec rake cldr:data:patch`
|
|
50
|
-
- Applies fixes to upstream CLDR data defined in `rake/cldr/patch.rb`
|
|
51
|
-
- Corrects inconsistencies in CLDR (e.g., `²` duplicate markers, inconsistent naming conventions)
|
|
52
|
-
- Updates `data/cldr/` files with patched data
|
|
53
|
-
|
|
54
|
-
4. **Generate additional data**: `bundle exec rake cldr:data:generate`
|
|
55
|
-
- Generates locale-specific data (date/time formats, missing plurals)
|
|
56
|
-
- Takes several minutes
|
|
57
|
-
|
|
58
|
-
5. **Generate file indices**: `bundle exec rake cldr:data:generate_paths`
|
|
59
|
-
- Creates lookup indices for fast file loading
|
|
60
|
-
|
|
61
|
-
### Adding Custom CLDR Patches
|
|
62
|
-
|
|
63
|
-
To fix CLDR data inconsistencies:
|
|
64
|
-
|
|
65
|
-
1. Edit `rake/cldr/patch.rb` and add your patch using `patch_subdivisions` or `patch_file`
|
|
66
|
-
2. Run the patch task: `bundle exec rake cldr:data:patch`
|
|
67
|
-
3. Verify changes in the appropriate `data/cldr/locales/*/` file
|
|
68
|
-
4. Commit both the patch code and the resulting data file changes
|
|
69
|
-
5. Consider reporting the issue upstream at https://unicode-org.atlassian.net
|
|
70
|
-
|
|
71
|
-
Example patch:
|
|
72
|
-
```ruby
|
|
73
|
-
# Remove ² markers from Spanish subdivisions in Portuguese
|
|
74
|
-
patch_subdivisions(:pt, [
|
|
75
|
-
[:esna, "Navarra²", "Navarra"],
|
|
76
|
-
[:esri, "La Rioja²", "La Rioja"],
|
|
77
|
-
])
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
**Important**: The `vendor/` directory is gitignored - it contains temporary build artifacts that should not be committed.
|
|
81
|
-
|
|
82
|
-
## Architecture
|
|
83
|
-
|
|
84
|
-
### Data-Driven Design
|
|
85
|
-
The gem is heavily data-driven, with locale/region data stored in YAML files under `data/`:
|
|
86
|
-
- `data/regions/` - Contains country/territory-specific data (one file per ISO country code)
|
|
87
|
-
- `data/cldr/` - Unicode CLDR data for localization
|
|
88
|
-
- `data/world.yml` - Global region hierarchy and metadata
|
|
89
|
-
- `data/country_codes.yml` - Country code mappings
|
|
90
|
-
- `data/extant_outcodes.yml` - Postal code prefix data for validation
|
|
91
|
-
|
|
92
|
-
### Core Module Structure
|
|
93
|
-
The `Worldwide` module provides a facade with factory methods:
|
|
94
|
-
- `Worldwide.region(code:)` - Access region/country data
|
|
95
|
-
- `Worldwide.address(...)` - Create and manipulate addresses
|
|
96
|
-
- `Worldwide.currency(code:)` - Currency information and formatting
|
|
97
|
-
- `Worldwide.locale(code:)` - Locale information
|
|
98
|
-
- `Worldwide.numbers`, `Worldwide.names`, `Worldwide.lists` - Formatting utilities
|
|
99
|
-
|
|
100
|
-
### Key Components
|
|
101
|
-
|
|
102
|
-
**Regions & Addresses**
|
|
103
|
-
- `Worldwide::Region` - Represents countries, territories, provinces, states, etc.
|
|
104
|
-
- `Worldwide::Address` - Address objects with validation, normalization, and formatting
|
|
105
|
-
- `Worldwide::AddressValidator` - Validates address completeness and correctness
|
|
106
|
-
- `Worldwide::Zip` - Postal code validation and normalization
|
|
107
|
-
|
|
108
|
-
**Localization**
|
|
109
|
-
- `Worldwide::Locale` - Locale metadata and translations
|
|
110
|
-
- `Worldwide::Locales` - Locale collections and lookups
|
|
111
|
-
- `Worldwide::RubyI18nConfig` - Configures Ruby's I18n library
|
|
112
|
-
- `Worldwide::Config` - Global configuration
|
|
113
|
-
|
|
114
|
-
**Formatting**
|
|
115
|
-
- `Worldwide::Numbers` - Number formatting per locale
|
|
116
|
-
- `Worldwide::Currency` - Currency symbols, names, and money formatting
|
|
117
|
-
- `Worldwide::TimeFormatter` - Time/date formatting helpers
|
|
118
|
-
- `Worldwide::Names` - Person name formatting respecting cultural conventions
|
|
119
|
-
- `Worldwide::Lists` - List formatting with locale-appropriate conjunctions
|
|
120
|
-
- `Worldwide::Punctuation` - Punctuation rules per locale
|
|
121
|
-
|
|
122
|
-
**Validation**
|
|
123
|
-
- `Worldwide::Phone` - Phone number validation using phonelib
|
|
124
|
-
- Region-specific postal code validation
|
|
125
|
-
- Address field completeness checking
|
|
126
|
-
|
|
127
|
-
### Testing
|
|
128
|
-
Uses Minitest with:
|
|
129
|
-
- `minitest/autorun` for test running
|
|
130
|
-
- `minitest/reporters` for better output
|
|
131
|
-
- `minitest/focus` for focusing on specific tests (dev only)
|
|
132
|
-
- `mocha/minitest` for mocking/stubbing
|
|
133
|
-
|
|
134
|
-
Test files are organized under `test/worldwide/` mirroring the `lib/worldwide/` structure.
|
|
135
|
-
|
|
136
|
-
### Dependencies
|
|
137
|
-
- `activesupport` (>= 7.0) - Rails utilities
|
|
138
|
-
- `i18n` - Ruby internationalization library
|
|
139
|
-
- `phonelib` (~> 0.8) - Phone number validation
|
|
140
|
-
- `ruby-cldr` (git ref) - CLDR data parser (dev/build only)
|
|
141
|
-
|
|
142
|
-
### Ruby Version
|
|
143
|
-
Requires Ruby >= 3.1.0
|
|
144
|
-
|
|
145
|
-
## Code Conventions
|
|
146
|
-
- Frozen string literals: All Ruby files should start with `# frozen_string_literal: true`
|
|
147
|
-
- Style: Follow Shopify Ruby style guide via `rubocop-shopify`
|
|
148
|
-
- Module caching: Use instance variables for caching (e.g., `@currencies_cache`)
|
|
149
|
-
- Data loading: Lazy-load YAML data to minimize memory footprint
|
|
150
|
-
- Locale awareness: Most classes accept `locale:` parameter, defaulting to `I18n.locale`
|
|
151
|
-
|
|
152
|
-
## Important Notes
|
|
153
|
-
- **This is a public gem**: Avoid adding internal-only references or artifacts
|
|
154
|
-
- When modifying region data, update the corresponding YAML file in `data/regions/`
|
|
155
|
-
- CLDR data is periodically updated; don't manually edit `data/cldr/` files directly - use patches
|
|
156
|
-
- The gem supports both country-level and province/state-level validation
|
|
157
|
-
- Address formatting varies significantly by country; check `data/regions/XX.yml` for country-specific rules
|
|
158
|
-
- The TypeScript package provides equivalent address concatenation/splitting utilities
|