Comparing version 0.3.1 to 0.4.0
56
cli.js
#! /usr/bin/env node | ||
const path = require('path') | ||
const yargs = require('yargs') | ||
const csvnorm = require('.') | ||
@@ -16,24 +18,52 @@ const {stdin, stdout, argv} = process | ||
function main (args) { | ||
const csvFilePath = args[0] | ||
const options = yargs | ||
.usage( | ||
[ | ||
'Usage:', | ||
' csvnorm [Options] INFILE [> OUTFILE]', | ||
' csvnorm [Options] < INFILE [> OUTFILE]', | ||
].join('\n') | ||
) | ||
.options({ | ||
'in-place': { | ||
describe: 'Normalize CSV file in place', | ||
type: 'boolean', | ||
default: false, | ||
}, | ||
}) | ||
.example('csvnorm input.csv > normalized.csv') | ||
.example('cat input.csv | csvnorm > normalized.csv') | ||
.version() | ||
.help() | ||
.parse(args) | ||
if (csvFilePath) { | ||
if (options._.length === 0) { | ||
if (options.inPlace) { | ||
console.error('Error: --in-place has no effect with input from stdin') | ||
} | ||
if (stdin.isTTY) { | ||
yargs.showHelp() | ||
return | ||
} | ||
if (stdout.isTTY) logMetaInfos() | ||
csvnorm({filePath: path.resolve(csvFilePath)}) | ||
return | ||
csvnorm({ | ||
readableStream: stdin, | ||
writableStream: stdout, | ||
}) | ||
} | ||
else { | ||
const csvFilePath = options._[0] | ||
if (stdin.isTTY) { | ||
console.info('Usage: csvnorm $input_file > $output_path') | ||
if (stdout.isTTY) logMetaInfos() | ||
csvnorm({ | ||
filePath: path.resolve(csvFilePath), | ||
inPlace: options.inPlace, | ||
}) | ||
return | ||
} | ||
if (stdout.isTTY) logMetaInfos() | ||
csvnorm({ | ||
readableStream: stdin, | ||
writableStream: stdout, | ||
}) | ||
} | ||
main(argv.slice(2)) |
17
index.js
const fs = require('fs') | ||
const path = require('path') | ||
const assert = require('assert') | ||
const stream = require('stream') | ||
@@ -88,6 +90,7 @@ | ||
const { | ||
filePath, | ||
inPlace, | ||
readableStream, | ||
writableStream, | ||
} = options | ||
const { filePath } = options | ||
let {writableStream} = options | ||
const config = {} | ||
@@ -188,2 +191,4 @@ | ||
if (filePath) { | ||
assert(path.isAbsolute(filePath)) | ||
fs | ||
@@ -193,2 +198,10 @@ .createReadStream(filePath) | ||
if (inPlace) { | ||
const temporaryFilePath = tempfile('.csv') | ||
writableStream = fs.createWriteStream(temporaryFilePath) | ||
writableStream.on('finish', () => { | ||
fs.rename(temporaryFilePath, filePath, console.error) | ||
}) | ||
} | ||
configGenerator.on('finish', () => { | ||
@@ -195,0 +208,0 @@ printCsv({ |
{ | ||
"name": "csvnorm", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"description": "Command line tool to normalize CSV and *SV files.", | ||
@@ -17,3 +17,4 @@ "main": "index.js", | ||
"jschardet": "^1.4.2", | ||
"tempfile": "^2.0.0" | ||
"tempfile": "^2.0.0", | ||
"yargs": "^8.0.2" | ||
}, | ||
@@ -20,0 +21,0 @@ "author": "Adrian Sieber <mail@adriansieber.com>", |
Sorry, the diff of this file is not supported yet
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
25486
289
6
+ Addedyargs@^8.0.2
+ Addedansi-regex@2.1.13.0.1(transitive)
+ Addedcamelcase@4.1.0(transitive)
+ Addedcliui@3.2.0(transitive)
+ Addedcode-point-at@1.1.0(transitive)
+ Addedcross-spawn@5.1.0(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addederror-ex@1.3.2(transitive)
+ Addedexeca@0.7.0(transitive)
+ Addedfind-up@2.1.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-caller-file@1.0.3(transitive)
+ Addedget-stream@3.0.0(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhosted-git-info@2.8.9(transitive)
+ Addedinvert-kv@1.0.0(transitive)
+ Addedis-arrayish@0.2.1(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedis-fullwidth-code-point@1.0.02.0.0(transitive)
+ Addedis-stream@1.1.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedlcid@1.0.0(transitive)
+ Addedload-json-file@2.0.0(transitive)
+ Addedlocate-path@2.0.0(transitive)
+ Addedlru-cache@4.1.5(transitive)
+ Addedmem@1.1.0(transitive)
+ Addedmimic-fn@1.2.0(transitive)
+ Addednormalize-package-data@2.5.0(transitive)
+ Addednpm-run-path@2.0.2(transitive)
+ Addednumber-is-nan@1.0.1(transitive)
+ Addedos-locale@2.1.0(transitive)
+ Addedp-finally@1.0.0(transitive)
+ Addedp-limit@1.3.0(transitive)
+ Addedp-locate@2.0.0(transitive)
+ Addedp-try@1.0.0(transitive)
+ Addedparse-json@2.2.0(transitive)
+ Addedpath-exists@3.0.0(transitive)
+ Addedpath-key@2.0.1(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpath-type@2.0.0(transitive)
+ Addedpify@2.3.0(transitive)
+ Addedpseudomap@1.0.2(transitive)
+ Addedread-pkg@2.0.0(transitive)
+ Addedread-pkg-up@2.0.0(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedrequire-main-filename@1.0.1(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedshebang-command@1.2.0(transitive)
+ Addedshebang-regex@1.0.0(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedspdx-correct@3.2.0(transitive)
+ Addedspdx-exceptions@2.5.0(transitive)
+ Addedspdx-expression-parse@3.0.1(transitive)
+ Addedspdx-license-ids@3.0.20(transitive)
+ Addedstring-width@1.0.22.1.1(transitive)
+ Addedstrip-ansi@3.0.14.0.0(transitive)
+ Addedstrip-bom@3.0.0(transitive)
+ Addedstrip-eof@1.0.0(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedvalidate-npm-package-license@3.0.4(transitive)
+ Addedwhich@1.3.1(transitive)
+ Addedwhich-module@2.0.1(transitive)
+ Addedwrap-ansi@2.1.0(transitive)
+ Addedy18n@3.2.2(transitive)
+ Addedyallist@2.1.2(transitive)
+ Addedyargs@8.0.2(transitive)
+ Addedyargs-parser@7.0.0(transitive)