generate-timezone-json
Advanced tools
Comparing version 0.1.6 to 0.2.0
51
index.js
#!/usr/bin/env node | ||
const fs = require('fs'); | ||
const args = process.argv; | ||
console.log("Generating Timezone JSON"); | ||
const args = process.argv; | ||
if (args.length < 3) { | ||
// no file | ||
const tzdb = require("@vvo/tzdb"); | ||
const data = JSON.stringify(tzdb.getTimeZones({ includeUtc: true })); | ||
console.log("... from IANA Database"); | ||
const data = JSON.stringify(tzdb.getTimeZones({ includeUtc: true })); | ||
writeToFile(data); | ||
@@ -18,21 +18,30 @@ } else { | ||
const fileName = args[2]; | ||
const parseZonetab = require("parse-zonetab"); | ||
console.log("... from file", fileName); | ||
if (isTabFile(fileName)) { | ||
const parseZonetab = require("parse-zonetab"); | ||
fs.readFile(fileName, (err, raw) => { | ||
fs.readFile(fileName, (err, raw) => { | ||
if (err) throw err; | ||
parseZonetab(raw).then(rows => { | ||
const data = JSON.stringify(rows); | ||
console.log("... from file", fileName); | ||
writeToFile(data); | ||
}); | ||
if (err) throw err; | ||
parseZonetab(raw).then(rows => { | ||
const data = JSON.stringify(rows); | ||
writeToFile(data); | ||
}); | ||
} else { | ||
console.error('Error: input not a TAB file', fileName) | ||
} | ||
} | ||
function isTabFile(fileName) { | ||
if (!!fileName && fileName !== '') { | ||
const extension = fileName.split('.')[1]; | ||
return extension === 'tab'; | ||
} | ||
}); | ||
return false; | ||
} | ||
function writeToFile(data) { | ||
fs.writeFile("timezones.json", data, (err) => { | ||
@@ -43,17 +52,1 @@ if (err) throw err; | ||
} | ||
/* | ||
function compare(a, b) { | ||
const bid = b.id || b.name; | ||
const aid = a.id || a.name; | ||
if (aid < bid) { | ||
return -1; | ||
} | ||
if (aid > bid) { | ||
return 1; | ||
} | ||
return 0; | ||
}; | ||
*/ | ||
{ | ||
"name": "generate-timezone-json", | ||
"version": "0.1.6", | ||
"version": "0.2.0", | ||
"bin": "./index.js", | ||
@@ -5,0 +5,0 @@ "description": "Generate JSON file containing timezones from a tab file or the official IANA database", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3672
40