generate-timezone-json
Advanced tools
Comparing version 0.0.3 to 0.0.4
55
index.js
@@ -0,6 +1,5 @@ | ||
const fs = require("fs"); | ||
const fs = require('fs'); | ||
console.log("Generating Timezone JSON"); | ||
console.log('Generating Timezone JSON'); | ||
const args = process.argv; | ||
@@ -10,12 +9,46 @@ | ||
// no file | ||
const tzdb = require('@vvo/tzdb'); | ||
console.log('... from IANA Database'); | ||
const data = tzdb.getTimeZones({includeUtc: true}); | ||
fs.writeFile('timezones.json', JSON.stringify(data), (err) => { | ||
const tzdb = require("@vvo/tzdb"); | ||
console.log("... from IANA Database"); | ||
const data = JSON.stringify(tzdb.getTimeZones({ includeUtc: true }).sort(compare)); | ||
writeToFile(data); | ||
} else { | ||
// file name | ||
const fileName = args[2]; | ||
const parseZonetab = require("parse-zonetab"); | ||
console.log("... from file", fileName); | ||
fs.readFile(fileName, (err, raw) => { | ||
if (err) throw err; | ||
console.log('... done writing to file: timezones.json'); | ||
parseZonetab(raw).then(rows => { | ||
const data = JSON.stringify(rows.sort(compare)); | ||
writeToFile(data); | ||
}); | ||
}); | ||
} else { | ||
const fileName = args[2] | ||
console.log('... from file', fileName); | ||
} | ||
function writeToFile(data) { | ||
fs.writeFile("timezones.json", data, (err) => { | ||
if (err) throw err; | ||
console.log("... done writing to file: timezones.json"); | ||
}); | ||
} | ||
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.0.3", | ||
"version": "0.0.4", | ||
"description": "Generate JSON file containing timezones from a tab file or the official IANA database", | ||
@@ -10,2 +10,5 @@ "main": "index.js", | ||
}, | ||
"bin": { | ||
"generate-timezone-json": "./index.js" | ||
}, | ||
"repository": { | ||
@@ -12,0 +15,0 @@ "type": "git", |
@@ -10,9 +10,12 @@ # Generate Timezone JSON | ||
- this will generate a file named "timezones.json" with data coming from the official IANA database | ||
1. Run: `generate-timezone-json <filename>` to generate timezones.json from a TAB file, | ||
- for example, using a file named "zone.tab": `generate-timezone-json zone.tab` | ||
### Gotchas | ||
1. Note that the structure of the generated JSON file will be different depending on the source (i.e, zone.tab or the IANA timezones database) | ||
### Planned features (not yet implemented) | ||
1. To generate timezones.json from a TAB file, run: `generate-timezone-json <filename>` | ||
- for example, using a file named "zone.tab": `generate-timezone-json zone.tab` | ||
2. Specify an output directory with option `--outDir`: `generate-timezone <filename> --outDir <directory>` | ||
1. Specify an output directory with option `--outDir`: `generate-timezone <filename> --outDir <directory>` | ||
Sorry, the diff of this file is too big to display
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
173757
5
39
21