Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

csvnorm

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

csvnorm - npm Package Compare versions

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))
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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc