@velion-la/onboarding-sdk-react-native 1.3.0-beta.22 → 1.3.0-beta.23
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.
- package/lib/commonjs/utils/subdivisions.js +12 -9
- package/lib/commonjs/utils/subdivisions.js.map +1 -1
- package/lib/commonjs/vendor/geo/README.md +2 -2
- package/lib/commonjs/vendor/geo/geocoder/AR.js +1 -26
- package/lib/commonjs/vendor/geo/geocoder/AR.js.map +1 -1
- package/lib/commonjs/vendor/geo/index.js +13 -4
- package/lib/commonjs/vendor/geo/index.js.map +1 -1
- package/lib/commonjs/vendor/geo/suggest.js +61 -0
- package/lib/commonjs/vendor/geo/suggest.js.map +1 -0
- package/lib/module/utils/subdivisions.js +13 -10
- package/lib/module/utils/subdivisions.js.map +1 -1
- package/lib/module/vendor/geo/README.md +2 -2
- package/lib/module/vendor/geo/geocoder/AR.js +1 -26
- package/lib/module/vendor/geo/geocoder/AR.js.map +1 -1
- package/lib/module/vendor/geo/index.js +8 -5
- package/lib/module/vendor/geo/index.js.map +1 -1
- package/lib/module/vendor/geo/suggest.js +57 -0
- package/lib/module/vendor/geo/suggest.js.map +1 -0
- package/lib/typescript/utils/subdivisions.d.ts +5 -2
- package/lib/typescript/utils/subdivisions.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/utils/subdivisions.ts +13 -10
- package/src/vendor/geo/README.md +2 -2
- package/src/vendor/geo/geocoder/AR.js +1 -1
- package/src/vendor/geo/index.js +8 -5
- package/src/vendor/geo/suggest.js +54 -0
- package/src/vendor/geo/types/geocoder.d.ts +5 -1
- package/src/vendor/geo/types/index.d.ts +16 -1
|
@@ -28,10 +28,10 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* `ENTRIES` of `scripts/vendor-geo.mjs`.
|
|
31
|
+
* Curated geocoder spellings that are no subdivision's name (e.g. "Capital
|
|
32
|
+
* Federal"). Plain names are matched in every country without them. Only AR
|
|
33
|
+
* has entries in geo; a country added to geo's `sources/geocoder.json` needs
|
|
34
|
+
* its import here and in `ENTRIES` of `scripts/vendor-geo.mjs`.
|
|
35
35
|
*/
|
|
36
36
|
const GEOCODER_ALIASES = {
|
|
37
37
|
AR: _AR.default
|
|
@@ -59,13 +59,16 @@ function listStateOptions(country, locale) {
|
|
|
59
59
|
* (Google's `administrative_area_level_1`, the platform geocoder's `region`).
|
|
60
60
|
* It only preselects the picker: the user still confirms or changes it.
|
|
61
61
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
62
|
+
* Matches the country's curated aliases first, then its subdivision names in
|
|
63
|
+
* every locale.
|
|
64
|
+
*
|
|
65
|
+
* @returns the code, or `''` when the name or country is unknown, or the name
|
|
66
|
+
* is ambiguous.
|
|
64
67
|
*/
|
|
65
68
|
function suggestState(country, geocoderName) {
|
|
66
|
-
const
|
|
67
|
-
if (!
|
|
68
|
-
return (0, _index.
|
|
69
|
+
const data = countryData(country);
|
|
70
|
+
if (!data) return '';
|
|
71
|
+
return (0, _index.suggestSubdivision)(data, geocoderName, GEOCODER_ALIASES[country.toUpperCase()]) ?? '';
|
|
69
72
|
}
|
|
70
73
|
|
|
71
74
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_index","require","_all","_interopRequireDefault","_AR","e","__esModule","default","GEOCODER_ALIASES","AR","arAliases","countryData","country","undefined","all","toUpperCase","listStateOptions","locale","data","subdivisionsOf","map","code","value","label","nameOf","sort","a","b","localeCompare","suggestState","geocoderName","
|
|
1
|
+
{"version":3,"names":["_index","require","_all","_interopRequireDefault","_AR","e","__esModule","default","GEOCODER_ALIASES","AR","arAliases","countryData","country","undefined","all","toUpperCase","listStateOptions","locale","data","subdivisionsOf","map","code","value","label","nameOf","sort","a","b","localeCompare","suggestState","geocoderName","suggestSubdivision","keepStateIfValid","state","includes"],"sourceRoot":"../../../src","sources":["utils/subdivisions.ts"],"mappings":";;;;;;;;AAiBA,IAAAA,MAAA,GAAAC,OAAA;AAOA,IAAAC,IAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,GAAA,GAAAD,sBAAA,CAAAF,OAAA;AAAkD,SAAAE,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAzBlD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMG,gBAA2D,GAAG;EAClEC,EAAE,EAAEC;AACN,CAAC;AAED,SAASC,WAAWA,CAACC,OAAkC,EAA2B;EAChF,IAAI,CAACA,OAAO,EAAE,OAAOC,SAAS;EAC9B,OAAOC,YAAG,CAACF,OAAO,CAACG,WAAW,CAAC,CAAC,CAAC;AACnC;AASA;AACA;AACA;AACA;AACA;AACO,SAASC,gBAAgBA,CAC9BJ,OAAkC,EAClCK,MAAc,EACC;EACf,MAAMC,IAAI,GAAGP,WAAW,CAACC,OAAO,CAAC;EACjC,IAAI,CAACM,IAAI,EAAE,OAAO,EAAE;EACpB,OAAO,IAAAC,qBAAc,EAACD,IAAI,CAAC,CACxBE,GAAG,CAAEC,IAAI,KAAM;IAAEC,KAAK,EAAED,IAAI;IAAEE,KAAK,EAAE,IAAAC,aAAM,EAACN,IAAI,EAAEG,IAAI,EAAEJ,MAAM,CAAC,IAAII;EAAK,CAAC,CAAC,CAAC,CAC3EI,IAAI,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAKD,CAAC,CAACH,KAAK,CAACK,aAAa,CAACD,CAAC,CAACJ,KAAK,EAAEN,MAAM,CAAC,CAAC;AAC3D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASY,YAAYA,CAC1BjB,OAAkC,EAClCkB,YAAuC,EAC/B;EACR,MAAMZ,IAAI,GAAGP,WAAW,CAACC,OAAO,CAAC;EACjC,IAAI,CAACM,IAAI,EAAE,OAAO,EAAE;EACpB,OAAO,IAAAa,yBAAkB,EAACb,IAAI,EAAEY,YAAY,EAAEtB,gBAAgB,CAACI,OAAO,CAAEG,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE;AAC/F;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASiB,gBAAgBA,CAC9BpB,OAAkC,EAClCqB,KAAgC,EACxB;EACR,MAAMf,IAAI,GAAGP,WAAW,CAACC,OAAO,CAAC;EACjC,IAAI,CAACM,IAAI,IAAI,CAACe,KAAK,EAAE,OAAO,EAAE;EAC9B,OAAO,IAAAd,qBAAc,EAACD,IAAI,CAAC,CAACgB,QAAQ,CAACD,KAAK,CAAC,GAAGA,KAAK,GAAG,EAAE;AAC1D","ignoreList":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# Embedded @velion-la/geo
|
|
2
2
|
|
|
3
|
-
Copied by `scripts/vendor-geo.mjs` from `@velion-la/geo@1.0.0-alpha.
|
|
3
|
+
Copied by `scripts/vendor-geo.mjs` from `@velion-la/geo@1.0.0-alpha.4`. Do not edit:
|
|
4
4
|
these files are regenerated before every typecheck, test, build and pack. To change
|
|
5
5
|
the version, update the `@velion-la/geo` devDependency in `sdk/package.json`.
|
|
6
6
|
|
|
7
|
-
Only the modules the SDK imports are included: `all.js`, `data/countries.js`, `data/locales.js`, `geocoder/AR.js`, `index.js`, `normalize.js`, `countries/*.js` (249 countries).
|
|
7
|
+
Only the modules the SDK imports are included: `all.js`, `data/countries.js`, `data/locales.js`, `geocoder/AR.js`, `index.js`, `normalize.js`, `suggest.js`, `countries/*.js` (249 countries).
|
|
8
8
|
|
|
9
9
|
## Notice
|
|
10
10
|
|
|
@@ -6,34 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
// Generated by generator/generate.mjs from CLDR 49. Do not edit.
|
|
8
8
|
var _default = exports.default = {
|
|
9
|
-
"autonomous city of buenos aires": "AR-C",
|
|
10
|
-
"buenos aires": "AR-B",
|
|
11
9
|
"caba": "AR-C",
|
|
12
10
|
"capital federal": "AR-C",
|
|
13
|
-
"catamarca": "AR-K",
|
|
14
|
-
"chaco": "AR-H",
|
|
15
|
-
"chubut": "AR-U",
|
|
16
|
-
"ciudad autonoma de buenos aires": "AR-C",
|
|
17
11
|
"ciudad de buenos aires": "AR-C",
|
|
18
|
-
"
|
|
19
|
-
"corrientes": "AR-W",
|
|
20
|
-
"entre rios": "AR-E",
|
|
21
|
-
"formosa": "AR-P",
|
|
22
|
-
"jujuy": "AR-Y",
|
|
23
|
-
"la pampa": "AR-L",
|
|
24
|
-
"la rioja": "AR-F",
|
|
25
|
-
"mendoza": "AR-M",
|
|
26
|
-
"misiones": "AR-N",
|
|
27
|
-
"neuquen": "AR-Q",
|
|
28
|
-
"rio negro": "AR-R",
|
|
29
|
-
"salta": "AR-A",
|
|
30
|
-
"san juan": "AR-J",
|
|
31
|
-
"san luis": "AR-D",
|
|
32
|
-
"santa cruz": "AR-Z",
|
|
33
|
-
"santa fe": "AR-S",
|
|
34
|
-
"santiago del estero": "AR-G",
|
|
35
|
-
"tierra del fuego": "AR-V",
|
|
36
|
-
"tierra del fuego antartida e islas del atlantico sur": "AR-V",
|
|
37
|
-
"tucuman": "AR-T"
|
|
12
|
+
"tierra del fuego antartida e islas del atlantico sur": "AR-V"
|
|
38
13
|
};
|
|
39
14
|
//# sourceMappingURL=AR.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_default","exports","default"],"sourceRoot":"../../../../../src","sources":["vendor/geo/geocoder/AR.js"],"mappings":";;;;;;AAAA;AAAA,IAAAA,QAAA,GAAAC,OAAA,CAAAC,OAAA,GACe;EAAC,
|
|
1
|
+
{"version":3,"names":["_default","exports","default"],"sourceRoot":"../../../../../src","sources":["vendor/geo/geocoder/AR.js"],"mappings":";;;;;;AAAA;AAAA,IAAAA,QAAA,GAAAC,OAAA,CAAAC,OAAA,GACe;EAAC,MAAM,EAAC,MAAM;EAAC,iBAAiB,EAAC,MAAM;EAAC,wBAAwB,EAAC,MAAM;EAAC,sDAAsD,EAAC;AAAM,CAAC","ignoreList":[]}
|
|
@@ -18,9 +18,16 @@ Object.defineProperty(exports, "normalize", {
|
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
20
|
exports.subdivisionsOf = subdivisionsOf;
|
|
21
|
+
Object.defineProperty(exports, "suggestSubdivision", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _suggest.suggestSubdivision;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
21
27
|
var _countries = _interopRequireDefault(require("./data/countries.js"));
|
|
22
28
|
var _locales = _interopRequireDefault(require("./data/locales.js"));
|
|
23
29
|
var _normalize = require("./normalize.js");
|
|
30
|
+
var _suggest = require("./suggest.js");
|
|
24
31
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
25
32
|
const FALLBACK_LOCALE = 'en';
|
|
26
33
|
const countrySet = new Set(_countries.default.codes);
|
|
@@ -103,13 +110,15 @@ function nameOf(data, code, locale) {
|
|
|
103
110
|
}
|
|
104
111
|
|
|
105
112
|
/**
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
113
|
+
* Looks the subdivision name a geocoder returned up in the country's geocoder aliases.
|
|
114
|
+
* Those hold only the spellings that are no subdivision's name ("CABA", "Capital
|
|
115
|
+
* Federal"), so this finds no "Córdoba" or "Andalucía": {@link suggestSubdivision} looks
|
|
116
|
+
* in the country's names as well.
|
|
109
117
|
*
|
|
118
|
+
* @deprecated Use {@link suggestSubdivision}, which also matches the country's names.
|
|
110
119
|
* @param {import('./types/geocoder.js').GeocoderAliases} aliases the country's aliases, from "@velion-la/geo/load" or "@velion-la/geo/geocoder/XX"
|
|
111
120
|
* @param {string | null | undefined} name the name as the geocoder returned it
|
|
112
|
-
* @returns {string | undefined} the code, or undefined when the name is
|
|
121
|
+
* @returns {string | undefined} the code, or undefined when the name is no alias
|
|
113
122
|
*/
|
|
114
123
|
function fromGeocoderName(aliases, name) {
|
|
115
124
|
const key = (0, _normalize.normalize)(name);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_countries","_interopRequireDefault","require","_locales","_normalize","e","__esModule","default","FALLBACK_LOCALE","countrySet","Set","countryData","codes","locales","exports","Object","freeze","supportedLocales","countries","language","locale","lang","toLowerCase","split","includes","isCountry","code","has","countryName","names","subdivisionsOf","data","childrenOf","parent","entries","subdivisions","filter","of","map","isSubdivision","state","hasOwn","nameOf","fromGeocoderName","aliases","name","key","normalize","undefined"],"sourceRoot":"../../../../src","sources":["vendor/geo/index.js"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_countries","_interopRequireDefault","require","_locales","_normalize","_suggest","e","__esModule","default","FALLBACK_LOCALE","countrySet","Set","countryData","codes","locales","exports","Object","freeze","supportedLocales","countries","language","locale","lang","toLowerCase","split","includes","isCountry","code","has","countryName","names","subdivisionsOf","data","childrenOf","parent","entries","subdivisions","filter","of","map","isSubdivision","state","hasOwn","nameOf","fromGeocoderName","aliases","name","key","normalize","undefined"],"sourceRoot":"../../../../src","sources":["vendor/geo/index.js"],"mappings":"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","ignoreList":[]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.nameIndex = nameIndex;
|
|
7
|
+
exports.suggestSubdivision = suggestSubdivision;
|
|
8
|
+
var _normalize = require("./normalize.js");
|
|
9
|
+
// One index per loaded country object. A WeakMap keeps it as long as the app keeps the
|
|
10
|
+
// country: importing "@velion-la/geo/all" and suggesting in every country does not pin
|
|
11
|
+
// 249 indexes once the data is gone.
|
|
12
|
+
const indexes = new WeakMap();
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Normalized name → ISO 3166-2 code, from every name of every subdivision in every locale.
|
|
16
|
+
* A normalized name shared by two subdivisions of the same country maps to null: the
|
|
17
|
+
* generator drops it from the geocoder table too, rather than guess.
|
|
18
|
+
*
|
|
19
|
+
* @param {import('./types/country.js').CountryData} data loaded country
|
|
20
|
+
* @returns {Map<string, string | null>}
|
|
21
|
+
*/
|
|
22
|
+
function nameIndex(data) {
|
|
23
|
+
let index = indexes.get(data);
|
|
24
|
+
if (!index) {
|
|
25
|
+
index = new Map();
|
|
26
|
+
for (const code of Object.keys(data.subdivisions)) {
|
|
27
|
+
for (const names of Object.values(data.names)) {
|
|
28
|
+
const key = (0, _normalize.normalize)(names[code]);
|
|
29
|
+
if (key) {
|
|
30
|
+
index.set(key, index.has(key) && index.get(key) !== code ? null : code);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
indexes.set(data, index);
|
|
35
|
+
}
|
|
36
|
+
return index;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Suggests the subdivision for the name a geocoder returned (Google's
|
|
41
|
+
* administrative_area_level_1, the platform geocoder's region), using the country's own
|
|
42
|
+
* names: "Andalucía" in Spain is ES-AN, "Provincia de Córdoba" in Argentina is AR-X. The
|
|
43
|
+
* aliases, when given, are tried first; they hold the spellings providers use that are no
|
|
44
|
+
* subdivision's name, such as "CABA". The result is a suggestion: the user still confirms it.
|
|
45
|
+
*
|
|
46
|
+
* @param {import('./types/country.js').CountryData} data the country of the address
|
|
47
|
+
* @param {string | null | undefined} name the name as the geocoder returned it
|
|
48
|
+
* @param {import('./types/geocoder.js').GeocoderAliases} [aliases] the country's aliases, from "@velion-la/geo/load" or "@velion-la/geo/geocoder/XX"
|
|
49
|
+
* @returns {string | undefined} the code, or undefined when the name is unknown or matches more than one subdivision
|
|
50
|
+
*/
|
|
51
|
+
function suggestSubdivision(data, name, aliases) {
|
|
52
|
+
const key = (0, _normalize.normalize)(name);
|
|
53
|
+
if (!key) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
if (aliases && Object.hasOwn(aliases, key)) {
|
|
57
|
+
return aliases[key];
|
|
58
|
+
}
|
|
59
|
+
return nameIndex(data).get(key) ?? undefined;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=suggest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_normalize","require","indexes","WeakMap","nameIndex","data","index","get","Map","code","Object","keys","subdivisions","names","values","key","normalize","set","has","suggestSubdivision","name","aliases","undefined","hasOwn"],"sourceRoot":"../../../../src","sources":["vendor/geo/suggest.js"],"mappings":";;;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA,MAAMC,OAAO,GAAG,IAAIC,OAAO,CAAC,CAAC;;AAE7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,SAASA,CAACC,IAAI,EAAE;EAC9B,IAAIC,KAAK,GAAGJ,OAAO,CAACK,GAAG,CAACF,IAAI,CAAC;EAC7B,IAAI,CAACC,KAAK,EAAE;IACVA,KAAK,GAAG,IAAIE,GAAG,CAAC,CAAC;IACjB,KAAK,MAAMC,IAAI,IAAIC,MAAM,CAACC,IAAI,CAACN,IAAI,CAACO,YAAY,CAAC,EAAE;MACjD,KAAK,MAAMC,KAAK,IAAIH,MAAM,CAACI,MAAM,CAACT,IAAI,CAACQ,KAAK,CAAC,EAAE;QAC7C,MAAME,GAAG,GAAG,IAAAC,oBAAS,EAACH,KAAK,CAACJ,IAAI,CAAC,CAAC;QAClC,IAAIM,GAAG,EAAE;UACPT,KAAK,CAACW,GAAG,CAACF,GAAG,EAAET,KAAK,CAACY,GAAG,CAACH,GAAG,CAAC,IAAIT,KAAK,CAACC,GAAG,CAACQ,GAAG,CAAC,KAAKN,IAAI,GAAG,IAAI,GAAGA,IAAI,CAAC;QACzE;MACF;IACF;IACAP,OAAO,CAACe,GAAG,CAACZ,IAAI,EAAEC,KAAK,CAAC;EAC1B;EACA,OAAOA,KAAK;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASa,kBAAkBA,CAACd,IAAI,EAAEe,IAAI,EAAEC,OAAO,EAAE;EACtD,MAAMN,GAAG,GAAG,IAAAC,oBAAS,EAACI,IAAI,CAAC;EAC3B,IAAI,CAACL,GAAG,EAAE;IACR,OAAOO,SAAS;EAClB;EACA,IAAID,OAAO,IAAIX,MAAM,CAACa,MAAM,CAACF,OAAO,EAAEN,GAAG,CAAC,EAAE;IAC1C,OAAOM,OAAO,CAACN,GAAG,CAAC;EACrB;EACA,OAAOX,SAAS,CAACC,IAAI,CAAC,CAACE,GAAG,CAACQ,GAAG,CAAC,IAAIO,SAAS;AAC9C","ignoreList":[]}
|
|
@@ -17,15 +17,15 @@
|
|
|
17
17
|
* listed in `GEOCODER_ALIASES`.
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
import {
|
|
20
|
+
import { nameOf, subdivisionsOf, suggestSubdivision } from '../vendor/geo/index';
|
|
21
21
|
import all from '../vendor/geo/all';
|
|
22
22
|
import arAliases from '../vendor/geo/geocoder/AR';
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* `ENTRIES` of `scripts/vendor-geo.mjs`.
|
|
25
|
+
* Curated geocoder spellings that are no subdivision's name (e.g. "Capital
|
|
26
|
+
* Federal"). Plain names are matched in every country without them. Only AR
|
|
27
|
+
* has entries in geo; a country added to geo's `sources/geocoder.json` needs
|
|
28
|
+
* its import here and in `ENTRIES` of `scripts/vendor-geo.mjs`.
|
|
29
29
|
*/
|
|
30
30
|
const GEOCODER_ALIASES = {
|
|
31
31
|
AR: arAliases
|
|
@@ -53,13 +53,16 @@ export function listStateOptions(country, locale) {
|
|
|
53
53
|
* (Google's `administrative_area_level_1`, the platform geocoder's `region`).
|
|
54
54
|
* It only preselects the picker: the user still confirms or changes it.
|
|
55
55
|
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
56
|
+
* Matches the country's curated aliases first, then its subdivision names in
|
|
57
|
+
* every locale.
|
|
58
|
+
*
|
|
59
|
+
* @returns the code, or `''` when the name or country is unknown, or the name
|
|
60
|
+
* is ambiguous.
|
|
58
61
|
*/
|
|
59
62
|
export function suggestState(country, geocoderName) {
|
|
60
|
-
const
|
|
61
|
-
if (!
|
|
62
|
-
return
|
|
63
|
+
const data = countryData(country);
|
|
64
|
+
if (!data) return '';
|
|
65
|
+
return suggestSubdivision(data, geocoderName, GEOCODER_ALIASES[country.toUpperCase()]) ?? '';
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["nameOf","subdivisionsOf","suggestSubdivision","all","arAliases","GEOCODER_ALIASES","AR","countryData","country","undefined","toUpperCase","listStateOptions","locale","data","map","code","value","label","sort","a","b","localeCompare","suggestState","geocoderName","keepStateIfValid","state","includes"],"sourceRoot":"../../../src","sources":["utils/subdivisions.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SACEA,MAAM,EACNC,cAAc,EACdC,kBAAkB,QAGb,qBAAqB;AAC5B,OAAOC,GAAG,MAAM,mBAAmB;AACnC,OAAOC,SAAS,MAAM,2BAA2B;;AAEjD;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,gBAA2D,GAAG;EAClEC,EAAE,EAAEF;AACN,CAAC;AAED,SAASG,WAAWA,CAACC,OAAkC,EAA2B;EAChF,IAAI,CAACA,OAAO,EAAE,OAAOC,SAAS;EAC9B,OAAON,GAAG,CAACK,OAAO,CAACE,WAAW,CAAC,CAAC,CAAC;AACnC;AASA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAC9BH,OAAkC,EAClCI,MAAc,EACC;EACf,MAAMC,IAAI,GAAGN,WAAW,CAACC,OAAO,CAAC;EACjC,IAAI,CAACK,IAAI,EAAE,OAAO,EAAE;EACpB,OAAOZ,cAAc,CAACY,IAAI,CAAC,CACxBC,GAAG,CAAEC,IAAI,KAAM;IAAEC,KAAK,EAAED,IAAI;IAAEE,KAAK,EAAEjB,MAAM,CAACa,IAAI,EAAEE,IAAI,EAAEH,MAAM,CAAC,IAAIG;EAAK,CAAC,CAAC,CAAC,CAC3EG,IAAI,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAKD,CAAC,CAACF,KAAK,CAACI,aAAa,CAACD,CAAC,CAACH,KAAK,EAAEL,MAAM,CAAC,CAAC;AAC3D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASU,YAAYA,CAC1Bd,OAAkC,EAClCe,YAAuC,EAC/B;EACR,MAAMV,IAAI,GAAGN,WAAW,CAACC,OAAO,CAAC;EACjC,IAAI,CAACK,IAAI,EAAE,OAAO,EAAE;EACpB,OAAOX,kBAAkB,CAACW,IAAI,EAAEU,YAAY,EAAElB,gBAAgB,CAACG,OAAO,CAAEE,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE;AAC/F;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASc,gBAAgBA,CAC9BhB,OAAkC,EAClCiB,KAAgC,EACxB;EACR,MAAMZ,IAAI,GAAGN,WAAW,CAACC,OAAO,CAAC;EACjC,IAAI,CAACK,IAAI,IAAI,CAACY,KAAK,EAAE,OAAO,EAAE;EAC9B,OAAOxB,cAAc,CAACY,IAAI,CAAC,CAACa,QAAQ,CAACD,KAAK,CAAC,GAAGA,KAAK,GAAG,EAAE;AAC1D","ignoreList":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# Embedded @velion-la/geo
|
|
2
2
|
|
|
3
|
-
Copied by `scripts/vendor-geo.mjs` from `@velion-la/geo@1.0.0-alpha.
|
|
3
|
+
Copied by `scripts/vendor-geo.mjs` from `@velion-la/geo@1.0.0-alpha.4`. Do not edit:
|
|
4
4
|
these files are regenerated before every typecheck, test, build and pack. To change
|
|
5
5
|
the version, update the `@velion-la/geo` devDependency in `sdk/package.json`.
|
|
6
6
|
|
|
7
|
-
Only the modules the SDK imports are included: `all.js`, `data/countries.js`, `data/locales.js`, `geocoder/AR.js`, `index.js`, `normalize.js`, `countries/*.js` (249 countries).
|
|
7
|
+
Only the modules the SDK imports are included: `all.js`, `data/countries.js`, `data/locales.js`, `geocoder/AR.js`, `index.js`, `normalize.js`, `suggest.js`, `countries/*.js` (249 countries).
|
|
8
8
|
|
|
9
9
|
## Notice
|
|
10
10
|
|
|
@@ -2,34 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
// Generated by generator/generate.mjs from CLDR 49. Do not edit.
|
|
4
4
|
export default {
|
|
5
|
-
"autonomous city of buenos aires": "AR-C",
|
|
6
|
-
"buenos aires": "AR-B",
|
|
7
5
|
"caba": "AR-C",
|
|
8
6
|
"capital federal": "AR-C",
|
|
9
|
-
"catamarca": "AR-K",
|
|
10
|
-
"chaco": "AR-H",
|
|
11
|
-
"chubut": "AR-U",
|
|
12
|
-
"ciudad autonoma de buenos aires": "AR-C",
|
|
13
7
|
"ciudad de buenos aires": "AR-C",
|
|
14
|
-
"
|
|
15
|
-
"corrientes": "AR-W",
|
|
16
|
-
"entre rios": "AR-E",
|
|
17
|
-
"formosa": "AR-P",
|
|
18
|
-
"jujuy": "AR-Y",
|
|
19
|
-
"la pampa": "AR-L",
|
|
20
|
-
"la rioja": "AR-F",
|
|
21
|
-
"mendoza": "AR-M",
|
|
22
|
-
"misiones": "AR-N",
|
|
23
|
-
"neuquen": "AR-Q",
|
|
24
|
-
"rio negro": "AR-R",
|
|
25
|
-
"salta": "AR-A",
|
|
26
|
-
"san juan": "AR-J",
|
|
27
|
-
"san luis": "AR-D",
|
|
28
|
-
"santa cruz": "AR-Z",
|
|
29
|
-
"santa fe": "AR-S",
|
|
30
|
-
"santiago del estero": "AR-G",
|
|
31
|
-
"tierra del fuego": "AR-V",
|
|
32
|
-
"tierra del fuego antartida e islas del atlantico sur": "AR-V",
|
|
33
|
-
"tucuman": "AR-T"
|
|
8
|
+
"tierra del fuego antartida e islas del atlantico sur": "AR-V"
|
|
34
9
|
};
|
|
35
10
|
//# sourceMappingURL=AR.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../../../../src","sources":["vendor/geo/geocoder/AR.js"],"mappings":";;AAAA;AACA,eAAe;EAAC,
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../../../src","sources":["vendor/geo/geocoder/AR.js"],"mappings":";;AAAA;AACA,eAAe;EAAC,MAAM,EAAC,MAAM;EAAC,iBAAiB,EAAC,MAAM;EAAC,wBAAwB,EAAC,MAAM;EAAC,sDAAsD,EAAC;AAAM,CAAC","ignoreList":[]}
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
import countryData from './data/countries.js';
|
|
4
4
|
import supportedLocales from './data/locales.js';
|
|
5
5
|
import { normalize } from './normalize.js';
|
|
6
|
-
|
|
6
|
+
import { suggestSubdivision } from './suggest.js';
|
|
7
|
+
export { normalize, suggestSubdivision };
|
|
7
8
|
const FALLBACK_LOCALE = 'en';
|
|
8
9
|
const countrySet = new Set(countryData.codes);
|
|
9
10
|
|
|
@@ -85,13 +86,15 @@ export function nameOf(data, code, locale) {
|
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
89
|
+
* Looks the subdivision name a geocoder returned up in the country's geocoder aliases.
|
|
90
|
+
* Those hold only the spellings that are no subdivision's name ("CABA", "Capital
|
|
91
|
+
* Federal"), so this finds no "Córdoba" or "Andalucía": {@link suggestSubdivision} looks
|
|
92
|
+
* in the country's names as well.
|
|
91
93
|
*
|
|
94
|
+
* @deprecated Use {@link suggestSubdivision}, which also matches the country's names.
|
|
92
95
|
* @param {import('./types/geocoder.js').GeocoderAliases} aliases the country's aliases, from "@velion-la/geo/load" or "@velion-la/geo/geocoder/XX"
|
|
93
96
|
* @param {string | null | undefined} name the name as the geocoder returned it
|
|
94
|
-
* @returns {string | undefined} the code, or undefined when the name is
|
|
97
|
+
* @returns {string | undefined} the code, or undefined when the name is no alias
|
|
95
98
|
*/
|
|
96
99
|
export function fromGeocoderName(aliases, name) {
|
|
97
100
|
const key = normalize(name);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["countryData","supportedLocales","normalize","FALLBACK_LOCALE","countrySet","Set","codes","locales","Object","freeze","countries","language","locale","lang","toLowerCase","split","includes","isCountry","code","has","countryName","names","subdivisionsOf","data","childrenOf","parent","entries","subdivisions","filter","of","map","isSubdivision","state","hasOwn","nameOf","fromGeocoderName","aliases","name","key","undefined"],"sourceRoot":"../../../../src","sources":["vendor/geo/index.js"],"mappings":";;AAAA,OAAOA,WAAW,MAAM,qBAAqB;AAC7C,OAAOC,gBAAgB,MAAM,mBAAmB;AAChD,SAASC,SAAS,QAAQ,gBAAgB;
|
|
1
|
+
{"version":3,"names":["countryData","supportedLocales","normalize","suggestSubdivision","FALLBACK_LOCALE","countrySet","Set","codes","locales","Object","freeze","countries","language","locale","lang","toLowerCase","split","includes","isCountry","code","has","countryName","names","subdivisionsOf","data","childrenOf","parent","entries","subdivisions","filter","of","map","isSubdivision","state","hasOwn","nameOf","fromGeocoderName","aliases","name","key","undefined"],"sourceRoot":"../../../../src","sources":["vendor/geo/index.js"],"mappings":";;AAAA,OAAOA,WAAW,MAAM,qBAAqB;AAC7C,OAAOC,gBAAgB,MAAM,mBAAmB;AAChD,SAASC,SAAS,QAAQ,gBAAgB;AAC1C,SAASC,kBAAkB,QAAQ,cAAc;AAEjD,SAASD,SAAS,EAAEC,kBAAkB;AAEtC,MAAMC,eAAe,GAAG,IAAI;AAC5B,MAAMC,UAAU,GAAG,IAAIC,GAAG,CAACN,WAAW,CAACO,KAAK,CAAC;;AAE7C;AACA,OAAO,MAAMC,OAAO,GAAGC,MAAM,CAACC,MAAM,CAAC,CAAC,GAAGT,gBAAgB,CAAC,CAAC;;AAE3D;AACA,OAAO,MAAMU,SAAS,GAAGF,MAAM,CAACC,MAAM,CAAC,CAAC,GAAGV,WAAW,CAACO,KAAK,CAAC,CAAC;AAE9D,SAASK,QAAQA,CAACC,MAAM,EAAE;EACxB,MAAMC,IAAI,GAAG,CAACD,MAAM,IAAI,EAAE,EAAEE,WAAW,CAAC,CAAC,CAACC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;EAC1D,OAAOf,gBAAgB,CAACgB,QAAQ,CAACH,IAAI,CAAC,GAAGA,IAAI,GAAGV,eAAe;AACjE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASc,SAASA,CAACC,IAAI,EAAE;EAC9B,OAAOd,UAAU,CAACe,GAAG,CAACD,IAAI,CAAC;AAC7B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,WAAWA,CAACF,IAAI,EAAEN,MAAM,EAAE;EACxC,OAAOb,WAAW,CAACsB,KAAK,CAACV,QAAQ,CAACC,MAAM,CAAC,CAAC,CAACM,IAAI,CAAC;AAClD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASI,cAAcA,CAACC,IAAI,EAAE;EACnC,OAAOC,UAAU,CAACD,IAAI,EAAE,IAAI,CAAC;AAC/B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAACD,IAAI,EAAEE,MAAM,EAAE;EACvC,OAAOjB,MAAM,CAACkB,OAAO,CAACH,IAAI,CAACI,YAAY,CAAC,CACrCC,MAAM,CAAC,CAAC,GAAGC,EAAE,CAAC,KAAMJ,MAAM,KAAK,IAAI,GAAG,CAACI,EAAE,CAACb,QAAQ,CAAC,GAAG,CAAC,GAAGa,EAAE,KAAKJ,MAAO,CAAC,CACzEK,GAAG,CAAC,CAAC,CAACZ,IAAI,CAAC,KAAKA,IAAI,CAAC;AAC1B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASa,aAAaA,CAACR,IAAI,EAAES,KAAK,EAAE;EACzC,OAAO,CAACA,KAAK,IAAIxB,MAAM,CAACyB,MAAM,CAACV,IAAI,CAACI,YAAY,EAAEK,KAAK,CAAC;AAC1D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,MAAMA,CAACX,IAAI,EAAEL,IAAI,EAAEN,MAAM,EAAE;EACzC,OAAOW,IAAI,CAACF,KAAK,CAACV,QAAQ,CAACC,MAAM,CAAC,CAAC,CAACM,IAAI,CAAC;AAC3C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASiB,gBAAgBA,CAACC,OAAO,EAAEC,IAAI,EAAE;EAC9C,MAAMC,GAAG,GAAGrC,SAAS,CAACoC,IAAI,CAAC;EAC3B,OAAOC,GAAG,IAAI9B,MAAM,CAACyB,MAAM,CAACG,OAAO,EAAEE,GAAG,CAAC,GAAGF,OAAO,CAACE,GAAG,CAAC,GAAGC,SAAS;AACtE","ignoreList":[]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { normalize } from './normalize.js';
|
|
4
|
+
|
|
5
|
+
// One index per loaded country object. A WeakMap keeps it as long as the app keeps the
|
|
6
|
+
// country: importing "@velion-la/geo/all" and suggesting in every country does not pin
|
|
7
|
+
// 249 indexes once the data is gone.
|
|
8
|
+
const indexes = new WeakMap();
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Normalized name → ISO 3166-2 code, from every name of every subdivision in every locale.
|
|
12
|
+
* A normalized name shared by two subdivisions of the same country maps to null: the
|
|
13
|
+
* generator drops it from the geocoder table too, rather than guess.
|
|
14
|
+
*
|
|
15
|
+
* @param {import('./types/country.js').CountryData} data loaded country
|
|
16
|
+
* @returns {Map<string, string | null>}
|
|
17
|
+
*/
|
|
18
|
+
export function nameIndex(data) {
|
|
19
|
+
let index = indexes.get(data);
|
|
20
|
+
if (!index) {
|
|
21
|
+
index = new Map();
|
|
22
|
+
for (const code of Object.keys(data.subdivisions)) {
|
|
23
|
+
for (const names of Object.values(data.names)) {
|
|
24
|
+
const key = normalize(names[code]);
|
|
25
|
+
if (key) {
|
|
26
|
+
index.set(key, index.has(key) && index.get(key) !== code ? null : code);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
indexes.set(data, index);
|
|
31
|
+
}
|
|
32
|
+
return index;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Suggests the subdivision for the name a geocoder returned (Google's
|
|
37
|
+
* administrative_area_level_1, the platform geocoder's region), using the country's own
|
|
38
|
+
* names: "Andalucía" in Spain is ES-AN, "Provincia de Córdoba" in Argentina is AR-X. The
|
|
39
|
+
* aliases, when given, are tried first; they hold the spellings providers use that are no
|
|
40
|
+
* subdivision's name, such as "CABA". The result is a suggestion: the user still confirms it.
|
|
41
|
+
*
|
|
42
|
+
* @param {import('./types/country.js').CountryData} data the country of the address
|
|
43
|
+
* @param {string | null | undefined} name the name as the geocoder returned it
|
|
44
|
+
* @param {import('./types/geocoder.js').GeocoderAliases} [aliases] the country's aliases, from "@velion-la/geo/load" or "@velion-la/geo/geocoder/XX"
|
|
45
|
+
* @returns {string | undefined} the code, or undefined when the name is unknown or matches more than one subdivision
|
|
46
|
+
*/
|
|
47
|
+
export function suggestSubdivision(data, name, aliases) {
|
|
48
|
+
const key = normalize(name);
|
|
49
|
+
if (!key) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
if (aliases && Object.hasOwn(aliases, key)) {
|
|
53
|
+
return aliases[key];
|
|
54
|
+
}
|
|
55
|
+
return nameIndex(data).get(key) ?? undefined;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=suggest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["normalize","indexes","WeakMap","nameIndex","data","index","get","Map","code","Object","keys","subdivisions","names","values","key","set","has","suggestSubdivision","name","aliases","undefined","hasOwn"],"sourceRoot":"../../../../src","sources":["vendor/geo/suggest.js"],"mappings":";;AAAA,SAASA,SAAS,QAAQ,gBAAgB;;AAE1C;AACA;AACA;AACA,MAAMC,OAAO,GAAG,IAAIC,OAAO,CAAC,CAAC;;AAE7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,SAASA,CAACC,IAAI,EAAE;EAC9B,IAAIC,KAAK,GAAGJ,OAAO,CAACK,GAAG,CAACF,IAAI,CAAC;EAC7B,IAAI,CAACC,KAAK,EAAE;IACVA,KAAK,GAAG,IAAIE,GAAG,CAAC,CAAC;IACjB,KAAK,MAAMC,IAAI,IAAIC,MAAM,CAACC,IAAI,CAACN,IAAI,CAACO,YAAY,CAAC,EAAE;MACjD,KAAK,MAAMC,KAAK,IAAIH,MAAM,CAACI,MAAM,CAACT,IAAI,CAACQ,KAAK,CAAC,EAAE;QAC7C,MAAME,GAAG,GAAGd,SAAS,CAACY,KAAK,CAACJ,IAAI,CAAC,CAAC;QAClC,IAAIM,GAAG,EAAE;UACPT,KAAK,CAACU,GAAG,CAACD,GAAG,EAAET,KAAK,CAACW,GAAG,CAACF,GAAG,CAAC,IAAIT,KAAK,CAACC,GAAG,CAACQ,GAAG,CAAC,KAAKN,IAAI,GAAG,IAAI,GAAGA,IAAI,CAAC;QACzE;MACF;IACF;IACAP,OAAO,CAACc,GAAG,CAACX,IAAI,EAAEC,KAAK,CAAC;EAC1B;EACA,OAAOA,KAAK;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASY,kBAAkBA,CAACb,IAAI,EAAEc,IAAI,EAAEC,OAAO,EAAE;EACtD,MAAML,GAAG,GAAGd,SAAS,CAACkB,IAAI,CAAC;EAC3B,IAAI,CAACJ,GAAG,EAAE;IACR,OAAOM,SAAS;EAClB;EACA,IAAID,OAAO,IAAIV,MAAM,CAACY,MAAM,CAACF,OAAO,EAAEL,GAAG,CAAC,EAAE;IAC1C,OAAOK,OAAO,CAACL,GAAG,CAAC;EACrB;EACA,OAAOX,SAAS,CAACC,IAAI,CAAC,CAACE,GAAG,CAACQ,GAAG,CAAC,IAAIM,SAAS;AAC9C","ignoreList":[]}
|
|
@@ -31,8 +31,11 @@ export declare function listStateOptions(country: string | null | undefined, loc
|
|
|
31
31
|
* (Google's `administrative_area_level_1`, the platform geocoder's `region`).
|
|
32
32
|
* It only preselects the picker: the user still confirms or changes it.
|
|
33
33
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
34
|
+
* Matches the country's curated aliases first, then its subdivision names in
|
|
35
|
+
* every locale.
|
|
36
|
+
*
|
|
37
|
+
* @returns the code, or `''` when the name or country is unknown, or the name
|
|
38
|
+
* is ambiguous.
|
|
36
39
|
*/
|
|
37
40
|
export declare function suggestState(country: string | null | undefined, geocoderName: string | null | undefined): string;
|
|
38
41
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subdivisions.d.ts","sourceRoot":"","sources":["../../../src/utils/subdivisions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA2BH,MAAM,WAAW,WAAW;IAC1B,8EAA8E;IAC9E,KAAK,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAClC,MAAM,EAAE,MAAM,GACb,WAAW,EAAE,CAMf;AAED
|
|
1
|
+
{"version":3,"file":"subdivisions.d.ts","sourceRoot":"","sources":["../../../src/utils/subdivisions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA2BH,MAAM,WAAW,WAAW;IAC1B,8EAA8E;IAC9E,KAAK,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAClC,MAAM,EAAE,MAAM,GACb,WAAW,EAAE,CAMf;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAClC,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GACtC,MAAM,CAIR;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAClC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAC/B,MAAM,CAIR"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@velion-la/onboarding-sdk-react-native",
|
|
3
|
-
"version": "1.3.0-beta.
|
|
3
|
+
"version": "1.3.0-beta.23",
|
|
4
4
|
"description": "Native React Native SDK for the Velion Onboarding (KYC) flow: ID document OCR, passive + active liveness, device fingerprint, OTP verification, address picker, and personal / legal information forms.",
|
|
5
5
|
"main": "./lib/commonjs/index.js",
|
|
6
6
|
"module": "./lib/module/index.js",
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
"devDependencies": {
|
|
111
111
|
"@types/jest": "^29.5.12",
|
|
112
112
|
"@types/react": "~19.2.0",
|
|
113
|
-
"@velion-la/geo": "1.0.0-alpha.
|
|
113
|
+
"@velion-la/geo": "1.0.0-alpha.4",
|
|
114
114
|
"del-cli": "^6.0.0",
|
|
115
115
|
"jest": "^29.7.0",
|
|
116
116
|
"react-native-builder-bob": "^0.40.0",
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
import {
|
|
19
|
-
fromGeocoderName,
|
|
20
19
|
nameOf,
|
|
21
20
|
subdivisionsOf,
|
|
21
|
+
suggestSubdivision,
|
|
22
22
|
type CountryData,
|
|
23
23
|
type GeocoderAliases,
|
|
24
24
|
} from '../vendor/geo/index';
|
|
@@ -26,10 +26,10 @@ import all from '../vendor/geo/all';
|
|
|
26
26
|
import arAliases from '../vendor/geo/geocoder/AR';
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* `ENTRIES` of `scripts/vendor-geo.mjs`.
|
|
29
|
+
* Curated geocoder spellings that are no subdivision's name (e.g. "Capital
|
|
30
|
+
* Federal"). Plain names are matched in every country without them. Only AR
|
|
31
|
+
* has entries in geo; a country added to geo's `sources/geocoder.json` needs
|
|
32
|
+
* its import here and in `ENTRIES` of `scripts/vendor-geo.mjs`.
|
|
33
33
|
*/
|
|
34
34
|
const GEOCODER_ALIASES: Readonly<Record<string, GeocoderAliases>> = {
|
|
35
35
|
AR: arAliases,
|
|
@@ -68,16 +68,19 @@ export function listStateOptions(
|
|
|
68
68
|
* (Google's `administrative_area_level_1`, the platform geocoder's `region`).
|
|
69
69
|
* It only preselects the picker: the user still confirms or changes it.
|
|
70
70
|
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
71
|
+
* Matches the country's curated aliases first, then its subdivision names in
|
|
72
|
+
* every locale.
|
|
73
|
+
*
|
|
74
|
+
* @returns the code, or `''` when the name or country is unknown, or the name
|
|
75
|
+
* is ambiguous.
|
|
73
76
|
*/
|
|
74
77
|
export function suggestState(
|
|
75
78
|
country: string | null | undefined,
|
|
76
79
|
geocoderName: string | null | undefined,
|
|
77
80
|
): string {
|
|
78
|
-
const
|
|
79
|
-
if (!
|
|
80
|
-
return
|
|
81
|
+
const data = countryData(country);
|
|
82
|
+
if (!data) return '';
|
|
83
|
+
return suggestSubdivision(data, geocoderName, GEOCODER_ALIASES[country!.toUpperCase()]) ?? '';
|
|
81
84
|
}
|
|
82
85
|
|
|
83
86
|
/**
|
package/src/vendor/geo/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# Embedded @velion-la/geo
|
|
2
2
|
|
|
3
|
-
Copied by `scripts/vendor-geo.mjs` from `@velion-la/geo@1.0.0-alpha.
|
|
3
|
+
Copied by `scripts/vendor-geo.mjs` from `@velion-la/geo@1.0.0-alpha.4`. Do not edit:
|
|
4
4
|
these files are regenerated before every typecheck, test, build and pack. To change
|
|
5
5
|
the version, update the `@velion-la/geo` devDependency in `sdk/package.json`.
|
|
6
6
|
|
|
7
|
-
Only the modules the SDK imports are included: `all.js`, `data/countries.js`, `data/locales.js`, `geocoder/AR.js`, `index.js`, `normalize.js`, `countries/*.js` (249 countries).
|
|
7
|
+
Only the modules the SDK imports are included: `all.js`, `data/countries.js`, `data/locales.js`, `geocoder/AR.js`, `index.js`, `normalize.js`, `suggest.js`, `countries/*.js` (249 countries).
|
|
8
8
|
|
|
9
9
|
## Notice
|
|
10
10
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by generator/generate.mjs from CLDR 49. Do not edit.
|
|
2
|
-
export default {"
|
|
2
|
+
export default {"caba":"AR-C","capital federal":"AR-C","ciudad de buenos aires":"AR-C","tierra del fuego antartida e islas del atlantico sur":"AR-V"};
|
package/src/vendor/geo/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import countryData from './data/countries.js';
|
|
2
2
|
import supportedLocales from './data/locales.js';
|
|
3
3
|
import { normalize } from './normalize.js';
|
|
4
|
+
import { suggestSubdivision } from './suggest.js';
|
|
4
5
|
|
|
5
|
-
export { normalize };
|
|
6
|
+
export { normalize, suggestSubdivision };
|
|
6
7
|
|
|
7
8
|
const FALLBACK_LOCALE = 'en';
|
|
8
9
|
const countrySet = new Set(countryData.codes);
|
|
@@ -88,13 +89,15 @@ export function nameOf(data, code, locale) {
|
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
92
|
+
* Looks the subdivision name a geocoder returned up in the country's geocoder aliases.
|
|
93
|
+
* Those hold only the spellings that are no subdivision's name ("CABA", "Capital
|
|
94
|
+
* Federal"), so this finds no "Córdoba" or "Andalucía": {@link suggestSubdivision} looks
|
|
95
|
+
* in the country's names as well.
|
|
94
96
|
*
|
|
97
|
+
* @deprecated Use {@link suggestSubdivision}, which also matches the country's names.
|
|
95
98
|
* @param {import('./types/geocoder.js').GeocoderAliases} aliases the country's aliases, from "@velion-la/geo/load" or "@velion-la/geo/geocoder/XX"
|
|
96
99
|
* @param {string | null | undefined} name the name as the geocoder returned it
|
|
97
|
-
* @returns {string | undefined} the code, or undefined when the name is
|
|
100
|
+
* @returns {string | undefined} the code, or undefined when the name is no alias
|
|
98
101
|
*/
|
|
99
102
|
export function fromGeocoderName(aliases, name) {
|
|
100
103
|
const key = normalize(name);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { normalize } from './normalize.js';
|
|
2
|
+
|
|
3
|
+
// One index per loaded country object. A WeakMap keeps it as long as the app keeps the
|
|
4
|
+
// country: importing "@velion-la/geo/all" and suggesting in every country does not pin
|
|
5
|
+
// 249 indexes once the data is gone.
|
|
6
|
+
const indexes = new WeakMap();
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Normalized name → ISO 3166-2 code, from every name of every subdivision in every locale.
|
|
10
|
+
* A normalized name shared by two subdivisions of the same country maps to null: the
|
|
11
|
+
* generator drops it from the geocoder table too, rather than guess.
|
|
12
|
+
*
|
|
13
|
+
* @param {import('./types/country.js').CountryData} data loaded country
|
|
14
|
+
* @returns {Map<string, string | null>}
|
|
15
|
+
*/
|
|
16
|
+
export function nameIndex(data) {
|
|
17
|
+
let index = indexes.get(data);
|
|
18
|
+
if (!index) {
|
|
19
|
+
index = new Map();
|
|
20
|
+
for (const code of Object.keys(data.subdivisions)) {
|
|
21
|
+
for (const names of Object.values(data.names)) {
|
|
22
|
+
const key = normalize(names[code]);
|
|
23
|
+
if (key) {
|
|
24
|
+
index.set(key, index.has(key) && index.get(key) !== code ? null : code);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
indexes.set(data, index);
|
|
29
|
+
}
|
|
30
|
+
return index;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Suggests the subdivision for the name a geocoder returned (Google's
|
|
35
|
+
* administrative_area_level_1, the platform geocoder's region), using the country's own
|
|
36
|
+
* names: "Andalucía" in Spain is ES-AN, "Provincia de Córdoba" in Argentina is AR-X. The
|
|
37
|
+
* aliases, when given, are tried first; they hold the spellings providers use that are no
|
|
38
|
+
* subdivision's name, such as "CABA". The result is a suggestion: the user still confirms it.
|
|
39
|
+
*
|
|
40
|
+
* @param {import('./types/country.js').CountryData} data the country of the address
|
|
41
|
+
* @param {string | null | undefined} name the name as the geocoder returned it
|
|
42
|
+
* @param {import('./types/geocoder.js').GeocoderAliases} [aliases] the country's aliases, from "@velion-la/geo/load" or "@velion-la/geo/geocoder/XX"
|
|
43
|
+
* @returns {string | undefined} the code, or undefined when the name is unknown or matches more than one subdivision
|
|
44
|
+
*/
|
|
45
|
+
export function suggestSubdivision(data, name, aliases) {
|
|
46
|
+
const key = normalize(name);
|
|
47
|
+
if (!key) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
if (aliases && Object.hasOwn(aliases, key)) {
|
|
51
|
+
return aliases[key];
|
|
52
|
+
}
|
|
53
|
+
return nameIndex(data).get(key) ?? undefined;
|
|
54
|
+
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Normalized geocoder spelling → ISO 3166-2 code, for one country: only the spellings that
|
|
3
|
+
* are no subdivision's name ("caba"), empty for most countries. The names themselves are
|
|
4
|
+
* matched from the country data by `suggestSubdivision`.
|
|
5
|
+
*/
|
|
2
6
|
export type GeocoderAliases = Readonly<Record<string, string>>;
|
|
3
7
|
|
|
4
8
|
declare const aliases: GeocoderAliases;
|
|
@@ -30,5 +30,20 @@ export declare function isSubdivision(data: CountryData, state: string | null |
|
|
|
30
30
|
/** Name of the country or one of its subdivisions in the given locale. */
|
|
31
31
|
export declare function nameOf(data: CountryData, code: string, locale?: string): string | undefined;
|
|
32
32
|
|
|
33
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* ISO 3166-2 code suggested for a geocoder's subdivision name, from the aliases when given
|
|
35
|
+
* and then from the country's names in every locale; undefined when unknown or ambiguous.
|
|
36
|
+
*/
|
|
37
|
+
export declare function suggestSubdivision(
|
|
38
|
+
data: CountryData,
|
|
39
|
+
name: string | null | undefined,
|
|
40
|
+
aliases?: GeocoderAliases,
|
|
41
|
+
): string | undefined;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* ISO 3166-2 code of a geocoder alias; undefined when the name is no alias. The aliases hold
|
|
45
|
+
* only spellings that are no subdivision's name, so plain names are not found.
|
|
46
|
+
*
|
|
47
|
+
* @deprecated Use {@link suggestSubdivision}, which also matches the country's names.
|
|
48
|
+
*/
|
|
34
49
|
export declare function fromGeocoderName(aliases: GeocoderAliases, name: string | null | undefined): string | undefined;
|