Last active
October 4, 2022 01:53
-
-
Save champierre/ddf80c3079eeade45a9b0f00f2ede75b to your computer and use it in GitHub Desktop.
https://github.com/geolonia/japanese-addresses/pull/123 で csv ファイルから patches 用の json ファイルに変換するために使った。
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
#!/usr/bin/env node | |
const fs = require('fs') | |
const csvParse = require('csv-parse/lib/sync') | |
const csvFile = process.argv[2] | |
const reference = process.argv[3] | |
const buffer = fs.readFileSync(csvFile) | |
const formatDate = date => { | |
const year = date.getFullYear(); | |
const month = ('00' + (date.getMonth() + 1)).slice(-2) | |
const day = ('00' + date.getDate()).slice(-2) | |
return `${year}/${month}/${day}` | |
} | |
const csvData = csvParse(buffer, { | |
columns: [ | |
'都道府県コード', | |
'都道府県名', | |
'都道府県名カナ', | |
'都道府県名ローマ字', | |
'市区町村コード', | |
'市区町村名', | |
'市区町村名カナ', | |
'市区町村名ローマ字', | |
'大字町丁目名', | |
'大字町丁目名カナ', | |
'大字町丁目名ローマ字', | |
'小字・通称名', | |
'緯度', | |
'経度', | |
], | |
}) | |
const additions = { 参照: reference, 更新日: formatDate(new Date()) } | |
const json = JSON.stringify( | |
csvData.map(data => { return { ...data, ...additions } }), null, 2, | |
) | |
console.log(json) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment