localized-regions 1.0.0 → 1.0.2

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/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import { Country, CountryOption, Province, City, Option } from './types';
2
2
  /**
3
3
  * All countries. Pass a locale (e.g. "es") to get bilingual labels like
4
- * "Spain (España)". Omit or pass "en" for English-only labels.
4
+ * "España (Spain)". Omit or pass "en" for English-only labels.
5
5
  */
6
6
  export declare function getCountries(opts?: {
7
7
  locale?: string;
8
8
  }): CountryOption[];
9
9
  export declare function getCountry(code: string): Country | undefined;
10
- /** Bilingual (or English) display label for a single country code. */
10
+ /** Bilingual (Native (English)) or native-only display label for a single country code. */
11
11
  export declare function formatCountryLabel(code: string, locale?: string): string;
12
12
  /**
13
13
  * Provinces for a country. Spain returns the curated 50 Provinces (RAT-1776);
package/dist/index.js CHANGED
@@ -10,31 +10,12 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
10
10
  if (k2 === undefined) k2 = k;
11
11
  o[k2] = m[k];
12
12
  }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
15
  };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
38
19
  Object.defineProperty(exports, "__esModule", { value: true });
39
20
  exports.getCountries = getCountries;
40
21
  exports.getCountry = getCountry;
@@ -45,15 +26,12 @@ exports.getCities = getCities;
45
26
  exports.countryOptions = countryOptions;
46
27
  exports.provinceOptions = provinceOptions;
47
28
  exports.cityOptions = cityOptions;
48
- const path = __importStar(require("path"));
49
29
  const country_state_city_1 = require("country-state-city");
50
- const DATA = path.join(__dirname, '..', 'data');
51
- // Static, build-time generated data (see scripts/generate.js). Loaded at runtime
52
- // so tsc does not need to copy JSON into dist.
53
- // eslint-disable-next-line @typescript-eslint/no-var-requires
54
- const countries = require(path.join(DATA, 'countries.json'));
55
- // eslint-disable-next-line @typescript-eslint/no-var-requires
56
- const provinces = require(path.join(DATA, 'provinces.json'));
30
+ // Static, build-time generated data (see scripts/generate.js). Imported statically
31
+ // so the data bundles cleanly in browser bundlers (webpack/vite) with no Node `path`
32
+ // or dynamic `require`.
33
+ const countries_1 = __importDefault(require("./data/countries"));
34
+ const provinces_1 = __importDefault(require("./data/provinces"));
57
35
  function displayName(code, locale) {
58
36
  try {
59
37
  return new Intl.DisplayNames([locale], { type: 'region' }).of(code) || undefined;
@@ -63,23 +41,23 @@ function displayName(code, locale) {
63
41
  }
64
42
  }
65
43
  function buildLabel(name, localized) {
66
- return localized && localized !== name ? `${name} (${localized})` : name;
44
+ return localized && localized !== name ? `${localized} (${name})` : name;
67
45
  }
68
46
  /**
69
47
  * All countries. Pass a locale (e.g. "es") to get bilingual labels like
70
- * "Spain (España)". Omit or pass "en" for English-only labels.
48
+ * "España (Spain)". Omit or pass "en" for English-only labels.
71
49
  */
72
50
  function getCountries(opts = {}) {
73
51
  const { locale } = opts;
74
- return countries.map((c) => {
52
+ return countries_1.default.map((c) => {
75
53
  const localized = locale && locale !== 'en' ? displayName(c.code, locale) : undefined;
76
54
  return { code: c.code, name: c.name, localized, label: buildLabel(c.name, localized) };
77
55
  });
78
56
  }
79
57
  function getCountry(code) {
80
- return countries.find((c) => c.code === code.toUpperCase());
58
+ return countries_1.default.find((c) => c.code === code.toUpperCase());
81
59
  }
82
- /** Bilingual (or English) display label for a single country code. */
60
+ /** Bilingual (Native (English)) or native-only display label for a single country code. */
83
61
  function formatCountryLabel(code, locale) {
84
62
  const c = getCountry(code);
85
63
  if (!c)
@@ -92,7 +70,7 @@ function formatCountryLabel(code, locale) {
92
70
  * other countries return their ISO 3166-2 subdivisions.
93
71
  */
94
72
  function getProvinces(countryCode) {
95
- return provinces[countryCode.toUpperCase()] || [];
73
+ return provinces_1.default[countryCode.toUpperCase()] || [];
96
74
  }
97
75
  function getProvince(provinceCode) {
98
76
  const cc = provinceCode.split('-')[0];
package/dist/types.d.ts CHANGED
@@ -10,7 +10,7 @@ export interface CountryOption {
10
10
  name: string;
11
11
  /** Name in the requested locale, e.g. "España" (undefined when locale is en/absent) */
12
12
  localized?: string;
13
- /** Display label, e.g. "Spain (España)" when localized, else "Spain" */
13
+ /** Display label, e.g. "España (Spain)" when localized, else "Spain" */
14
14
  label: string;
15
15
  }
16
16
  export interface Province {
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "localized-regions",
3
- "version": "1.0.0",
4
- "description": "Country, province and city data with bilingual localized labels (e.g. \"Spain (España)\") and ISO 3166-1 / ISO 3166-2 codes. Ships all 50 Spanish provinces. Framework-agnostic, drop-in options for react-select and MUI dropdowns.",
3
+ "version": "1.0.2",
4
+ "description": "Country, province and city data with bilingual localized labels (e.g. \"España (Spain)\") and ISO 3166-1 / ISO 3166-2 codes. Ships all 50 Spanish provinces. Framework-agnostic, drop-in options for react-select and MUI dropdowns.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
8
8
  "dist",
9
- "data",
10
9
  "README.md",
11
10
  "LICENSE"
12
11
  ],