@janekolszak/poland 1.0.2 → 1.0.5
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 +25 -1
- package/SIMC_Urzedowy_2023-02-12.csv +102313 -0
- package/TERC_Urzedowy_2023-02-12.csv +4266 -0
- package/WMRODZ_2023-02-12.csv +14 -0
- package/generated/go/counties.json +1 -0
- package/generated/go/districts.json +1 -0
- package/generated/go/localities.json +1 -0
- package/generated/go/municipalities.json +1 -0
- package/generated/go/root.go +7 -0
- package/generated/go/voivodeships.json +1 -0
- package/generated/json/districts.json +1 -0
- package/generated/json/localities.json +1 -0
- package/generated/json/municipalities.json +1 -1
- package/generated/typescript/data.ts +1 -1
- package/index.ts +3 -3
- package/package.json +10 -5
- package/src/args.ts +4 -0
- package/src/compute.ts +143 -8
- package/src/csvparse.ts +69 -1
- package/src/generate.ts +16 -11
- package/src/map.ts +97 -0
- package/tsconfig.json +4 -4
- package/TERC_Urzedowy_2022-10-22.csv +0 -4236
- package/generated/go/data.go +0 -7
package/src/csvparse.ts
CHANGED
|
@@ -8,9 +8,29 @@ export type Region = {
|
|
|
8
8
|
county: string;
|
|
9
9
|
municipality: string;
|
|
10
10
|
type: string;
|
|
11
|
-
typeId:
|
|
11
|
+
typeId: string;
|
|
12
12
|
name: string;
|
|
13
13
|
date: string;
|
|
14
|
+
localityId: string;
|
|
15
|
+
baseLocalityId: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type Locality = {
|
|
19
|
+
voivodeship: string
|
|
20
|
+
county: string;
|
|
21
|
+
municipality: string;
|
|
22
|
+
municipalityTypeId: string;
|
|
23
|
+
localityTypeId: string;
|
|
24
|
+
isLocalName: string;
|
|
25
|
+
name: string;
|
|
26
|
+
localityId: string;
|
|
27
|
+
baseLocalityId: string;
|
|
28
|
+
date: string;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type LocalityType = {
|
|
32
|
+
id: string;
|
|
33
|
+
name: string;
|
|
14
34
|
};
|
|
15
35
|
|
|
16
36
|
function toTitleCase(str: String) {
|
|
@@ -44,3 +64,51 @@ export async function parseCsv() {
|
|
|
44
64
|
await finished(parser);
|
|
45
65
|
return records;
|
|
46
66
|
};
|
|
67
|
+
|
|
68
|
+
export async function parseLocalityCsv() {
|
|
69
|
+
const records: Locality[] = [];
|
|
70
|
+
const parser = fs
|
|
71
|
+
.createReadStream(args.localities)
|
|
72
|
+
.pipe(parse({
|
|
73
|
+
relax_quotes: true,
|
|
74
|
+
delimiter: ';',
|
|
75
|
+
skip_empty_lines: true,
|
|
76
|
+
record_delimiter: '\r\n',
|
|
77
|
+
columns: () => {
|
|
78
|
+
return ["voivodeship", "county", "municipality", "municipalityTypeId", "localityTypeId", "isLocalName", "name", "localityId", "baseLocalityId", "date"]
|
|
79
|
+
},
|
|
80
|
+
}))
|
|
81
|
+
.on('readable', function () {
|
|
82
|
+
let record; while ((record = parser.read()) !== null) {
|
|
83
|
+
// Work with each record
|
|
84
|
+
record.name = toTitleCase(record.name)
|
|
85
|
+
records.push(record);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
await finished(parser);
|
|
89
|
+
return records;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export async function parseLocalityTypeCsv() {
|
|
93
|
+
const records: LocalityType[] = [];
|
|
94
|
+
const parser = fs
|
|
95
|
+
.createReadStream(args.types)
|
|
96
|
+
.pipe(parse({
|
|
97
|
+
relax_quotes: true,
|
|
98
|
+
delimiter: ';',
|
|
99
|
+
skip_empty_lines: true,
|
|
100
|
+
record_delimiter: '\r\n',
|
|
101
|
+
columns: () => {
|
|
102
|
+
return ["id", "name", "date"]
|
|
103
|
+
},
|
|
104
|
+
}))
|
|
105
|
+
.on('readable', function () {
|
|
106
|
+
let record; while ((record = parser.read()) !== null) {
|
|
107
|
+
// Work with each record
|
|
108
|
+
// record.name = toTitleCase(record.name)
|
|
109
|
+
records.push(record);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
await finished(parser);
|
|
113
|
+
return records;
|
|
114
|
+
};
|
package/src/generate.ts
CHANGED
|
@@ -6,21 +6,26 @@ function genJson(c: Computed) {
|
|
|
6
6
|
fs.writeFileSync(args.output + "/json/voivodeships.json", JSON.stringify(c.voivodeships))
|
|
7
7
|
fs.writeFileSync(args.output + "/json/counties.json", JSON.stringify(c.counties))
|
|
8
8
|
fs.writeFileSync(args.output + "/json/municipalities.json", JSON.stringify(c.municipalities))
|
|
9
|
+
fs.writeFileSync(args.output + "/json/localities.json", JSON.stringify(c.localities.Get3Deep()))
|
|
10
|
+
fs.writeFileSync(args.output + "/json/districts.json", JSON.stringify(c.districts.Get4Deep()))
|
|
11
|
+
|
|
9
12
|
}
|
|
10
13
|
|
|
11
14
|
function genGo(c: Computed) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
fs.copyFileSync(args.output + "/json/voivodeships.json", args.output + "/go/voivodeships.json")
|
|
16
|
+
fs.copyFileSync(args.output + "/json/counties.json", args.output + "/go/counties.json")
|
|
17
|
+
fs.copyFileSync(args.output + "/json/municipalities.json", args.output + "/go/municipalities.json")
|
|
18
|
+
fs.copyFileSync(args.output + "/json/localities.json", args.output + "/go/localities.json")
|
|
19
|
+
fs.copyFileSync(args.output + "/json/districts.json", args.output + "/go/districts.json")
|
|
16
20
|
const data = `package poland
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
import (
|
|
22
|
+
"embed"
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
//go:embed *.json
|
|
26
|
+
var FS embed.FS
|
|
27
|
+
`
|
|
28
|
+
fs.writeFileSync(args.output + "/go/root.go", data)
|
|
24
29
|
}
|
|
25
30
|
|
|
26
31
|
function genTypescript(c: Computed) {
|
package/src/map.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { NamesMapThreeKeys, NamesMapFourKeys, NamesMapTwoKeys } from "./compute";
|
|
2
|
+
|
|
3
|
+
export class MultiKeyMap {
|
|
4
|
+
private map: Record<string, any> = {};
|
|
5
|
+
|
|
6
|
+
private getKey(key: string[]): string {
|
|
7
|
+
return key.join('|');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
set(key: string[], value: any): void {
|
|
11
|
+
const strKey = this.getKey(key);
|
|
12
|
+
this.map[strKey] = value;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
get(key: string[]): any | undefined {
|
|
16
|
+
const strKey = this.getKey(key);
|
|
17
|
+
return this.map[strKey];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
delete(key: string[]): boolean {
|
|
21
|
+
const strKey = this.getKey(key);
|
|
22
|
+
|
|
23
|
+
if (strKey in this.map) {
|
|
24
|
+
delete this.map[strKey];
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
has(key: string[]): boolean {
|
|
32
|
+
const strKey = this.getKey(key);
|
|
33
|
+
return strKey in this.map;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get size(): number {
|
|
37
|
+
return Object.keys(this.map).length;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
clear(): void {
|
|
41
|
+
this.map = {};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
sortValues(): void {
|
|
45
|
+
for (const strKey in this.map) {
|
|
46
|
+
let value = this.map[strKey];
|
|
47
|
+
value.sort()
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
forEach(callbackfn: (keys: string[], value: any, map: MultiKeyMap) => void): void {
|
|
52
|
+
for (const strKey in this.map) {
|
|
53
|
+
const value = this.map[strKey];
|
|
54
|
+
const keys = strKey.split('|');
|
|
55
|
+
callbackfn(keys, value, this);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
Get3Deep(): NamesMapThreeKeys {
|
|
60
|
+
var out: NamesMapThreeKeys = {}
|
|
61
|
+
this.forEach((keys, value) => {
|
|
62
|
+
const [v, c, m] = keys
|
|
63
|
+
if (!out[v]) {
|
|
64
|
+
out[v] = {}
|
|
65
|
+
}
|
|
66
|
+
if (!out[v][c]) {
|
|
67
|
+
out[v][c] = {}
|
|
68
|
+
}
|
|
69
|
+
if (!out[v][c][m]) {
|
|
70
|
+
out[v][c][m] = []
|
|
71
|
+
}
|
|
72
|
+
out[v][c][m].push(value)
|
|
73
|
+
})
|
|
74
|
+
return out
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
Get4Deep(): NamesMapFourKeys {
|
|
78
|
+
var out: NamesMapFourKeys = {}
|
|
79
|
+
this.forEach((keys, value) => {
|
|
80
|
+
const [v, c, m, l] = keys
|
|
81
|
+
if (!out[v]) {
|
|
82
|
+
out[v] = {}
|
|
83
|
+
}
|
|
84
|
+
if (!out[v][c]) {
|
|
85
|
+
out[v][c] = {}
|
|
86
|
+
}
|
|
87
|
+
if (!out[v][c][m]) {
|
|
88
|
+
out[v][c][m] = {}
|
|
89
|
+
}
|
|
90
|
+
if (!out[v][c][m][l]) {
|
|
91
|
+
out[v][c][m][l] = []
|
|
92
|
+
}
|
|
93
|
+
out[v][c][m][l].push(value)
|
|
94
|
+
})
|
|
95
|
+
return out
|
|
96
|
+
}
|
|
97
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
12
12
|
|
|
13
13
|
/* Language and Environment */
|
|
14
|
-
"target": "
|
|
14
|
+
"target": "ES6", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
15
15
|
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
16
16
|
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
17
17
|
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
/* Modules */
|
|
28
28
|
"module": "CommonJS", /* Specify what module code is generated. */
|
|
29
29
|
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
30
|
-
|
|
30
|
+
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
31
31
|
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
32
32
|
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
33
33
|
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
49
49
|
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
50
50
|
"sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
51
|
-
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
52
|
-
|
|
51
|
+
// "outFile": "./out.js", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
52
|
+
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
|
53
53
|
// "removeComments": true, /* Disable emitting comments. */
|
|
54
54
|
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
55
55
|
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|