@cobre-npm/library-portal-core 0.54.0 → 0.55.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.
- package/README.md +22 -7
- package/dist/cjs/countries/base/utils/country.utils.d.ts +7 -0
- package/dist/cjs/countries/base/utils/country.utils.js +9 -1
- package/dist/cjs/countries/iso/utils/country-iso.utils.d.ts +7 -0
- package/dist/cjs/countries/iso/utils/country-iso.utils.js +9 -1
- package/dist/esm/countries/base/utils/country.utils.js +7 -0
- package/dist/esm/countries/iso/utils/country-iso.utils.js +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -221,19 +221,34 @@ Groups two catalogs:
|
|
|
221
221
|
|
|
222
222
|
```ts
|
|
223
223
|
import {
|
|
224
|
-
getCountries, type Country, type CountryOption,
|
|
225
|
-
getCountriesISO, getIndicativesWithCodes, hasCountryISOFlag,
|
|
226
|
-
type CountryISO, type CountryISOOption, type IndicativeWithCode,
|
|
224
|
+
getCountries, queryCountries, type Country, type CountryOption, type CountryQuery,
|
|
225
|
+
getCountriesISO, queryCountriesISO, getIndicativesWithCodes, hasCountryISOFlag,
|
|
226
|
+
type CountryISO, type CountryISOOption, type CountryISOQuery, type IndicativeWithCode,
|
|
227
227
|
} from "@cobre-npm/library-portal-core/countries"
|
|
228
228
|
|
|
229
|
-
getCountries("en").col.label
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
229
|
+
getCountries("en").col.label // "Colombia"
|
|
230
|
+
queryCountries({ lang: "en", code: ["mex", "col"] }) // [ mex, col ] → the list a picker needs
|
|
231
|
+
getCountriesISO("en").col // { code:"col", isoCode:"COL", indicative:"+57", label:"Colombia" }
|
|
232
|
+
queryCountriesISO({ lang: "en", isoCode: "MEX" }) // [ mex ] → filter the full ISO catalog
|
|
233
|
+
getIndicativesWithCodes("en") // view-model for a phone dialing-code selector
|
|
234
|
+
hasCountryISOFlag("col") // true — whether a flag asset is available
|
|
233
235
|
```
|
|
234
236
|
|
|
235
237
|
- **base** (i18n): business countries (`col`, `mex`, `usa`, `global`, …).
|
|
238
|
+
`queryCountries({ lang, ... })` returns the same catalog as a **list**, narrowed by `code` — same
|
|
239
|
+
matching rules as [`queryAccountTypes`](#accounts): `lang` is required (i18n domain, no default) inside
|
|
240
|
+
the query object, and there is no default field.
|
|
236
241
|
- **iso** (i18n): full ISO catalog (~249 countries) with `isoCode` and `indicative`.
|
|
242
|
+
`queryCountriesISO({ lang, ... })` returns the same catalog as a **list**, narrowed by `code`/`isoCode`
|
|
243
|
+
— same rules as above, over the full ISO catalog instead of the small business one.
|
|
244
|
+
|
|
245
|
+
As with every `queryX()`, **a key that is present always filters** — it's the absence of the key that
|
|
246
|
+
doesn't. So `queryCountries({ lang, code: undefined })` returns `[]`, not "no filter". An optional UI
|
|
247
|
+
filter has to be spread in conditionally:
|
|
248
|
+
|
|
249
|
+
```ts
|
|
250
|
+
queryCountries({ lang, ...(codes ? { code: codes } : {}) })
|
|
251
|
+
```
|
|
237
252
|
|
|
238
253
|
### `movements`
|
|
239
254
|
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import type { Country, CountryRecord } from "../catalog";
|
|
2
2
|
import type { Locale } from "../../../lang";
|
|
3
|
+
import type { CatalogQuery } from "../../../utils/catalog-query.utils";
|
|
3
4
|
export type CountryOption = CountryRecord & {
|
|
4
5
|
label: string;
|
|
5
6
|
};
|
|
6
7
|
export declare const getCountries: (lang: Locale) => Record<Country, CountryOption>;
|
|
8
|
+
/** `lang` is required (i18n domain, no default) and travels inside the query object, never positional. */
|
|
9
|
+
export type CountryQuery = CatalogQuery<CountryRecord> & {
|
|
10
|
+
lang: Locale;
|
|
11
|
+
};
|
|
12
|
+
/** The catalog as a list, narrowed by the query — see `matchesQuery` for the matching rules. */
|
|
13
|
+
export declare const queryCountries: (query: CountryQuery) => CountryOption[];
|
|
@@ -3,10 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getCountries = void 0;
|
|
6
|
+
exports.queryCountries = exports.getCountries = void 0;
|
|
7
7
|
const catalog_1 = require("../catalog");
|
|
8
8
|
const en_json_1 = __importDefault(require("../locales/en.json"));
|
|
9
9
|
const es_mex_json_1 = __importDefault(require("../locales/es-mex.json"));
|
|
10
|
+
const catalog_query_utils_1 = require("../../../utils/catalog-query.utils");
|
|
10
11
|
const locales = { en: en_json_1.default, "es-mex": es_mex_json_1.default };
|
|
11
12
|
const getCountries = (lang) => {
|
|
12
13
|
const locale = locales[lang];
|
|
@@ -17,3 +18,10 @@ const getCountries = (lang) => {
|
|
|
17
18
|
return result;
|
|
18
19
|
};
|
|
19
20
|
exports.getCountries = getCountries;
|
|
21
|
+
/** The catalog as a list, narrowed by the query — see `matchesQuery` for the matching rules. */
|
|
22
|
+
const queryCountries = (query) => {
|
|
23
|
+
const { lang, ...criteria } = query;
|
|
24
|
+
const countries = (0, exports.getCountries)(lang);
|
|
25
|
+
return Object.values(countries).filter(country => (0, catalog_query_utils_1.matchesQuery)(country, criteria));
|
|
26
|
+
};
|
|
27
|
+
exports.queryCountries = queryCountries;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CountryISO, CountryISORecord } from "../catalog";
|
|
2
2
|
import type { Locale } from "../../../lang";
|
|
3
|
+
import type { CatalogQuery } from "../../../utils/catalog-query.utils";
|
|
3
4
|
export declare const hasCountryISOFlag: (code: CountryISO) => boolean;
|
|
4
5
|
export type CountryISOOption = CountryISORecord & {
|
|
5
6
|
label: string;
|
|
@@ -12,4 +13,10 @@ export interface IndicativeWithCode {
|
|
|
12
13
|
isoCode: string | undefined;
|
|
13
14
|
}
|
|
14
15
|
export declare const getCountriesISO: (lang: Locale) => Record<CountryISO, CountryISOOption>;
|
|
16
|
+
/** `lang` is required (i18n domain, no default) and travels inside the query object, never positional. */
|
|
17
|
+
export type CountryISOQuery = CatalogQuery<CountryISORecord> & {
|
|
18
|
+
lang: Locale;
|
|
19
|
+
};
|
|
20
|
+
/** The catalog as a list, narrowed by the query — see `matchesQuery` for the matching rules. */
|
|
21
|
+
export declare const queryCountriesISO: (query: CountryISOQuery) => CountryISOOption[];
|
|
15
22
|
export declare const getIndicativesWithCodes: (lang: Locale) => IndicativeWithCode[];
|
|
@@ -3,10 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getIndicativesWithCodes = exports.getCountriesISO = exports.hasCountryISOFlag = void 0;
|
|
6
|
+
exports.getIndicativesWithCodes = exports.queryCountriesISO = exports.getCountriesISO = exports.hasCountryISOFlag = void 0;
|
|
7
7
|
const catalog_1 = require("../catalog");
|
|
8
8
|
const en_json_1 = __importDefault(require("../locales/en.json"));
|
|
9
9
|
const es_mex_json_1 = __importDefault(require("../locales/es-mex.json"));
|
|
10
|
+
const catalog_query_utils_1 = require("../../../utils/catalog-query.utils");
|
|
10
11
|
const locales = { en: en_json_1.default, "es-mex": es_mex_json_1.default };
|
|
11
12
|
const AVAILABLE_FLAG_CODES = new Set(["col", "mex", "usa"]);
|
|
12
13
|
const hasCountryISOFlag = (code) => AVAILABLE_FLAG_CODES.has(code);
|
|
@@ -20,6 +21,13 @@ const getCountriesISO = (lang) => {
|
|
|
20
21
|
return result;
|
|
21
22
|
};
|
|
22
23
|
exports.getCountriesISO = getCountriesISO;
|
|
24
|
+
/** The catalog as a list, narrowed by the query — see `matchesQuery` for the matching rules. */
|
|
25
|
+
const queryCountriesISO = (query) => {
|
|
26
|
+
const { lang, ...criteria } = query;
|
|
27
|
+
const countries = (0, exports.getCountriesISO)(lang);
|
|
28
|
+
return Object.values(countries).filter(country => (0, catalog_query_utils_1.matchesQuery)(country, criteria));
|
|
29
|
+
};
|
|
30
|
+
exports.queryCountriesISO = queryCountriesISO;
|
|
23
31
|
const getIndicativesWithCodes = (lang) => {
|
|
24
32
|
const locale = locales[lang];
|
|
25
33
|
const seenDialCodes = new Set();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { COUNTRIES } from "../catalog";
|
|
2
2
|
import enLocale from "../locales/en.json";
|
|
3
3
|
import esMexLocale from "../locales/es-mex.json";
|
|
4
|
+
import { matchesQuery } from "../../../utils/catalog-query.utils";
|
|
4
5
|
const locales = { en: enLocale, "es-mex": esMexLocale };
|
|
5
6
|
export const getCountries = (lang) => {
|
|
6
7
|
const locale = locales[lang];
|
|
@@ -10,3 +11,9 @@ export const getCountries = (lang) => {
|
|
|
10
11
|
}
|
|
11
12
|
return result;
|
|
12
13
|
};
|
|
14
|
+
/** The catalog as a list, narrowed by the query — see `matchesQuery` for the matching rules. */
|
|
15
|
+
export const queryCountries = (query) => {
|
|
16
|
+
const { lang, ...criteria } = query;
|
|
17
|
+
const countries = getCountries(lang);
|
|
18
|
+
return Object.values(countries).filter(country => matchesQuery(country, criteria));
|
|
19
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { COUNTRIES_ISO } from "../catalog";
|
|
2
2
|
import enLocale from "../locales/en.json";
|
|
3
3
|
import esMexLocale from "../locales/es-mex.json";
|
|
4
|
+
import { matchesQuery } from "../../../utils/catalog-query.utils";
|
|
4
5
|
const locales = { en: enLocale, "es-mex": esMexLocale };
|
|
5
6
|
const AVAILABLE_FLAG_CODES = new Set(["col", "mex", "usa"]);
|
|
6
7
|
export const hasCountryISOFlag = (code) => AVAILABLE_FLAG_CODES.has(code);
|
|
@@ -12,6 +13,12 @@ export const getCountriesISO = (lang) => {
|
|
|
12
13
|
}
|
|
13
14
|
return result;
|
|
14
15
|
};
|
|
16
|
+
/** The catalog as a list, narrowed by the query — see `matchesQuery` for the matching rules. */
|
|
17
|
+
export const queryCountriesISO = (query) => {
|
|
18
|
+
const { lang, ...criteria } = query;
|
|
19
|
+
const countries = getCountriesISO(lang);
|
|
20
|
+
return Object.values(countries).filter(country => matchesQuery(country, criteria));
|
|
21
|
+
};
|
|
15
22
|
export const getIndicativesWithCodes = (lang) => {
|
|
16
23
|
const locale = locales[lang];
|
|
17
24
|
const seenDialCodes = new Set();
|