26 lines
819 B
JavaScript
26 lines
819 B
JavaScript
const fs = require('fs')
|
|
const path = require('path')
|
|
const infile = path.join(__dirname, '..', '..', 'CH.txt')
|
|
const out = fs.readFileSync(infile, 'utf8')
|
|
const lines = out.split(/\r?\n/)
|
|
const map = new Map()
|
|
for (const line of lines) {
|
|
if (!line || line.trim() === '') continue
|
|
const parts = line.split('\t')
|
|
const zip = parts[1]
|
|
const name = parts[2]
|
|
const canton = parts[4] || ''
|
|
if (!zip) continue
|
|
if (!map.has(zip)) {
|
|
map.set(zip, { zip, city: name, canton })
|
|
}
|
|
}
|
|
const arr = Array.from(map.values())
|
|
function escapeStr(s){ return String(s).replace(/\\/g,'\\\\').replace(/'/g, "\\'") }
|
|
let ts = 'export const SWISS_CITIES = [\n'
|
|
for (const e of arr) {
|
|
ts += ` { zip: '${escapeStr(e.zip)}', city: '${escapeStr(e.city)}', canton: '${escapeStr(e.canton)}' },\n`
|
|
}
|
|
ts += ']\n'
|
|
console.log(ts)
|