diff --git a/docs/index.html b/docs/index.html
deleted file mode 100644
index 5d35c52..0000000
--- a/docs/index.html
+++ /dev/null
@@ -1,40 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
- Your Library
-
-
-
-
-
Your Library
-
- Show a demo of your library here.
-
-
-
-
-
-
-
-
-
-
diff --git a/docs/main.js b/docs/main.js
deleted file mode 100644
index fe19266..0000000
--- a/docs/main.js
+++ /dev/null
@@ -1,6 +0,0 @@
-document.addEventListener("DOMContentLoaded", onLoaded);
-
-function onLoaded() {
- const r = irem.yourLibFunction(2, 5);
- document.getElementById("result").innerText = `2 + 5 = ${r}`;
-}
diff --git a/docs/style.css b/docs/style.css
deleted file mode 100644
index 2797c7a..0000000
--- a/docs/style.css
+++ /dev/null
@@ -1,4 +0,0 @@
-.bordered {
- border: 0.5px solid rgba(0, 0, 0, 0.125);
- border-radius: 0.25rem;
-}
diff --git a/docs/your-library.umd.js b/docs/your-library.umd.js
deleted file mode 100644
index 665bfdd..0000000
--- a/docs/your-library.umd.js
+++ /dev/null
@@ -1,16 +0,0 @@
-!(function (e, n) {
- "object" == typeof exports && "undefined" != typeof module
- ? n(exports)
- : "function" == typeof define && define.amd
- ? define(["exports"], n)
- : n(
- ((e =
- "undefined" != typeof globalThis ? globalThis : e || self).irem =
- {}),
- );
-})(this, function (e) {
- "use strict";
- e.yourLibFunction = function (e, n) {
- return e + n;
- };
-});
diff --git a/rollup.config.js b/rollup.config.js
index bdc460d..4cd0029 100644
--- a/rollup.config.js
+++ b/rollup.config.js
@@ -1,26 +1,10 @@
-import commonjs from "@rollup/plugin-commonjs";
import typescript from "@rollup/plugin-typescript";
import terser from "@rollup/plugin-terser";
const isProduction = process.env.NODE_ENV === "production";
export default [
- // browser-friendly UMD build
- {
- input: "src/main.ts",
- output: {
- name: "irem",
- file: "dist/irem.umd.js",
- format: "umd",
- },
- plugins: [
- commonjs(), // so Rollup can convert `ms` to an ES module
- typescript({ module: "esnext", tsconfig: "./tsconfig.json" }), // so Rollup can convert TypeScript to JavaScript
- isProduction && terser(),
- ],
- },
-
- // CommonJS (for Node) and ES module (for bundlers) build.
+ // ES module (for bundlers) build.
// (We could have three entries in the configuration array
// instead of two, but it's quicker to generate multiple
// builds from a single configuration where possible, using
@@ -33,9 +17,6 @@ export default [
typescript({ module: "esnext", tsconfig: "./tsconfig.json" }), // so Rollup can convert TypeScript to JavaScript
isProduction && terser(),
],
- output: [
- { file: "dist/irem.cjs.js", format: "cjs" },
- { file: "dist/irem.esm.js", format: "es" },
- ],
+ output: [{ file: "dist/irem.esm.js", format: "es" }],
},
];
diff --git a/src/main.ts b/src/main.ts
index 71dbe4b..c6752f0 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -8,11 +8,9 @@ import {
import { readFileSync } from "fs";
import { isSupportedNonEnglishLanguage } from "./util";
-export async function getAllCountries(
- language?: SupportedLanguage,
-): Promise {
+export function getAllCountries(language?: SupportedLanguage): SimpleCountry[] {
const t1 = new Date().getTime();
- const data = await readJSON(language);
+ const data = readJSON(language);
const t2 = new Date().getTime();
console.log((t2 - t1) / 1000, " seconds passed ");
@@ -28,11 +26,11 @@ export async function getAllCountries(
return countries;
}
-export async function getAllRegionsOfCountry(
+export function getAllRegionsOfCountry(
countryCode: CountryCode,
language?: SupportedLanguage,
-): Promise {
- const data = await readJSON(language);
+): SimplePlace[] {
+ const data = readJSON(language);
const regions: SimplePlace[] = [];
for (const regionNameInEnglish in data[countryCode][">"]) {
regions.push({
@@ -43,27 +41,28 @@ export async function getAllRegionsOfCountry(
return regions;
}
-// export async function getAllCities(
-// countryCode: CountryCode,
-// language?: SupportedLanguage,
-// ): SimplePlace[] {
-// const data = await readJSON(language);
+export function getAllCities(
+ countryCode: CountryCode,
+ regionNameInEnglish: string,
+ language?: SupportedLanguage,
+): SimplePlace[] {
+ const data = readJSON(language);
-// const regions: SimplePlace[] = [];
-// for (const regionNameInEnglish in data[countryCode][">"]) {
-// regions.push({
-// englishName: regionNameInEnglish,
-// name: data[countryCode][">"][regionNameInEnglish].t,
-// });
-// }
-// return regions;
-// }
+ const cities: SimplePlace[] = [];
+ for (const cityName in data[countryCode][">"][regionNameInEnglish][">"]) {
+ cities.push({
+ englishName: cityName,
+ name: data[countryCode][">"][regionNameInEnglish][">"][cityName].t,
+ });
+ }
+ return cities;
+}
-async function readJSON(
+function readJSON(
language?: SupportedLanguage,
nonEnglishDataPath: string = "./data/",
englishDataPath: string = "./data/",
-): Promise> {
+): Record {
const fileToRead = isSupportedNonEnglishLanguage(language)
? `${nonEnglishDataPath}GPS-data-${language}.json`
: `${englishDataPath}GPS-data.json`;
diff --git a/test/main.spec.ts b/test/main.spec.ts
index 89b07d6..92700d4 100644
--- a/test/main.spec.ts
+++ b/test/main.spec.ts
@@ -1,18 +1,22 @@
-import { getAllCountries, getAllRegionsOfCountry } from "../src/main";
+import {
+ getAllCities,
+ getAllCountries,
+ getAllRegionsOfCountry,
+} from "../src/main";
import { describe, test, expect } from "vitest";
import { supportedNonEnglishLanguages } from "../src/util";
describe("allCountriesInEnglish", () => {
test.each([...supportedNonEnglishLanguages, "en", "EN", "undefined"])(
"should get all countries in Language %s",
- async (language) => {
- const allCountries = await getAllCountries(language);
+ (language) => {
+ const allCountries = getAllCountries(language);
expect(allCountries).toHaveLength(242);
},
);
- test("should get Turkey from all countries in Turkish", async () => {
- const allCountriesInTurkish = await getAllCountries("tr");
+ test("should get Turkey from all countries in Turkish", () => {
+ const allCountriesInTurkish = getAllCountries("tr");
const turkey = allCountriesInTurkish.find((x) => x.code == "TR");
expect(turkey).toEqual({
code: "TR",
@@ -23,13 +27,13 @@ describe("allCountriesInEnglish", () => {
});
describe("getAllRegionsOfCountry", () => {
- test("should get 81 regions (cities) in Turkey", async () => {
- const allRegionsInTurkey = await getAllRegionsOfCountry("TR", "tr");
+ test("should get 81 regions (cities) in Turkey", () => {
+ const allRegionsInTurkey = getAllRegionsOfCountry("TR", "tr");
expect(allRegionsInTurkey.length).toBe(81);
});
- test("should get Kocaeli and İstanbul cities in Turkey", async () => {
- const allRegionsInTurkey = await getAllRegionsOfCountry("TR", "tr");
+ test("should get Kocaeli and İstanbul cities in Turkey", () => {
+ const allRegionsInTurkey = getAllRegionsOfCountry("TR", "tr");
const istanbul = allRegionsInTurkey.find(
(x) => x.englishName === "İstanbul",
@@ -39,3 +43,11 @@ describe("getAllRegionsOfCountry", () => {
expect(kocaeli).toEqual({ englishName: "Kocaeli", name: "" });
});
});
+
+describe("getAllCities", () => {
+ test("should get cities (districts) in Ankara in Turkey", () => {
+ const allPlacesInAnkara = getAllCities("TR", "Ankara", "tr");
+ console.log("allPlacesInAnkara: ", allPlacesInAnkara);
+ expect(allPlacesInAnkara.length).toBe(26);
+ });
+});