Add linked Chinese postal code input and lookup data
This commit is contained in:
1 parent
3f685ca068
commit
1e43d910c0
8 files changed
+141
-4
No files matched your search
@@ -0,0 +1,17 @@
|
||||
import { readFile, writeFile } from 'node:fs/promises'
|
||||
import { resolve } from 'node:path'
|
||||
|
||||
const [inputFile, outputFile] = process.argv.slice(2)
|
||||
|
||||
if (!inputFile || !outputFile) {
|
||||
throw new Error('用法:node scripts/generate-china-postcode-data.mjs <china_zipcode_adcode.json> <输出文件>')
|
||||
}
|
||||
|
||||
const sourceData = JSON.parse(await readFile(resolve(inputFile), 'utf8'))
|
||||
const rows = sourceData
|
||||
.filter((row) => /^\d{6}$/.test(row.code) && /^\d{6}$/.test(row.zipCode))
|
||||
.map((row) => [row.code, row.zipCode])
|
||||
|
||||
const source = `// 由 tombcato/china-zipcode-data 的 china_zipcode_adcode.json 生成。\n// 上游项目采用 MIT License:https://github.com/tombcato/china-zipcode-data\nexport type ChinaPostcodeRow = readonly [districtCode: string, postcode: string]\n\nexport const chinaPostcodeRows: readonly ChinaPostcodeRow[] = ${JSON.stringify(rows)} as const\n`
|
||||
|
||||
await writeFile(resolve(outputFile), source, 'utf8')
|
||||
Reference in new issue
Block a user