Skip to content

Commit

Permalink
esm compliant imports
Browse files Browse the repository at this point in the history
  • Loading branch information
erikyo committed Jun 1, 2024
1 parent 143df3a commit b1eb6e2
Show file tree
Hide file tree
Showing 15 changed files with 334 additions and 332 deletions.
540 changes: 270 additions & 270 deletions src/data/countries-extra.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/data/countries-geo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ISOCountryGeo } from "../types";
import type { ISOCountryGeo } from "../types.js";

export const countriesGeo: ISOCountryGeo = {
AX: {
Expand Down
10 changes: 5 additions & 5 deletions src/formatIso.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { tryCountriesFallback } from "./fallbacks";
import { getIso } from "./getIso";
import type { IsoCodeFormat } from "./types";
import { getSeparator } from "./utils";
import { validateISO } from "./validation";
import { tryCountriesFallback } from "./fallbacks.js";
import { getIso } from "./getIso.js";
import type { IsoCodeFormat } from "./types.js";
import { getSeparator } from "./utils.js";
import { validateISO } from "./validation.js";

/**
* Formats the language and country into a single string.
Expand Down
16 changes: 8 additions & 8 deletions src/getAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ import type {
IsoType,
LanguageData,
LanguageDataFields,
} from "./types";
} from "./types.js";

import { countriesIso } from "./data/countries-iso";
import { langIso } from "./data/lang-iso";
import { LangIso3 } from "./data/lang-iso3";
import { formatIso } from "./formatIso";
import { getCountry } from "./getCountry";
import { getIso } from "./getIso";
import { countriesIso } from "./data/countries-iso.js";
import { langIso } from "./data/lang-iso.js";
import { LangIso3 } from "./data/lang-iso3.js";
import { formatIso } from "./formatIso.js";
import { getCountry } from "./getCountry.js";
import { getIso } from "./getIso.js";
import {
isCountryFormat,
isExtraField,
isGeoField,
isLanguageFormat,
} from "./utils";
} from "./utils.js";

/**
* Returns an array of languages divided by a custom separator.
Expand Down
4 changes: 2 additions & 2 deletions src/getByProximity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { countriesExtra } from "./data/countries-extra";
import { getIso } from "./getIso";
import { countriesExtra } from "./data/countries-extra.js";
import { getIso } from "./getIso.js";

/**
* Calculate the distance between two sets of coordinates using the Haversine formula.
Expand Down
14 changes: 7 additions & 7 deletions src/getCountry.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { countriesExtra } from "./data/countries-extra";
import { countriesGeo } from "./data/countries-geo";
import { countriesIso } from "./data/countries-iso";
import { formatIso } from "./formatIso";
import { getIso } from "./getIso";
import { countriesExtra } from "./data/countries-extra.js";
import { countriesGeo } from "./data/countries-geo.js";
import { countriesIso } from "./data/countries-iso.js";
import { formatIso } from "./formatIso.js";
import { getIso } from "./getIso.js";
import type {
Country,
CountryData,
Expand All @@ -13,8 +13,8 @@ import type {
ISOLangCode,
LanguageData,
} from "./types";
import { formatCoordinatesToDMS, isExtraField, isGeoField } from "./utils";
import { validateISO } from "./validation";
import { formatCoordinatesToDMS, isExtraField, isGeoField } from "./utils.js";
import { validateISO } from "./validation.js";

const wikiMediaUrl = "https://upload.wikimedia.org/wikipedia/commons/";

Expand Down
6 changes: 3 additions & 3 deletions src/getGroupedBy.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { countriesGeo } from "./data/countries-geo";
import { countriesIso } from "./data/countries-iso";
import { countriesGeo } from "./data/countries-geo.js";
import { countriesIso } from "./data/countries-iso.js";
import type {
Country,
CountryData,
CountryGeo,
ISOCountryCode,
IsoCode,
} from "./types";
} from "./types.js";

export function getGroupedBy(
field: "region" | "continent" | "subRegion",
Expand Down
6 changes: 3 additions & 3 deletions src/getIso.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getCountry } from "./getCountry";
import { getLanguage } from "./getLanguage";
import { getCountry } from "./getCountry.js";
import { getLanguage } from "./getLanguage.js";
import type {
CountryDataExtended,
CountryDataFields,
Expand All @@ -9,7 +9,7 @@ import type {
IsoType,
LanguageData,
LanguageDataFields,
} from "./types";
} from "./types.js";

/**
* Retrieves the ISO value for a given code, type, and fields.
Expand Down
6 changes: 3 additions & 3 deletions src/getKeyValue.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { countriesIso } from "./data/countries-iso";
import { getIso } from "./getIso";
import type { CountryDataFields } from "./types";
import { countriesIso } from "./data/countries-iso.js";
import { getIso } from "./getIso.js";
import type { CountryDataFields } from "./types.js";

/**
* Generates an array of objects suitable for React Select options based on the specified field.
Expand Down
20 changes: 11 additions & 9 deletions src/getLanguage.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { langIso } from "./data/lang-iso";
import { langIso } from "./data/lang-iso.js";
import type {
ISOLangCode,
Language,
LanguageData,
LanguageDataFields,
LanguageFields,
} from "./types";
import { validateISO } from "./validation";
} from "./types.js";
import { validateISO } from "./validation.js";

/**
* Retrieves the ISO language object based on the provided language code.
Expand Down Expand Up @@ -45,18 +45,20 @@ export function getLanguage(
if (fields === "iso2") {
return isoCode;
}
/** @type {string[]} fieldsArray The array of fields to return */
let fieldsArray: string[] = [];
if (fields === "all") {
fields = ["iso2", "name", "original", "iso3"];
fieldsArray = ["iso2", "name", "original", "iso3"];
} else if (typeof fields === "string") {
fields = [fields as LanguageDataFields];
fieldsArray = [fields as LanguageDataFields];
}

// if the fields are not an iso, return the fields
// if the fields are not an iso, return the fieldsArray
const collected: Partial<LanguageData> = {};
if (Object.keys(fields).length === 1) {
return language[Object.values(fields)[0] as LanguageFields];
if (Object.keys(fieldsArray).length === 1) {
return language[Object.values(fieldsArray)[0] as LanguageFields];
}
for (const field of fields) {
for (const field of fieldsArray) {
const key = field;
if (key === "iso2") {
collected.iso2 = isoCode as ISOLangCode;
Expand Down
16 changes: 8 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export { formatIso } from "./formatIso";
export { validateISO } from "./validation";
export { getIso } from "./getIso";
export { getAll } from "./getAll";
export { isoInfo } from "./isoInfo";
export { getLanguage } from "./getLanguage";
export { getKeyValue } from "./getKeyValue";
export { getGroupedBy, getCountriesByLanguage } from "./getGroupedBy";
export { formatIso } from "./formatIso.js";
export { validateISO } from "./validation.js";
export { getIso } from "./getIso.js";
export { getAll } from "./getAll.js";
export { isoInfo } from "./isoInfo.js";
export { getLanguage } from "./getLanguage.js";
export { getKeyValue } from "./getKeyValue.js";
export { getGroupedBy, getCountriesByLanguage } from "./getGroupedBy.js";
12 changes: 6 additions & 6 deletions src/isoInfo.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { countriesIso } from "./data/countries-iso";
import { langIso } from "./data/lang-iso";
import { getIso } from "./getIso";
import type { Country, ISOCountry, ISOLanguage, Language } from "./types";
import { parseIso5Code } from "./utils";
import { validateISO, validateSeparator } from "./validation";
import { countriesIso } from "./data/countries-iso.js";
import { langIso } from "./data/lang-iso.js";
import { getIso } from "./getIso.js";
import type { Country, ISOCountry, ISOLanguage, Language } from "./types.js";
import { parseIso5Code } from "./utils.js";
import { validateISO, validateSeparator } from "./validation.js";

export function isoInfo(iso: string) {
// detect the length of the iso
Expand Down
6 changes: 3 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { countriesIso } from "./data/countries-iso";
import type { langIso } from "./data/lang-iso";
import type { LangIso3 } from "./data/lang-iso3";
import type { countriesIso } from "./data/countries-iso.js";
import type { langIso } from "./data/lang-iso.js";
import type { LangIso3 } from "./data/lang-iso3.js";

/** Type of ISO */
export type IsoType = "country" | "language";
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
CountryGeoFields,
IsoCodeFormat,
LanguageFields,
} from "./types";
} from "./types.js";

export function isExtraField(fields: string[]): fields is CountryExtraFields[] {
return (
Expand Down
6 changes: 3 additions & 3 deletions src/validation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { countriesIso } from "./data/countries-iso";
import { langIso } from "./data/lang-iso";
import type { IsoCodeFormat, IsoType } from "./types";
import { countriesIso } from "./data/countries-iso.js";
import { langIso } from "./data/lang-iso.js";
import type { IsoCodeFormat, IsoType } from "./types.js";

function isValidCountry(iso: string): boolean {
return iso in countriesIso;
Expand Down

0 comments on commit b1eb6e2

Please sign in to comment.