-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use geonames source data and export used fields only
- Loading branch information
Showing
10 changed files
with
633 additions
and
5,321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@bicou/countries-server-schema": patch | ||
"@bicou/countries-server-data": patch | ||
--- | ||
|
||
use geonames source data and export used fields only |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ node_modules | |
dist | ||
.nitro | ||
.output | ||
data/src/countries.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { createReadStream, createWriteStream } from "node:fs"; | ||
import { createInterface } from "node:readline"; | ||
import { once } from "node:events"; | ||
import { type GeoCountry } from "./src/geo-country.js"; | ||
|
||
const source = createWriteStream("src/countries.ts", { flags: "w" }); | ||
source.write('import { type GeoCountry } from "./geo-country.js";\n'); | ||
source.write('export { type GeoCountry } from "./geo-country.js";\n'); | ||
source.write("export const countries: GeoCountry[] = [\n"); | ||
|
||
const tsv = createInterface({ | ||
input: createReadStream("countryInfo.txt"), | ||
crlfDelay: Number.POSITIVE_INFINITY, | ||
}); | ||
|
||
tsv.on("line", (line) => { | ||
if (line.length > 0 && !line.startsWith("#")) { | ||
const data = line.split("\t"); | ||
const country: GeoCountry = { | ||
ISO: data[0], | ||
ISO3: data[1], | ||
"ISO-Numeric": data[2], | ||
Country: data[4], | ||
tld: data[9], | ||
neighbours: (data[17].length > 0 && data[17].split(",")) || [], | ||
}; | ||
source.write("\t" + JSON.stringify(country) + ",\n"); | ||
} | ||
}); | ||
|
||
await once(tsv, "close"); | ||
|
||
source.write("];\n"); | ||
source.end(); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
6a207a9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
countries-server – ./
countries-server.vercel.app
countries-server-bicou.vercel.app
countries-server-git-main-bicou.vercel.app
countries.bicou.com