@tw-labs/countries 0.0.1 → 0.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/README.md +23 -34
- package/dist/chunk-TGO6OI3L.mjs +2927 -0
- package/dist/chunk-TGO6OI3L.mjs.map +1 -0
- package/dist/data.d.cts +1 -1
- package/dist/data.d.ts +1 -1
- package/dist/data.js +2646 -249
- package/dist/data.js.map +1 -1
- package/dist/data.mjs +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +2666 -268
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -4
- package/dist/index.mjs.map +1 -1
- package/dist/react.js +2646 -249
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +2646 -249
- package/dist/react.mjs.map +1 -1
- package/dist/{types-Dte-oYZc.d.cts → types-DHrHsQwF.d.cts} +1 -1
- package/dist/{types-Dte-oYZc.d.ts → types-DHrHsQwF.d.ts} +1 -1
- package/package.json +6 -2
- package/dist/chunk-T2ZQU6E6.mjs +0 -530
- package/dist/chunk-T2ZQU6E6.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { countries_exports, __spreadValues, __spreadProps } from './chunk-
|
|
1
|
+
import { countries_exports, __spreadValues, __spreadProps } from './chunk-TGO6OI3L.mjs';
|
|
2
2
|
|
|
3
3
|
// src/core/flags.ts
|
|
4
4
|
var toFlagEmoji = (code) => String.fromCodePoint(
|
|
@@ -34,10 +34,11 @@ var applyOptions = (countries, options) => {
|
|
|
34
34
|
};
|
|
35
35
|
var getAllCountries = (options) => applyOptions(allCountriesArray, options);
|
|
36
36
|
var getAllCountriesWithFlags = (options) => applyOptions(allCountriesArray, options).map(withFlags);
|
|
37
|
-
var getCountryByCode = (code) =>
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
var getCountryByCode = (code) => (
|
|
38
|
+
// biome-ignore lint/performance/noDynamicNamespaceImportAccess: required for getCountryByCode lookup
|
|
39
|
+
countries_exports[code.toUpperCase()]
|
|
40
40
|
);
|
|
41
|
+
var getCountryByAlpha3 = (alpha3) => allCountriesArray.find((c) => c.alpha3.toLowerCase() === alpha3.toLowerCase());
|
|
41
42
|
var getCountryByPhone = (phone) => allCountriesArray.filter((c) => c.phone === phone);
|
|
42
43
|
|
|
43
44
|
export { getAllCountries, getAllCountriesWithFlags, getCountryByAlpha3, getCountryByCode, getCountryByPhone, toFlagEmoji, toFlagUrls, withFlags };
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/flags.ts","../src/core/utils.ts"],"names":[],"mappings":";;;AAEO,IAAM,WAAA,GAAc,CAAC,IAAA,KAC1B,MAAA,CAAO,aAAA;AAAA,EACL,GAAG,IAAA,CACA,WAAA,EAAY,CACZ,MAAM,EAAE,CAAA,CACR,GAAA,CAAI,CAAC,CAAA,KAAM,MAAA,GAAS,CAAA,CAAE,UAAA,CAAW,CAAC,CAAC;AACxC;AAEK,IAAM,UAAA,GAAa,CACxB,IAAA,KAC6E;AAC7E,EAAA,MAAM,KAAA,GAAQ,KAAK,WAAA,EAAY;AAC/B,EAAA,OAAO;AAAA,IACL,SAAA,EAAW,2BAA2B,KAAK,CAAA,IAAA,CAAA;AAAA,IAC3C,SAAA,EAAW,2BAA2B,KAAK,CAAA,IAAA,CAAA;AAAA,IAC3C,OAAA,EAAS,uBAAuB,KAAK,CAAA,IAAA,CAAA;AAAA,IACrC,MAAA,EAAQ,2BAA2B,KAAK,CAAA,OAAA;AAAA,GAC1C;AACF;AAEO,IAAM,SAAA,GAAY,CAAC,OAAA,KAAwC,cAAA,CAAA,aAAA,CAAA,cAAA,CAAA,EAAA,EAC7D,OAAA,CAAA,EAD6D;AAAA,EAEhE,SAAA,EAAW,WAAA,CAAY,OAAA,CAAQ,IAAI;AAAA,CAAA,CAAA,EAChC,UAAA,CAAW,QAAQ,IAAI,CAAA;;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GAAG,SAAS,CAAA;AAE/E,EAAA,IAAI,mCAAS,IAAA,EAAM;AACjB,IAAA,MAAM,EAAE,EAAA,EAAI,KAAA,EAAM,GAAI,OAAA,CAAQ,IAAA;AAC9B,IAAA,MAAA,GAAS,MAAA,CAAO,IAAA,CAAK,CAAC,CAAA,EAAG,CAAA,KAAM;AAC7B,MAAA,MAAM,IAAA,GAAO,EAAE,EAAE,CAAA;AACjB,MAAA,MAAM,IAAA,GAAO,EAAE,EAAE,CAAA;AACjB,MAAA,MAAM,GAAA,GAAM,IAAA,CAAK,aAAA,CAAc,IAAI,CAAA;AACnC,MAAA,OAAO,KAAA,KAAU,KAAA,GAAQ,GAAA,GAAM,CAAC,GAAA;AAAA,IAClC,CAAC,CAAA;AAAA,EACH;AAEA,EAAA,OAAO,MAAA;AACT,CAAA;AAEO,IAAM,eAAA,GAAkB,CAAC,OAAA,KAC9B,YAAA,CAAa,mBAAmB,OAAO;AAElC,IAAM,wBAAA,GAA2B,CAAC,OAAA,KACvC,YAAA,CAAa,mBAAmB,OAAO,CAAA,CAAE,IAAI,SAAS;AAGjD,IAAM,mBAAmB,CAAC,IAAA;AAAA;AAAA,EAE/B,iBAAA,CAAc,IAAA,CAAK,WAAA,EAA2C;AAAA;AAEzD,IAAM,kBAAA,GAAqB,CAAC,MAAA,KACjC,iBAAA,CAAkB,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,MAAA,CAAO,WAAA,EAAY,KAAM,MAAA,CAAO,aAAa;AAExE,IAAM,iBAAA,GAAoB,CAAC,KAAA,KAChC,iBAAA,CAAkB,OAAO,CAAC,CAAA,KAAM,CAAA,CAAE,KAAA,KAAU,KAAK","file":"index.mjs","sourcesContent":["import type { Country, CountryWithFlags } from \"./types\";\n\nexport const toFlagEmoji = (code: string): string =>\n String.fromCodePoint(\n ...code\n .toUpperCase()\n .split(\"\")\n .map((c) => 127397 + c.charCodeAt(0)),\n );\n\nexport const toFlagUrls = (\n code: string,\n): Pick<CountryWithFlags, \"flagPng20\" | \"flagPng40\" | \"flagSvg\" | \"srcSet\"> => {\n const lower = code.toLowerCase();\n return {\n flagPng20: `https://flagcdn.com/w20/${lower}.png`,\n flagPng40: `https://flagcdn.com/w40/${lower}.png`,\n flagSvg: `https://flagcdn.com/${lower}.svg`,\n srcSet: `https://flagcdn.com/w40/${lower}.png 2x`,\n };\n};\n\nexport const withFlags = (country: Country): CountryWithFlags => ({\n ...country,\n flagEmoji: toFlagEmoji(country.code),\n ...toFlagUrls(country.code),\n});\n","import * as _allCountries from \"../data/countries\";\nimport { withFlags } from \"./flags\";\nimport type { Country, CountryWithFlags, FilterSortOptions } from \"./types\";\n\nconst allCountriesArray: Country[] = Object.values(_allCountries);\n\nconst applyOptions = (countries: Country[], options?: FilterSortOptions): Country[] => {\n let result = options?.filter ? countries.filter(options.filter) : [...countries];\n\n if (options?.sort) {\n const { by, order } = options.sort;\n result = result.sort((a, b) => {\n const aVal = a[by];\n const bVal = b[by];\n const cmp = aVal.localeCompare(bVal);\n return order === \"asc\" ? cmp : -cmp;\n });\n }\n\n return result;\n};\n\nexport const getAllCountries = (options?: FilterSortOptions): Country[] =>\n applyOptions(allCountriesArray, options);\n\nexport const getAllCountriesWithFlags = (options?: FilterSortOptions): CountryWithFlags[] =>\n applyOptions(allCountriesArray, options).map(withFlags);\n\n// Intentional: runtime lookup by code; tree-shakeable path is @tw-labs/countries/data\nexport const getCountryByCode = (code: string): Country | undefined =>\n // biome-ignore lint/performance/noDynamicNamespaceImportAccess: required for getCountryByCode lookup\n _allCountries[code.toUpperCase() as keyof typeof _allCountries];\n\nexport const getCountryByAlpha3 = (alpha3: string): Country | undefined =>\n allCountriesArray.find((c) => c.alpha3.toLowerCase() === alpha3.toLowerCase());\n\nexport const getCountryByPhone = (phone: string): Country[] =>\n allCountriesArray.filter((c) => c.phone === phone);\n"]}
|