@code-plate/iran-cities 1.1.0 → 2.0.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.
Files changed (130) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/LICENSE +21 -0
  3. package/MIGRATION.fa.md +277 -0
  4. package/MIGRATION.md +272 -0
  5. package/NOTICE.md +38 -0
  6. package/README.fa.md +528 -201
  7. package/README.md +524 -201
  8. package/dist/boundaries.cjs +9218 -0
  9. package/dist/boundaries.cjs.map +1 -0
  10. package/dist/boundaries.d.cts +30 -0
  11. package/dist/boundaries.d.mts +30 -0
  12. package/dist/boundaries.mjs +9215 -0
  13. package/dist/boundaries.mjs.map +1 -0
  14. package/dist/changes-B-wz9-Gy.cjs +841 -0
  15. package/dist/changes-B-wz9-Gy.cjs.map +1 -0
  16. package/dist/changes-CMVZbfZO.d.mts +8 -0
  17. package/dist/changes-DLZkHBwZ.mjs +800 -0
  18. package/dist/changes-DLZkHBwZ.mjs.map +1 -0
  19. package/dist/changes-DnnwRAKl.d.cts +8 -0
  20. package/dist/components-B7060em0.mjs +240 -0
  21. package/dist/components-B7060em0.mjs.map +1 -0
  22. package/dist/components-BuMUB7XT.d.cts +47 -0
  23. package/dist/components-DZz72pd1.d.mts +47 -0
  24. package/dist/components-grWmOsaV.cjs +247 -0
  25. package/dist/components-grWmOsaV.cjs.map +1 -0
  26. package/dist/components.css +251 -0
  27. package/dist/data/cities.csv +1253 -0
  28. package/dist/data/cities.json +23305 -0
  29. package/dist/data/iran-cities.sql +1487 -0
  30. package/dist/data/iran-provinces.geojson +1 -0
  31. package/dist/data/provinces.csv +32 -0
  32. package/dist/data/provinces.json +460 -0
  33. package/dist/hooks-C6kjWLIE.mjs +134 -0
  34. package/dist/hooks-C6kjWLIE.mjs.map +1 -0
  35. package/dist/hooks-K7pTMF2R.cjs +139 -0
  36. package/dist/hooks-K7pTMF2R.cjs.map +1 -0
  37. package/dist/index.cjs +30 -7550
  38. package/dist/index.d.cts +25 -0
  39. package/dist/index.d.mts +25 -25
  40. package/dist/index.mjs +3 -7507
  41. package/dist/lite-CtNPRhU-.mjs +1926 -0
  42. package/dist/lite-CtNPRhU-.mjs.map +1 -0
  43. package/dist/lite-CutarzAc.cjs +2051 -0
  44. package/dist/lite-CutarzAc.cjs.map +1 -0
  45. package/dist/lite-react-1HVWJOWt.cjs +55 -0
  46. package/dist/lite-react-1HVWJOWt.cjs.map +1 -0
  47. package/dist/lite-react-Ds-DNmEi.mjs +20 -0
  48. package/dist/lite-react-Ds-DNmEi.mjs.map +1 -0
  49. package/dist/lite-react-components.cjs +12 -0
  50. package/dist/lite-react-components.cjs.map +1 -0
  51. package/dist/lite-react-components.d.cts +5 -0
  52. package/dist/lite-react-components.d.mts +5 -0
  53. package/dist/lite-react-components.mjs +11 -0
  54. package/dist/lite-react-components.mjs.map +1 -0
  55. package/dist/lite-react.cjs +8 -0
  56. package/dist/lite-react.d.cts +7 -0
  57. package/dist/lite-react.d.mts +7 -0
  58. package/dist/lite-react.mjs +2 -0
  59. package/dist/lite.cjs +28 -0
  60. package/dist/lite.d.cts +23 -0
  61. package/dist/lite.d.mts +23 -0
  62. package/dist/lite.mjs +3 -0
  63. package/dist/react-BKmJ476x.mjs +20 -0
  64. package/dist/react-BKmJ476x.mjs.map +1 -0
  65. package/dist/react-BZV3TkXB.cjs +55 -0
  66. package/dist/react-BZV3TkXB.cjs.map +1 -0
  67. package/dist/react-components.cjs +12 -0
  68. package/dist/react-components.cjs.map +1 -0
  69. package/dist/react-components.d.cts +5 -0
  70. package/dist/react-components.d.mts +5 -0
  71. package/dist/react-components.mjs +11 -0
  72. package/dist/react-components.mjs.map +1 -0
  73. package/dist/react.cjs +8 -7553
  74. package/dist/react.d.cts +7 -0
  75. package/dist/react.d.mts +7 -30
  76. package/dist/react.mjs +2 -7524
  77. package/dist/rolldown-runtime-78lK1XfQ.cjs +42 -0
  78. package/dist/rolldown-runtime-D3KUYPsf.mjs +12 -0
  79. package/dist/src-DRaUVbc4.mjs +4302 -0
  80. package/dist/src-DRaUVbc4.mjs.map +1 -0
  81. package/dist/src-mqZTwJfQ.cjs +4439 -0
  82. package/dist/src-mqZTwJfQ.cjs.map +1 -0
  83. package/dist/types/boundaries.d.ts +30 -0
  84. package/dist/types/changes.d.ts +4 -0
  85. package/dist/types/components.d.ts +47 -0
  86. package/dist/types/core.d.ts +25 -0
  87. package/dist/types/geo.d.ts +2 -0
  88. package/dist/types/hooks.d.ts +2 -0
  89. package/dist/types/index.d.ts +28 -0
  90. package/dist/types/keyboard.d.ts +3 -0
  91. package/dist/types/lite-react-components.d.ts +5 -0
  92. package/dist/types/lite-react.d.ts +7 -0
  93. package/dist/types/lite.d.ts +26 -0
  94. package/dist/types/normalize.d.ts +1 -0
  95. package/dist/types/packed.d.ts +16 -0
  96. package/dist/types/react-components.d.ts +5 -0
  97. package/dist/types/react.d.ts +7 -0
  98. package/dist/types/types.d.ts +149 -0
  99. package/dist/types/valibot.d.ts +23 -0
  100. package/dist/types/validation-shared.d.ts +11 -0
  101. package/dist/types/zod.d.ts +23 -0
  102. package/dist/types-Ds_b0yHP.d.cts +150 -0
  103. package/dist/types-Ds_b0yHP.d.mts +150 -0
  104. package/dist/valibot.cjs +47 -0
  105. package/dist/valibot.cjs.map +1 -0
  106. package/dist/valibot.d.cts +21 -0
  107. package/dist/valibot.d.mts +21 -0
  108. package/dist/valibot.mjs +38 -0
  109. package/dist/valibot.mjs.map +1 -0
  110. package/dist/validation-shared-BFilTuY1.cjs +58 -0
  111. package/dist/validation-shared-BFilTuY1.cjs.map +1 -0
  112. package/dist/validation-shared-C7l2cv4e.d.cts +8 -0
  113. package/dist/validation-shared-CJjGRx8p.d.mts +7 -0
  114. package/dist/validation-shared-mh_saZne.mjs +29 -0
  115. package/dist/validation-shared-mh_saZne.mjs.map +1 -0
  116. package/dist/zod.cjs +49 -0
  117. package/dist/zod.cjs.map +1 -0
  118. package/dist/zod.d.cts +21 -0
  119. package/dist/zod.d.mts +21 -0
  120. package/dist/zod.mjs +42 -0
  121. package/dist/zod.mjs.map +1 -0
  122. package/package.json +177 -29
  123. package/dist/index.cjs.map +0 -1
  124. package/dist/index.d.ts +0 -25
  125. package/dist/index.mjs.map +0 -1
  126. package/dist/react.cjs.map +0 -1
  127. package/dist/react.d.ts +0 -30
  128. package/dist/react.mjs.map +0 -1
  129. package/dist/types-DzSw8Uw2.d.mts +0 -52
  130. package/dist/types-DzSw8Uw2.d.ts +0 -52
@@ -0,0 +1 @@
1
+ {"version":3,"file":"src-mqZTwJfQ.cjs","names":["createApi","unpack","packed"],"sources":["../src/generated/data-full.json","../src/geo.ts","../src/index.ts"],"sourcesContent":["","import type {\r\n CoordinateConfidence,\r\n FlatCity,\r\n IranCities,\r\n IranCitiesGeo,\r\n LatLng,\r\n NearestCitiesOptions,\r\n NearestCity,\r\n Query,\r\n} from './types';\r\n\r\nconst EARTH_RADIUS_KM = 6371.0088;\r\n\r\nconst CONFIDENCE_LEVEL: Readonly<Record<CoordinateConfidence, number>> = { low: 0, medium: 1, high: 2 };\r\n\r\nfunction toRadians(deg: number): number {\r\n return (deg * Math.PI) / 180;\r\n}\r\n\r\nfunction haversine(a: LatLng, b: LatLng): number {\r\n const dLat = toRadians(b.lat - a.lat);\r\n const dLng = toRadians(b.lng - a.lng);\r\n const h =\r\n Math.sin(dLat / 2) ** 2 + Math.cos(toRadians(a.lat)) * Math.cos(toRadians(b.lat)) * Math.sin(dLng / 2) ** 2;\r\n return 2 * EARTH_RADIUS_KM * Math.asin(Math.min(1, Math.sqrt(h)));\r\n}\r\n\r\nfunction isLatLng(value: unknown): value is LatLng {\r\n return (\r\n typeof value === 'object' &&\r\n value !== null &&\r\n typeof (value as LatLng).lat === 'number' &&\r\n typeof (value as LatLng).lng === 'number' &&\r\n Number.isFinite((value as LatLng).lat) &&\r\n Number.isFinite((value as LatLng).lng)\r\n );\r\n}\r\n\r\nexport function createGeo(api: IranCities): IranCitiesGeo {\r\n function resolve(point: LatLng | Query): { coords?: LatLng; city?: FlatCity } {\r\n if (isLatLng(point)) return { coords: { lat: point.lat, lng: point.lng } };\r\n if (typeof point !== 'string' && typeof point !== 'number') return {};\r\n const city = api.getCity(point);\r\n return { coords: city?.coordinates, city };\r\n }\r\n\r\n function getDistance(from: LatLng | Query, to: LatLng | Query): number | undefined {\r\n const a = resolve(from).coords;\r\n const b = resolve(to).coords;\r\n return a && b ? haversine(a, b) : undefined;\r\n }\r\n\r\n function getNearestCities(point: LatLng | Query, options: NearestCitiesOptions = {}): NearestCity[] {\r\n const { coords, city: origin } = resolve(point);\r\n if (!coords) return [];\r\n const limit = typeof options.limit === 'number' && options.limit >= 0 ? Math.floor(options.limit) : 5;\r\n const minLevel = CONFIDENCE_LEVEL[options.minConfidence ?? 'low'] ?? 0;\r\n const maxDistanceKm =\r\n typeof options.maxDistanceKm === 'number' && options.maxDistanceKm >= 0 ? options.maxDistanceKm : Infinity;\r\n\r\n const results: NearestCity[] = [];\r\n for (const city of api.getAllCities()) {\r\n if (!city.coordinates || city === origin) continue;\r\n if (CONFIDENCE_LEVEL[city.coordinates.confidence] < minLevel) continue;\r\n const distanceKm = haversine(coords, city.coordinates);\r\n if (distanceKm <= maxDistanceKm) results.push({ city, distanceKm });\r\n }\r\n results.sort((a, b) => a.distanceKm - b.distanceKm || a.city.id - b.city.id);\r\n return limit > 0 ? results.slice(0, limit) : results;\r\n }\r\n\r\n return { getDistance, getNearestCities };\r\n}\r\n","import packed from './generated/data-full.json' with { type: 'json' };\nimport { createApi } from './core';\nimport { unpack } from './packed';\nimport type { PackedData } from './packed';\nimport { createGeo } from './geo';\nimport type { IranCities, IranCitiesGeo } from './types';\n\nconst api: IranCities = createApi(unpack(packed as PackedData));\nconst geo: IranCitiesGeo = createGeo(api);\n\nexport const getProvinces: IranCities['getProvinces'] = api.getProvinces;\nexport const getProvincesList: IranCities['getProvincesList'] = api.getProvincesList;\nexport const getProvinceById: IranCities['getProvinceById'] = api.getProvinceById;\nexport const getProvince: IranCities['getProvince'] = api.getProvince;\nexport const getCities: IranCities['getCities'] = api.getCities;\nexport const getAllCities: IranCities['getAllCities'] = api.getAllCities;\nexport const getCityById: IranCities['getCityById'] = api.getCityById;\nexport const getCityBySlug: IranCities['getCityBySlug'] = api.getCityBySlug;\nexport const getCity: IranCities['getCity'] = api.getCity;\nexport const getCitiesByName: IranCities['getCitiesByName'] = api.getCitiesByName;\nexport const isAmbiguousCityName: IranCities['isAmbiguousCityName'] = api.isAmbiguousCityName;\nexport const getProvinceOfCity: IranCities['getProvinceOfCity'] = api.getProvinceOfCity;\nexport const getCapital: IranCities['getCapital'] = api.getCapital;\nexport const getCapitals: IranCities['getCapitals'] = api.getCapitals;\nexport const getProvinceByPhoneCode: IranCities['getProvinceByPhoneCode'] = api.getProvinceByPhoneCode;\nexport const searchProvinces: IranCities['searchProvinces'] = api.searchProvinces;\nexport const searchCities: IranCities['searchCities'] = api.searchCities;\nexport const getNeighborProvinces: IranCities['getNeighborProvinces'] = api.getNeighborProvinces;\nexport const areNeighborProvinces: IranCities['areNeighborProvinces'] = api.areNeighborProvinces;\nexport const getStats: IranCities['getStats'] = api.getStats;\nexport const getDistance: IranCitiesGeo['getDistance'] = geo.getDistance;\nexport const getNearestCities: IranCitiesGeo['getNearestCities'] = geo.getNearestCities;\n\nexport { normalize } from './normalize';\nexport { convertKeyboardLayout } from './keyboard';\nexport type { KeyboardTarget } from './keyboard';\nexport { DATA_VERSION, DATA_CHANGES, getDataChanges } from './changes';\n\nexport type {\n City,\n CityId,\n CityKey,\n DataChange,\n DataChangeType,\n CoordinateConfidence,\n Coordinates,\n FlatCity,\n IranCities,\n IranCitiesGeo,\n LatLng,\n Locale,\n NearestCitiesOptions,\n NearestCity,\n Province,\n ProvinceId,\n ProvinceListItem,\n Query,\n SearchOptions,\n Stats,\n} from './types';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AC5D,MAAa,cAAyC,IAAI;AAC1D,MAAa,gBAA6C,IAAI;AAC9D,MAAa,UAAiC,IAAI;AAClD,MAAa,kBAAiD,IAAI;AAClE,MAAa,sBAAyD,IAAI;AAC1E,MAAa,oBAAqD,IAAI;AACtE,MAAa,aAAuC,IAAI;AACxD,MAAa,cAAyC,IAAI;AAC1D,MAAa,yBAA+D,IAAI;AAChF,MAAa,kBAAiD,IAAI;AAClE,MAAa,eAA2C,IAAI;AAC5D,MAAa,uBAA2D,IAAI;AAC5E,MAAa,uBAA2D,IAAI;AAC5E,MAAa,WAAmC,IAAI;AACpD,MAAa,cAA4C,IAAI;AAC7D,MAAa,mBAAsD,IAAI"}
@@ -0,0 +1,30 @@
1
+ import type { LatLng, Province, ProvinceId } from './types';
2
+ export type Position = readonly [number, number];
3
+ export interface PolygonGeometry {
4
+ readonly type: 'Polygon';
5
+ readonly coordinates: readonly (readonly Position[])[];
6
+ }
7
+ export interface MultiPolygonGeometry {
8
+ readonly type: 'MultiPolygon';
9
+ readonly coordinates: readonly (readonly (readonly Position[])[])[];
10
+ }
11
+ export interface ProvinceFeature {
12
+ readonly type: 'Feature';
13
+ readonly id: ProvinceId;
14
+ readonly properties: {
15
+ readonly id: ProvinceId;
16
+ readonly en: string;
17
+ readonly fa: string;
18
+ };
19
+ readonly geometry: PolygonGeometry | MultiPolygonGeometry;
20
+ }
21
+ export interface ProvinceBoundaries {
22
+ readonly type: 'FeatureCollection';
23
+ readonly features: readonly ProvinceFeature[];
24
+ }
25
+ export interface ProvinceAtOptions {
26
+ maxDistanceKm?: number;
27
+ }
28
+ export declare const provinceBoundaries: ProvinceBoundaries;
29
+ export declare function getProvinceAt(point: LatLng, options?: ProvinceAtOptions): Province | undefined;
30
+ export declare function getProvinceBoundary(provinceId: ProvinceId): ProvinceFeature | undefined;
@@ -0,0 +1,4 @@
1
+ import type { DataChange } from './types';
2
+ export declare const DATA_VERSION: string;
3
+ export declare const DATA_CHANGES: readonly DataChange[];
4
+ export declare function getDataChanges(sinceVersion?: string): DataChange[];
@@ -0,0 +1,47 @@
1
+ import * as React from 'react';
2
+ import type { CityId, FlatCity, IranCities, IranCitiesHooks, ProvinceCityValue, Query } from './types';
3
+ export interface CityComboboxProps {
4
+ value?: CityId | null;
5
+ defaultValue?: CityId | null;
6
+ onChange?: (city: FlatCity | null) => void;
7
+ province?: Query | null;
8
+ label?: React.ReactNode;
9
+ placeholder?: string;
10
+ noResultsText?: React.ReactNode;
11
+ limit?: number;
12
+ fuzzy?: boolean;
13
+ showProvince?: boolean;
14
+ locale?: 'fa' | 'en';
15
+ name?: string;
16
+ id?: string;
17
+ required?: boolean;
18
+ disabled?: boolean;
19
+ invalid?: boolean;
20
+ dir?: 'rtl' | 'ltr' | 'auto';
21
+ className?: string;
22
+ inputProps?: Omit<React.InputHTMLAttributes<HTMLInputElement>, 'value' | 'defaultValue' | 'onChange'>;
23
+ }
24
+ export interface ProvinceCitySelectProps {
25
+ value?: ProvinceCityValue;
26
+ defaultValue?: ProvinceCityValue;
27
+ onChange?: (value: ProvinceCityValue) => void;
28
+ provinceLabel?: React.ReactNode;
29
+ cityLabel?: React.ReactNode;
30
+ provincePlaceholder?: string;
31
+ cityPlaceholder?: string;
32
+ provinceName?: string;
33
+ cityName?: string;
34
+ locale?: 'fa' | 'en';
35
+ id?: string;
36
+ required?: boolean;
37
+ disabled?: boolean;
38
+ invalid?: boolean;
39
+ layout?: 'row' | 'column';
40
+ dir?: 'rtl' | 'ltr' | 'auto';
41
+ className?: string;
42
+ }
43
+ export interface IranCitiesComponents {
44
+ CityCombobox: (props: CityComboboxProps) => React.ReactElement;
45
+ ProvinceCitySelect: (props: ProvinceCitySelectProps) => React.ReactElement;
46
+ }
47
+ export declare function createComponents(api: IranCities, hooks: IranCitiesHooks): IranCitiesComponents;
@@ -0,0 +1,25 @@
1
+ import type { IranCities } from './types';
2
+ export interface RawCity {
3
+ 'city-id': number;
4
+ 'city-en': string;
5
+ 'city-fa': string;
6
+ 'name-en'?: string;
7
+ lat?: number;
8
+ lng?: number;
9
+ 'coord-confidence'?: 'medium' | 'low';
10
+ aliases?: string[];
11
+ 'legacy-slugs'?: string[];
12
+ primary?: boolean;
13
+ }
14
+ export interface RawProvince {
15
+ 'province-id': number;
16
+ 'province-en': string;
17
+ 'province-fa': string;
18
+ 'phone-code': string;
19
+ 'capital-city-id': number;
20
+ 'name-en': string;
21
+ neighbors: number[];
22
+ cities: RawCity[];
23
+ }
24
+ export declare function displayNameFromSlug(slug: string): string;
25
+ export declare function createApi(rawData: readonly RawProvince[]): IranCities;
@@ -0,0 +1,2 @@
1
+ import type { IranCities, IranCitiesGeo } from './types';
2
+ export declare function createGeo(api: IranCities): IranCitiesGeo;
@@ -0,0 +1,2 @@
1
+ import type { IranCities, IranCitiesHooks } from './types';
2
+ export declare function createHooks(api: IranCities): IranCitiesHooks;
@@ -0,0 +1,28 @@
1
+ import type { IranCities, IranCitiesGeo } from './types';
2
+ export declare const getProvinces: IranCities['getProvinces'];
3
+ export declare const getProvincesList: IranCities['getProvincesList'];
4
+ export declare const getProvinceById: IranCities['getProvinceById'];
5
+ export declare const getProvince: IranCities['getProvince'];
6
+ export declare const getCities: IranCities['getCities'];
7
+ export declare const getAllCities: IranCities['getAllCities'];
8
+ export declare const getCityById: IranCities['getCityById'];
9
+ export declare const getCityBySlug: IranCities['getCityBySlug'];
10
+ export declare const getCity: IranCities['getCity'];
11
+ export declare const getCitiesByName: IranCities['getCitiesByName'];
12
+ export declare const isAmbiguousCityName: IranCities['isAmbiguousCityName'];
13
+ export declare const getProvinceOfCity: IranCities['getProvinceOfCity'];
14
+ export declare const getCapital: IranCities['getCapital'];
15
+ export declare const getCapitals: IranCities['getCapitals'];
16
+ export declare const getProvinceByPhoneCode: IranCities['getProvinceByPhoneCode'];
17
+ export declare const searchProvinces: IranCities['searchProvinces'];
18
+ export declare const searchCities: IranCities['searchCities'];
19
+ export declare const getNeighborProvinces: IranCities['getNeighborProvinces'];
20
+ export declare const areNeighborProvinces: IranCities['areNeighborProvinces'];
21
+ export declare const getStats: IranCities['getStats'];
22
+ export declare const getDistance: IranCitiesGeo['getDistance'];
23
+ export declare const getNearestCities: IranCitiesGeo['getNearestCities'];
24
+ export { normalize } from './normalize';
25
+ export { convertKeyboardLayout } from './keyboard';
26
+ export type { KeyboardTarget } from './keyboard';
27
+ export { DATA_VERSION, DATA_CHANGES, getDataChanges } from './changes';
28
+ export type { City, CityId, CityKey, DataChange, DataChangeType, CoordinateConfidence, Coordinates, FlatCity, IranCities, IranCitiesGeo, LatLng, Locale, NearestCitiesOptions, NearestCity, Province, ProvinceId, ProvinceListItem, Query, SearchOptions, Stats, } from './types';
@@ -0,0 +1,3 @@
1
+ export type KeyboardTarget = 'fa' | 'en';
2
+ export declare function convertKeyboardLayout(text: string, to: KeyboardTarget): string;
3
+ export declare function guessKeyboardTarget(text: string): KeyboardTarget | undefined;
@@ -0,0 +1,5 @@
1
+ import type { IranCitiesComponents } from './components';
2
+ export declare const CityCombobox: IranCitiesComponents['CityCombobox'];
3
+ export declare const ProvinceCitySelect: IranCitiesComponents['ProvinceCitySelect'];
4
+ export type { CityComboboxProps, IranCitiesComponents, ProvinceCitySelectProps } from './components';
5
+ export type { CityId, FlatCity, ProvinceCityValue, ProvinceId, Query } from './types';
@@ -0,0 +1,7 @@
1
+ import type { IranCitiesHooks } from './types';
2
+ export declare const useProvinces: IranCitiesHooks['useProvinces'];
3
+ export declare const useCities: IranCitiesHooks['useCities'];
4
+ export declare const useProvinceCitySelect: IranCitiesHooks['useProvinceCitySelect'];
5
+ export declare const useCitySearch: IranCitiesHooks['useCitySearch'];
6
+ export declare const useProvinceSearch: IranCitiesHooks['useProvinceSearch'];
7
+ export type { City, CityId, FlatCity, IranCitiesHooks, Province, ProvinceCitySelect, ProvinceCitySelectOptions, ProvinceCityValue, ProvinceId, ProvinceListItem, Query, SearchOptions, SearchState, } from './types';
@@ -0,0 +1,26 @@
1
+ import type { IranCities } from './types';
2
+ export declare const getProvinces: IranCities['getProvinces'];
3
+ export declare const getProvincesList: IranCities['getProvincesList'];
4
+ export declare const getProvinceById: IranCities['getProvinceById'];
5
+ export declare const getProvince: IranCities['getProvince'];
6
+ export declare const getCities: IranCities['getCities'];
7
+ export declare const getAllCities: IranCities['getAllCities'];
8
+ export declare const getCityById: IranCities['getCityById'];
9
+ export declare const getCityBySlug: IranCities['getCityBySlug'];
10
+ export declare const getCity: IranCities['getCity'];
11
+ export declare const getCitiesByName: IranCities['getCitiesByName'];
12
+ export declare const isAmbiguousCityName: IranCities['isAmbiguousCityName'];
13
+ export declare const getProvinceOfCity: IranCities['getProvinceOfCity'];
14
+ export declare const getCapital: IranCities['getCapital'];
15
+ export declare const getCapitals: IranCities['getCapitals'];
16
+ export declare const getProvinceByPhoneCode: IranCities['getProvinceByPhoneCode'];
17
+ export declare const searchProvinces: IranCities['searchProvinces'];
18
+ export declare const searchCities: IranCities['searchCities'];
19
+ export declare const getNeighborProvinces: IranCities['getNeighborProvinces'];
20
+ export declare const areNeighborProvinces: IranCities['areNeighborProvinces'];
21
+ export declare const getStats: IranCities['getStats'];
22
+ export { normalize } from './normalize';
23
+ export { convertKeyboardLayout } from './keyboard';
24
+ export type { KeyboardTarget } from './keyboard';
25
+ export { DATA_VERSION, DATA_CHANGES, getDataChanges } from './changes';
26
+ export type { City, CityId, CityKey, DataChange, DataChangeType, FlatCity, IranCities, Locale, Province, ProvinceId, ProvinceListItem, Query, SearchOptions, Stats, } from './types';
@@ -0,0 +1 @@
1
+ export declare function normalize(input: string): string;
@@ -0,0 +1,16 @@
1
+ import type { RawProvince } from './core';
2
+ type PackedProvince = [number, string, string, string, number, string, number[], number];
3
+ type PackedExtra = [number, string | 0, string[] | 0, 0 | 1, string[] | 0];
4
+ export interface PackedData {
5
+ format: number;
6
+ provinces: PackedProvince[];
7
+ ids: number[];
8
+ en: string;
9
+ fa: string;
10
+ extras: PackedExtra[];
11
+ confidence?: string;
12
+ lat?: number[];
13
+ lng?: number[];
14
+ }
15
+ export declare function unpack(packed: PackedData): RawProvince[];
16
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { IranCitiesComponents } from './components';
2
+ export declare const CityCombobox: IranCitiesComponents['CityCombobox'];
3
+ export declare const ProvinceCitySelect: IranCitiesComponents['ProvinceCitySelect'];
4
+ export type { CityComboboxProps, IranCitiesComponents, ProvinceCitySelectProps } from './components';
5
+ export type { CityId, FlatCity, ProvinceCityValue, ProvinceId, Query } from './types';
@@ -0,0 +1,7 @@
1
+ import type { IranCitiesHooks } from './types';
2
+ export declare const useProvinces: IranCitiesHooks['useProvinces'];
3
+ export declare const useCities: IranCitiesHooks['useCities'];
4
+ export declare const useProvinceCitySelect: IranCitiesHooks['useProvinceCitySelect'];
5
+ export declare const useCitySearch: IranCitiesHooks['useCitySearch'];
6
+ export declare const useProvinceSearch: IranCitiesHooks['useProvinceSearch'];
7
+ export type { City, CityId, FlatCity, IranCitiesHooks, Province, ProvinceCitySelect, ProvinceCitySelectOptions, ProvinceCityValue, ProvinceId, ProvinceListItem, Query, SearchOptions, SearchState, } from './types';
@@ -0,0 +1,149 @@
1
+ export type CityId = number;
2
+ export type ProvinceId = number;
3
+ export type CityKey = string;
4
+ export type Query = string | number;
5
+ export type Locale = 'en' | 'fa';
6
+ export type CoordinateConfidence = 'high' | 'medium' | 'low';
7
+ export interface LatLng {
8
+ readonly lat: number;
9
+ readonly lng: number;
10
+ }
11
+ export interface Coordinates extends LatLng {
12
+ readonly confidence: CoordinateConfidence;
13
+ }
14
+ export interface City {
15
+ readonly id: CityId;
16
+ readonly isCapital: boolean;
17
+ readonly coordinates?: Coordinates;
18
+ readonly slug: CityKey;
19
+ readonly en: string;
20
+ readonly fa: string;
21
+ readonly nameEn: string;
22
+ readonly aliases: readonly string[];
23
+ }
24
+ export interface Province {
25
+ readonly id: ProvinceId;
26
+ readonly en: string;
27
+ readonly fa: string;
28
+ readonly nameEn: string;
29
+ readonly phoneCode: string;
30
+ readonly capitalId: CityId;
31
+ readonly neighborIds: readonly ProvinceId[];
32
+ readonly cities: readonly City[];
33
+ }
34
+ export interface ProvinceListItem {
35
+ id: ProvinceId;
36
+ en: string;
37
+ fa: string;
38
+ nameEn: string;
39
+ phoneCode: string;
40
+ capitalId: CityId;
41
+ }
42
+ export interface FlatCity extends City {
43
+ readonly provinceId: ProvinceId;
44
+ readonly provinceEn: string;
45
+ readonly provinceFa: string;
46
+ readonly provinceNameEn: string;
47
+ readonly phoneCode: string;
48
+ }
49
+ export interface SearchOptions {
50
+ limit?: number;
51
+ locale?: Locale | 'both';
52
+ fuzzy?: boolean;
53
+ maxDistance?: number;
54
+ emptyQuery?: 'all' | 'none';
55
+ keyboardFix?: boolean;
56
+ }
57
+ export interface NearestCitiesOptions {
58
+ limit?: number;
59
+ minConfidence?: CoordinateConfidence;
60
+ maxDistanceKm?: number;
61
+ }
62
+ export interface NearestCity {
63
+ readonly city: FlatCity;
64
+ readonly distanceKm: number;
65
+ }
66
+ export type DataChangeType = 'renamed' | 'spelling' | 'removed' | 'coordinates';
67
+ export interface DataChange {
68
+ readonly version: string;
69
+ readonly type: DataChangeType;
70
+ readonly cityId?: CityId;
71
+ readonly provinceId?: ProvinceId;
72
+ readonly before?: {
73
+ readonly en?: string;
74
+ readonly fa?: string;
75
+ readonly slug?: CityKey;
76
+ };
77
+ readonly after?: {
78
+ readonly en?: string;
79
+ readonly fa?: string;
80
+ readonly slug?: CityKey;
81
+ };
82
+ readonly note: string;
83
+ }
84
+ export interface Stats {
85
+ readonly provinceCount: number;
86
+ readonly cityCount: number;
87
+ }
88
+ export interface IranCities {
89
+ getProvinces(): readonly Province[];
90
+ getProvincesList(): ProvinceListItem[];
91
+ getProvinceById(id: ProvinceId): Province | undefined;
92
+ getProvince(query: Query): Province | undefined;
93
+ getCities(provinceQuery: Query): readonly City[];
94
+ getAllCities(): readonly FlatCity[];
95
+ getCityById(id: CityId): FlatCity | undefined;
96
+ getCityBySlug(slug: CityKey): FlatCity | undefined;
97
+ getCity(cityQuery: Query, provinceQuery?: Query): FlatCity | undefined;
98
+ getCitiesByName(cityQuery: string): readonly FlatCity[];
99
+ isAmbiguousCityName(cityQuery: string): boolean;
100
+ getProvinceOfCity(cityQuery: Query): Province | undefined;
101
+ getCapital(provinceQuery: Query): FlatCity | undefined;
102
+ getCapitals(): FlatCity[];
103
+ getProvinceByPhoneCode(code: string | number): Province | undefined;
104
+ searchProvinces(query: string, options?: SearchOptions): Province[];
105
+ searchCities(query: string, options?: SearchOptions): FlatCity[];
106
+ getNeighborProvinces(provinceQuery: Query): Province[];
107
+ areNeighborProvinces(a: Query, b: Query): boolean;
108
+ getStats(): Stats;
109
+ }
110
+ export interface IranCitiesGeo {
111
+ getDistance(from: LatLng | Query, to: LatLng | Query): number | undefined;
112
+ getNearestCities(point: LatLng | Query, options?: NearestCitiesOptions): NearestCity[];
113
+ }
114
+ export interface ProvinceCityValue {
115
+ provinceId?: ProvinceId;
116
+ cityId?: CityId;
117
+ }
118
+ export interface ProvinceCitySelectOptions {
119
+ initialProvince?: Query;
120
+ initialCity?: Query;
121
+ value?: ProvinceCityValue;
122
+ onChange?: (value: ProvinceCityValue) => void;
123
+ }
124
+ export interface ProvinceCitySelect {
125
+ provinces: ProvinceListItem[];
126
+ cities: readonly City[];
127
+ province: string;
128
+ city: string;
129
+ provinceId: ProvinceId | undefined;
130
+ cityId: CityId | undefined;
131
+ value: ProvinceCityValue;
132
+ selectedProvince: Province | undefined;
133
+ selectedCity: FlatCity | undefined;
134
+ setProvince: (value: Query) => void;
135
+ setCity: (value: Query) => void;
136
+ reset: () => void;
137
+ }
138
+ export interface SearchState<T> {
139
+ query: string;
140
+ setQuery: (query: string | ((previous: string) => string)) => void;
141
+ results: T[];
142
+ }
143
+ export interface IranCitiesHooks {
144
+ useProvinces(): ProvinceListItem[];
145
+ useCities(provinceQuery: Query | undefined | null): readonly City[];
146
+ useProvinceCitySelect(options?: ProvinceCitySelectOptions): ProvinceCitySelect;
147
+ useCitySearch(initialQuery?: string, options?: SearchOptions): SearchState<FlatCity>;
148
+ useProvinceSearch(initialQuery?: string, options?: SearchOptions): SearchState<Province>;
149
+ }
@@ -0,0 +1,23 @@
1
+ import * as v from 'valibot';
2
+ import type { FlatCity, Province } from './types';
3
+ import { toId } from './validation-shared';
4
+ import type { ValidationMessages } from './validation-shared';
5
+ export interface ProvinceCityIds {
6
+ provinceId: number;
7
+ cityId: number;
8
+ }
9
+ export interface IranCitiesValibotSchemas {
10
+ provinceId: v.GenericSchema<unknown, number>;
11
+ cityId: v.GenericSchema<unknown, number>;
12
+ province: v.GenericSchema<unknown, Province>;
13
+ city: v.GenericSchema<unknown, FlatCity>;
14
+ provinceCity: v.GenericSchema<unknown, ProvinceCityIds>;
15
+ }
16
+ export declare function createValibotSchemas(messages?: Partial<ValidationMessages>): IranCitiesValibotSchemas;
17
+ export declare const provinceIdSchema: v.GenericSchema<unknown, number>;
18
+ export declare const cityIdSchema: v.GenericSchema<unknown, number>;
19
+ export declare const provinceSchema: v.GenericSchema<unknown, Province>;
20
+ export declare const citySchema: v.GenericSchema<unknown, FlatCity>;
21
+ export declare const provinceCitySchema: v.GenericSchema<unknown, ProvinceCityIds>;
22
+ export { toId };
23
+ export type { ValidationMessages };
@@ -0,0 +1,11 @@
1
+ import type { IranCities } from './types';
2
+ export interface ValidationMessages {
3
+ province: string;
4
+ city: string;
5
+ cityNotInProvince: string;
6
+ }
7
+ export declare const DEFAULT_MESSAGES: ValidationMessages;
8
+ export declare function toId(value: unknown): number | undefined;
9
+ export declare function isProvinceId(api: IranCities, value: unknown): boolean;
10
+ export declare function isCityId(api: IranCities, value: unknown): boolean;
11
+ export declare function cityBelongsToProvince(api: IranCities, cityId: unknown, provinceId: unknown): boolean;
@@ -0,0 +1,23 @@
1
+ import { z } from 'zod';
2
+ import type { FlatCity, Province } from './types';
3
+ import { toId } from './validation-shared';
4
+ import type { ValidationMessages } from './validation-shared';
5
+ export interface ProvinceCityIds {
6
+ provinceId: number;
7
+ cityId: number;
8
+ }
9
+ export interface IranCitiesZodSchemas {
10
+ provinceId: z.ZodType<number>;
11
+ cityId: z.ZodType<number>;
12
+ province: z.ZodType<Province>;
13
+ city: z.ZodType<FlatCity>;
14
+ provinceCity: z.ZodType<ProvinceCityIds>;
15
+ }
16
+ export declare function createZodSchemas(messages?: Partial<ValidationMessages>): IranCitiesZodSchemas;
17
+ export declare const provinceIdSchema: z.ZodType<number>;
18
+ export declare const cityIdSchema: z.ZodType<number>;
19
+ export declare const provinceSchema: z.ZodType<Province>;
20
+ export declare const citySchema: z.ZodType<FlatCity>;
21
+ export declare const provinceCitySchema: z.ZodType<ProvinceCityIds>;
22
+ export { toId };
23
+ export type { ValidationMessages };
@@ -0,0 +1,150 @@
1
+ type CityId = number;
2
+ type ProvinceId = number;
3
+ type CityKey = string;
4
+ type Query = string | number;
5
+ type Locale = "en" | "fa";
6
+ type CoordinateConfidence = "high" | "medium" | "low";
7
+ interface LatLng {
8
+ readonly lat: number;
9
+ readonly lng: number;
10
+ }
11
+ interface Coordinates extends LatLng {
12
+ readonly confidence: CoordinateConfidence;
13
+ }
14
+ interface City {
15
+ readonly id: CityId;
16
+ readonly isCapital: boolean;
17
+ readonly coordinates?: Coordinates;
18
+ readonly slug: CityKey;
19
+ readonly en: string;
20
+ readonly fa: string;
21
+ readonly nameEn: string;
22
+ readonly aliases: readonly string[];
23
+ }
24
+ interface Province {
25
+ readonly id: ProvinceId;
26
+ readonly en: string;
27
+ readonly fa: string;
28
+ readonly nameEn: string;
29
+ readonly phoneCode: string;
30
+ readonly capitalId: CityId;
31
+ readonly neighborIds: readonly ProvinceId[];
32
+ readonly cities: readonly City[];
33
+ }
34
+ interface ProvinceListItem {
35
+ id: ProvinceId;
36
+ en: string;
37
+ fa: string;
38
+ nameEn: string;
39
+ phoneCode: string;
40
+ capitalId: CityId;
41
+ }
42
+ interface FlatCity extends City {
43
+ readonly provinceId: ProvinceId;
44
+ readonly provinceEn: string;
45
+ readonly provinceFa: string;
46
+ readonly provinceNameEn: string;
47
+ readonly phoneCode: string;
48
+ }
49
+ interface SearchOptions {
50
+ limit?: number;
51
+ locale?: Locale | "both";
52
+ fuzzy?: boolean;
53
+ maxDistance?: number;
54
+ emptyQuery?: "all" | "none";
55
+ keyboardFix?: boolean;
56
+ }
57
+ interface NearestCitiesOptions {
58
+ limit?: number;
59
+ minConfidence?: CoordinateConfidence;
60
+ maxDistanceKm?: number;
61
+ }
62
+ interface NearestCity {
63
+ readonly city: FlatCity;
64
+ readonly distanceKm: number;
65
+ }
66
+ type DataChangeType = "renamed" | "spelling" | "removed" | "coordinates";
67
+ interface DataChange {
68
+ readonly version: string;
69
+ readonly type: DataChangeType;
70
+ readonly cityId?: CityId;
71
+ readonly provinceId?: ProvinceId;
72
+ readonly before?: {
73
+ readonly en?: string;
74
+ readonly fa?: string;
75
+ readonly slug?: CityKey;
76
+ };
77
+ readonly after?: {
78
+ readonly en?: string;
79
+ readonly fa?: string;
80
+ readonly slug?: CityKey;
81
+ };
82
+ readonly note: string;
83
+ }
84
+ interface Stats {
85
+ readonly provinceCount: number;
86
+ readonly cityCount: number;
87
+ }
88
+ interface IranCities {
89
+ getProvinces(): readonly Province[];
90
+ getProvincesList(): ProvinceListItem[];
91
+ getProvinceById(id: ProvinceId): Province | undefined;
92
+ getProvince(query: Query): Province | undefined;
93
+ getCities(provinceQuery: Query): readonly City[];
94
+ getAllCities(): readonly FlatCity[];
95
+ getCityById(id: CityId): FlatCity | undefined;
96
+ getCityBySlug(slug: CityKey): FlatCity | undefined;
97
+ getCity(cityQuery: Query, provinceQuery?: Query): FlatCity | undefined;
98
+ getCitiesByName(cityQuery: string): readonly FlatCity[];
99
+ isAmbiguousCityName(cityQuery: string): boolean;
100
+ getProvinceOfCity(cityQuery: Query): Province | undefined;
101
+ getCapital(provinceQuery: Query): FlatCity | undefined;
102
+ getCapitals(): FlatCity[];
103
+ getProvinceByPhoneCode(code: string | number): Province | undefined;
104
+ searchProvinces(query: string, options?: SearchOptions): Province[];
105
+ searchCities(query: string, options?: SearchOptions): FlatCity[];
106
+ getNeighborProvinces(provinceQuery: Query): Province[];
107
+ areNeighborProvinces(a: Query, b: Query): boolean;
108
+ getStats(): Stats;
109
+ }
110
+ interface IranCitiesGeo {
111
+ getDistance(from: LatLng | Query, to: LatLng | Query): number | undefined;
112
+ getNearestCities(point: LatLng | Query, options?: NearestCitiesOptions): NearestCity[];
113
+ }
114
+ interface ProvinceCityValue {
115
+ provinceId?: ProvinceId;
116
+ cityId?: CityId;
117
+ }
118
+ interface ProvinceCitySelectOptions {
119
+ initialProvince?: Query;
120
+ initialCity?: Query;
121
+ value?: ProvinceCityValue;
122
+ onChange?: (value: ProvinceCityValue) => void;
123
+ }
124
+ interface ProvinceCitySelect {
125
+ provinces: ProvinceListItem[];
126
+ cities: readonly City[];
127
+ province: string;
128
+ city: string;
129
+ provinceId: ProvinceId | undefined;
130
+ cityId: CityId | undefined;
131
+ value: ProvinceCityValue;
132
+ selectedProvince: Province | undefined;
133
+ selectedCity: FlatCity | undefined;
134
+ setProvince: (value: Query) => void;
135
+ setCity: (value: Query) => void;
136
+ reset: () => void;
137
+ }
138
+ interface SearchState<T> {
139
+ query: string;
140
+ setQuery: (query: string | ((previous: string) => string)) => void;
141
+ results: T[];
142
+ }
143
+ interface IranCitiesHooks {
144
+ useProvinces(): ProvinceListItem[];
145
+ useCities(provinceQuery: Query | undefined | null): readonly City[];
146
+ useProvinceCitySelect(options?: ProvinceCitySelectOptions): ProvinceCitySelect;
147
+ useCitySearch(initialQuery?: string, options?: SearchOptions): SearchState<FlatCity>;
148
+ useProvinceSearch(initialQuery?: string, options?: SearchOptions): SearchState<Province>;
149
+ }
150
+ export { SearchOptions as C, Query as S, Stats as T, ProvinceCitySelect as _, Coordinates as a, ProvinceId as b, FlatCity as c, IranCitiesHooks as d, LatLng as f, Province as g, NearestCity as h, CoordinateConfidence as i, IranCities as l, NearestCitiesOptions as m, CityId as n, DataChange as o, Locale as p, CityKey as r, DataChangeType as s, City as t, IranCitiesGeo as u, ProvinceCitySelectOptions as v, SearchState as w, ProvinceListItem as x, ProvinceCityValue as y };