findCapitalByProvince
ResearchfindCapitalByProvince is an Agent Skill for research published in the persian-tools/persian-tools repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.
Look up the capital city of an Iranian province by its Persian name (e.g. "خراسان رضوی" → "مشهد"). Use when displaying capital info next to a province name, or building dropdowns/forms keyed by province. Triggers on mentions of findCapitalByProvince, capital of province, مرکز استان, پایتخت استان.
How to use this skill
Bring this guide into your coding agent with a prompt tailored to the tool you use.
- Open your project in Codex.
- Copy and paste the prompt below.
- Review files and risks before approving any action.
Inspect the Agent Skill at https://github.com/persian-tools/persian-tools/blob/HEAD/skills/findCapitalByProvince/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/findcapitalbyprovince, but wait for my approval before writing files or running scripts.
Copying this prompt does not install or run the skill. Review third-party files before use.
findCapitalByProvince — province → capital (Persian)
import { findCapitalByProvince } from "@persian-tools/persian-tools";
// CommonJS
const { findCapitalByProvince } = require("@persian-tools/persian-tools");
Public export
findCapitalByProvince(state: string): string
Behaviour
import { findCapitalByProvince } from "@persian-tools/persian-tools";
findCapitalByProvince("خراسان رضوی"); // "مشهد"
findCapitalByProvince("تهران"); // "تهران"
findCapitalByProvince("اصفهان"); // "اصفهان"
findCapitalByProvince("ندارد"); // throws PersianToolsError
What it does
- Normalize the input via
toPersianChars(state)— so Arabic-keyboardedك/يare tolerated. - Look up in the
IRAN_STATESmap (src/modules/findCapitalByProvince/states.ts). - If found, return the capital. If not, throw:
PersianToolsError("findCapitalByProvince", "no province found").
Return type is
string, neverundefined. Older docs claimstring | undefined— incorrect; the function throws instead. Wrap calls that may receive bad input in atry/catchor pre-validate against the province list.
Common pitfalls
- Throws on unknown province; doesn't return
null/undefined. - Input is Persian. Latin transliterations (
"Tehran") won't match. No transliteration table. toPersianCharsis applied, so Arabic-keyboarded variations like"تهرآن"with combining marks may still fail — normalize ZWNJ and diacritics upstream too if input is user-typed.- The dataset is a
Map—IRAN_STATES.get(name)exact match after normalization. To pre-filter or autocomplete, iterateArray.from(IRAN_STATES.keys()).
Composition
For coordinate → province → capital chains, use this with findProvinceFromCoordinate:
import { findProvinceFromCoordinate, findCapitalByProvince } from "@persian-tools/persian-tools";
const province = findProvinceFromCoordinate({ longitude: 51.4, latitude: 35.7 });
const capital = findCapitalByProvince(province.fa);
References
- Tests:
test/findCapitalByProvince.spec.ts - Related:
findProvinceFromCoordinateskill