Skip to content

Commit

Permalink
cloneDeep;cli tests;better examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mhkeller committed Jan 8, 2017
1 parent 4218648 commit 397d34f
Show file tree
Hide file tree
Showing 13 changed files with 601 additions and 45,043 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ Usage: joiner
-l DATASET_B_KEY
-f (json|geojson) # defaults to `json`
-p NESTED_PATH_ID
-o OUT_FILE_PATH
-o OUT_FILE_PATH # Where to save the file, will write intermediate directories if they don't exist
-d (summary|full) # defaults to `summary`
````

The first four parameters, `-a`, `-k`, `-b` and `-l` are required.

If you specify an output file, it will write the join report to the same directory. For example, `-o path/to/output.csv` will also write `-o path/to/output-report.json`
If you specify an output file, it will write the join result to the specified path and the report to the same directory, creating directories if they don't already exist. For example, `-o path/to/output.csv` will also write `-o path/to/output-report.json`.

`-f` defaults to `json`. `-f geojson` acts the same as the `.geoJson` method above.

Expand Down
27 changes: 13 additions & 14 deletions bin/index.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ var argv = optimist
describe: 'Dataset B key',
default: null
})
.options('f', {
alias: 'format',
describe: 'json or geojson',
default: 'json'
.options('g', {
alias: 'geojson',
describe: 'Are you joining geojson?',
default: false,
boolean: true
})
.options('p', {
alias: 'path',
Expand Down Expand Up @@ -67,7 +68,7 @@ var aPath = argv.a || argv['apath']
var aKey = argv.k || argv['akey']
var bPath = argv.b || argv['bpath']
var bKey = argv.l || argv['bkey']
var format = argv.f || argv['format']
var geojson = argv.g || argv['geojson']
var path = argv.p || argv['path']
var outPath = argv.o || argv['out']
var reportDesc = argv.r || argv['report']
Expand All @@ -92,20 +93,18 @@ q.await(function (err, aData, bData) {
path: path
}

// Join data
if (format !== 'json' && format !== 'geojson') {
throw new Error('Format must be either json or geojson')
}
var jd = joiner[format](config)
var fn = geojson === true ? 'geoJson' : 'left'

// Join data
var jd = joiner[fn](config)
if (outPath !== null) {
io.writeData(outPath, jd.data, function (err) {
io.writeData(outPath, jd.data, {makeDirectories: true}, function (err) {
if (err) {
console.error('Error writing data file', outPath)
throw new Error(err)
}
})
io.writeDataSync(stripExtension(outPath) + 'report.json', jd.report)
io.writeDataSync(stripExtension(outPath) + 'report.json', jd.report, {makeDirectories: true})
} else {
if (reportDesc === 'summary') {
console.log(jd.report.prose.summary)
Expand All @@ -116,10 +115,10 @@ q.await(function (err, aData, bData) {
})

function getDbfOrDataLoader (path) {
io.discernParser(path) === 'dbf' ? io.readDbf : io.readData
return io.discernParser(path) === 'dbf' ? io.readDbf : io.readData
}

function stripExtension (fullPath) {
var ext = io.discernFormat(fullPath)
return fullPath.replace(ext, '')
return fullPath.replace(new RegExp(ext + '$', 'g'), '')
}
15 changes: 15 additions & 0 deletions examples/data/left-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[
{
"id": "1",
"name": "UT"
}, {
"id": "2",
"name": "WY"
}, {
"id": "3",
"name": "CO"
}, {
"id": "4",
"name": "NM"
}
]
14 changes: 14 additions & 0 deletions examples/data/new-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"state_name": "CO",
"avg_temp": 34
},
{
"state_name": "UT",
"avg_temp": 72
},
{
"state_name": "NM",
"avg_temp": 45
}
]
17 changes: 17 additions & 0 deletions examples/data/new-geo-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{
"state_abbr": "CO",
"state_name": "Colorado",
"avg_temp": 34
},
{
"state_abbr": "UT",
"state_name": "Utah",
"avg_temp": 72
},
{
"state_abbr": "NM",
"state_name": "New Mexico",
"avg_temp": 45
}
]
7 changes: 6 additions & 1 deletion examples/data/us-states.geojson

Large diffs are not rendered by default.

0 comments on commit 397d34f

Please sign in to comment.