@mailwoman/un-locode-lookup 8.6.0 → 9.0.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/build.ts +13 -7
- package/out/build.d.ts.map +1 -1
- package/out/build.js +11 -6
- package/out/build.js.map +1 -1
- package/package.json +4 -4
package/build.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
import { readFileSync } from "node:fs"
|
|
12
12
|
import { DatabaseSync } from "node:sqlite"
|
|
13
13
|
|
|
14
|
-
import {
|
|
14
|
+
import { CSVSpliterator } from "spliterator"
|
|
15
15
|
|
|
16
16
|
import { foldName, parseUnLocodeCoords } from "./index.ts"
|
|
17
17
|
|
|
@@ -27,11 +27,14 @@ interface CSVRow {
|
|
|
27
27
|
* Read the code-list CSV at `csvPath` and write the lookup DB to `dbPath`.
|
|
28
28
|
*/
|
|
29
29
|
export function buildUnLocodeDB(csvPath: string, dbPath: string): { rows: number; withCoords: number } {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
// `normalizeKeys: false` keeps the UNECE header casing the row shape above is written against
|
|
31
|
+
// (`NameWoDiacritics`, not `name_wo_diacritics`). Location names carry commas, so quote handling
|
|
32
|
+
// is on — it is off by default.
|
|
33
|
+
const records = CSVSpliterator.from(readFileSync(csvPath), {
|
|
34
|
+
mode: "object",
|
|
35
|
+
normalizeKeys: false,
|
|
36
|
+
enableQuoteHandling: true,
|
|
37
|
+
}) as Iterable<CSVRow>
|
|
35
38
|
|
|
36
39
|
const db = new DatabaseSync(dbPath)
|
|
37
40
|
db.exec("DROP TABLE IF EXISTS un_locode")
|
|
@@ -43,9 +46,12 @@ export function buildUnLocodeDB(csvPath: string, dbPath: string): { rows: number
|
|
|
43
46
|
const insert = db.prepare("INSERT INTO un_locode (country, location, name, nameNorm, lat, lon) VALUES (?,?,?,?,?,?)")
|
|
44
47
|
|
|
45
48
|
let withCoords = 0
|
|
49
|
+
let rows = 0
|
|
46
50
|
db.exec("BEGIN")
|
|
47
51
|
|
|
48
52
|
for (const r of records) {
|
|
53
|
+
rows++
|
|
54
|
+
|
|
49
55
|
if (!r.Country || !r.Location) continue // header/country rows carry no Location
|
|
50
56
|
const coords = r.Coordinates ? parseUnLocodeCoords(r.Coordinates) : null
|
|
51
57
|
|
|
@@ -62,5 +68,5 @@ export function buildUnLocodeDB(csvPath: string, dbPath: string): { rows: number
|
|
|
62
68
|
db.exec("CREATE INDEX idx_locode_bbox ON un_locode (lat, lon)")
|
|
63
69
|
db.close()
|
|
64
70
|
|
|
65
|
-
return { rows
|
|
71
|
+
return { rows, withCoords }
|
|
66
72
|
}
|
package/out/build.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../build.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAiBH;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../build.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAiBH;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CA2CrG"}
|
package/out/build.js
CHANGED
|
@@ -9,24 +9,29 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { readFileSync } from "node:fs";
|
|
11
11
|
import { DatabaseSync } from "node:sqlite";
|
|
12
|
-
import {
|
|
12
|
+
import { CSVSpliterator } from "spliterator";
|
|
13
13
|
import { foldName, parseUnLocodeCoords } from "./index.js";
|
|
14
14
|
/**
|
|
15
15
|
* Read the code-list CSV at `csvPath` and write the lookup DB to `dbPath`.
|
|
16
16
|
*/
|
|
17
17
|
export function buildUnLocodeDB(csvPath, dbPath) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
// `normalizeKeys: false` keeps the UNECE header casing the row shape above is written against
|
|
19
|
+
// (`NameWoDiacritics`, not `name_wo_diacritics`). Location names carry commas, so quote handling
|
|
20
|
+
// is on — it is off by default.
|
|
21
|
+
const records = CSVSpliterator.from(readFileSync(csvPath), {
|
|
22
|
+
mode: "object",
|
|
23
|
+
normalizeKeys: false,
|
|
24
|
+
enableQuoteHandling: true,
|
|
22
25
|
});
|
|
23
26
|
const db = new DatabaseSync(dbPath);
|
|
24
27
|
db.exec("DROP TABLE IF EXISTS un_locode");
|
|
25
28
|
db.exec("CREATE TABLE un_locode (country TEXT NOT NULL, location TEXT NOT NULL, name TEXT, nameNorm TEXT, lat REAL, lon REAL)");
|
|
26
29
|
const insert = db.prepare("INSERT INTO un_locode (country, location, name, nameNorm, lat, lon) VALUES (?,?,?,?,?,?)");
|
|
27
30
|
let withCoords = 0;
|
|
31
|
+
let rows = 0;
|
|
28
32
|
db.exec("BEGIN");
|
|
29
33
|
for (const r of records) {
|
|
34
|
+
rows++;
|
|
30
35
|
if (!r.Country || !r.Location)
|
|
31
36
|
continue; // header/country rows carry no Location
|
|
32
37
|
const coords = r.Coordinates ? parseUnLocodeCoords(r.Coordinates) : null;
|
|
@@ -40,6 +45,6 @@ export function buildUnLocodeDB(csvPath, dbPath) {
|
|
|
40
45
|
db.exec("CREATE INDEX idx_locode_name ON un_locode (country, nameNorm)");
|
|
41
46
|
db.exec("CREATE INDEX idx_locode_bbox ON un_locode (lat, lon)");
|
|
42
47
|
db.close();
|
|
43
|
-
return { rows
|
|
48
|
+
return { rows, withCoords };
|
|
44
49
|
}
|
|
45
50
|
//# sourceMappingURL=build.js.map
|
package/out/build.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../build.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../build.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE5C,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAU1D;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,OAAe,EAAE,MAAc;IAC9D,8FAA8F;IAC9F,iGAAiG;IACjG,gCAAgC;IAChC,MAAM,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE;QAC1D,IAAI,EAAE,QAAQ;QACd,aAAa,EAAE,KAAK;QACpB,mBAAmB,EAAE,IAAI;KACzB,CAAqB,CAAA;IAEtB,MAAM,EAAE,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC,CAAA;IACnC,EAAE,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAA;IAEzC,EAAE,CAAC,IAAI,CACN,sHAAsH,CACtH,CAAA;IAED,MAAM,MAAM,GAAG,EAAE,CAAC,OAAO,CAAC,0FAA0F,CAAC,CAAA;IAErH,IAAI,UAAU,GAAG,CAAC,CAAA;IAClB,IAAI,IAAI,GAAG,CAAC,CAAA;IACZ,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAEhB,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;QACzB,IAAI,EAAE,CAAA;QAEN,IAAI,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,QAAQ;YAAE,SAAQ,CAAC,wCAAwC;QAChF,MAAM,MAAM,GAAG,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;QAExE,IAAI,MAAM,EAAE,CAAC;YACZ,UAAU,EAAE,CAAA;QACb,CAAC;QAED,MAAM,IAAI,GAAG,CAAC,CAAC,gBAAgB,IAAI,CAAC,CAAC,IAAI,IAAI,EAAE,CAAA;QAC/C,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,IAAI,IAAI,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,IAAI,CAAC,CAAA;IAC5G,CAAC;IAED,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IACjB,EAAE,CAAC,IAAI,CAAC,+DAA+D,CAAC,CAAA;IACxE,EAAE,CAAC,IAAI,CAAC,sDAAsD,CAAC,CAAA;IAC/D,EAAE,CAAC,KAAK,EAAE,CAAA;IAEV,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,CAAA;AAC5B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mailwoman/un-locode-lookup",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "Place → UN/LOCODE (UNECE Code for Trade and Transport Locations), by country + name or nearest coordinate. node:sqlite over the UNECE code list. An @mailwoman/annotations Annotator.",
|
|
5
5
|
"license": "AGPL-3.0-only OR LicenseRef-Commercial",
|
|
6
6
|
"repository": {
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@mailwoman/annotations": "
|
|
55
|
-
"@mailwoman/spatial": "
|
|
56
|
-
"
|
|
54
|
+
"@mailwoman/annotations": "9.0.0",
|
|
55
|
+
"@mailwoman/spatial": "9.0.0",
|
|
56
|
+
"spliterator": "^6.0.1"
|
|
57
57
|
}
|
|
58
58
|
}
|