Repository navigation
feat(area-codes): add getMunicipalitiesByAreaCode and getAreaCodeByMunicipalityCode - #597
Conversation
…nicipalityCode There was no way to go from a DDD to the municipalities that dial it, or from a municipality to its DDD; getAreaCodeInfo only knew the state. Both now come from the Código Nacional in force for every municipality, in the Codigos_Nacionais.csv Anatel publishes in pgcn.zip (21/09/2026): 5,571 rows in force, the same municipalities as the IBGE table, and the same 67 DDDs and four cross-border ones as AREA_CODE_STATES. getAreaCodeByMunicipalityCode builds on getMunicipalityByCode and returns the DDD, or null for a code that is not a municipality. getMunicipalitiesByAreaCode builds on getAreaCodeInfo and lists the municipalities of the seat state first, then those of the state the DDD crosses into (61 covers 12 municipalities of Goiás; 42, 47 and 49 one each). scripts/area-codes.ts generates the table and runs with the other datasets. It stores the two digits of each municipality's DDD in ascending order of the municipality code, one string per state, so it adds 11.5 KB minified (2.6 KB gzipped) on top of the municipality table the two functions already need. A test checks the table covers exactly the municipalities of the IBGE table and agrees with AREA_CODE_STATES. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RLkm9YrtAifc6XCLFVEsdH
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
"Publish a preview to pkg.pr.new" failed in the service's publish call, not in this PR. The build, attw and publint steps passed. Then Generated by Claude Code |
Tree-shaking report✅ No size regression. 2 grew, 1 shrank, 2 new out of 187 exports.
What changed (5)
All exports (187)
How this is measuredEvery export is imported alone into an esbuild consumer bundle (minified, tree-shaken) built from the head and from the base of this pull request; the sizes are the resulting bundles, gzip is their gzipped size. 🔴 marks a regression: a pre-existing export that grew more than 20% and more than 256 B, or the bundle importing every pre-existing export growing more than 5%. 🟡 is growth under the threshold, 🟢 a decrease, ⚪ no change, 🆕 an export that does not exist on the base (never a regression), 🗑️ an export that was removed. An intentional increase is accepted with the |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## claude/lookup-fixes #597 +/- ##
=====================================================
Coverage 100.00% 100.00%
=====================================================
Files 224 227 +3
Lines 2341 2364 +23
Branches 703 706 +3
=====================================================
+ Hits 2341 2364 +23
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
commit: |
…er municipality getMunicipalitiesByAreaCode found each municipality's position with indexOf over the state's sorted codes, so listing Minas Gerais compared about 360,000 strings, and the property test that also looked every listed municipality up again (5,571 linear lookups through getMunicipalityByCode) timed out at 5 seconds in the Stryker dry run. readMunicipalityAreaCode now builds each state's code-to-DDD index on its first lookup and keeps it, and the property test samples municipalities instead of walking all of them; a separate test still checks every DDD in use lists a municipality. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RLkm9YrtAifc6XCLFVEsdH
…etMunicipalityByCode do Follows #596 restoring the 2.4.0 contract of the lookups it builds on: a string code has any non-digit character stripped, so the tests and docs no longer expect "1e1" or "355030a8" to be rejected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RLkm9YrtAifc6XCLFVEsdH
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RLkm9YrtAifc6XCLFVEsdH
|
Generated by Claude Code |
|
Generated by Claude Code |
What does this PR do?
This PR adds two lookups between DDDs and municipalities. Until now
getAreaCodeInfoonly returned the state of a DDD, so there was no way to list the municipalities that dial it, or to find a municipality's DDD. It stacks on #596.getAreaCodeByMunicipalityCode(code)nullwhen the code is not a municipality. It builds ongetMunicipalityByCodeand reads the code the same way.getMunicipalitiesByAreaCode(areaCode){ code, name, stateCode }of every municipality that dials the DDD, or[]for a DDD not in use. It builds ongetAreaCodeInfoand reads the DDD the same way, parentheses included. The seat state's municipalities come first, then those of the state the DDD crosses into, each state sorted by name.Data
Codigos_Nacionais.csvthat Anatel publishes inpgcn.zip(21/09/2026). Only the rows in force are kept (VIGENTE=Sim).AREA_CODE_STATES/AREA_CODE_SECONDARY_STATES: the same 67 DDDs, each with the same states. The four cross-border cases are the same too: 61 covers 12 municipalities of Goiás; Porto União (SC) dials 42, Rio Negro (PR) 47 and Barracão (PR) 49.scripts/area-codes.tsgeneratessrc/_internals/constants/municipality-area-codes.tsand runs with the other datasets inscripts/data.ts.scripts/read-xlsx-sheet.tsnow exportsreadZipFile, which reuses its existing unzip code.AREA_CODE_STATES.The docs (
docs/utilities.md,docs/pt-br/utilities.md, and the dataset table in bothgetting-started.md),jsr.json,context7.jsonand the data summary are updated.Checklist
docs/utilities.mdanddocs/pt-br/utilities.md.npm run checkpasses locally. Coverage (100%, 7777 tests), Deno, Bun,check:unused,check:duplication,check:apiand Stryker on the new files (100%) also pass.npm run build:llms.check:apireports no breaking change against 2.4.0.Additional context
getAreaCodeByMunicipalityCode) and 167.8 KB (getMunicipalitiesByAreaCode) minified, or 52.1 and 52.8 KB gzipped.getMunicipalityByCode). The DDD data adds 11.5 KB minified (2.6 KB gzipped).pgcn.zip🤖 Generated with Claude Code
https://claude.ai/code/session_01RLkm9YrtAifc6XCLFVEsdH
Generated by Claude Code