Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate dependency on minimist #215

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 71 additions & 20 deletions bin/csv-parser
Original file line number Diff line number Diff line change
@@ -1,32 +1,83 @@
#!/usr/bin/env node

const { EOL } = require('os')
const minimist = require('minimist')
const { Transform } = require('stream');
const fs = require('fs')
const csv = require('../')
const pkg = require('../package.json')

const argv = minimist(process.argv, {
alias: {
c: 'skipComments',
e: 'escape',
h: 'headers',
o: 'output',
q: 'quote',
l: 'skipLines',
s: 'separator',
v: 'version'
},
default: {
e: '"',
q: '"',
s: ','
},
boolean: ['version', 'help']
})
function parseArgs () {
let skipComments
let escape = '"'
let headers
let output
let quote = '"'
let skipLines
let separator = ','
let version
let help
const defaultArgs = []

const [,, filename] = argv._
const args = process.argv.slice(2)
for (let i = 0; i < args.length; i++) {
const arg = args[i]
switch (arg) {
case '--skipComments':
case '-c':
skipComments = args[++i]
break
case '--escape':
case '-e':
escape = args[++i]
break
case '--headers':
case '-h':
headers = args[++i]
break
case '--output':
case '-o':
output = args[++i]
break
case '--quote':
case '-q':
quote = args[++i]
break
case '--skipLines':
case '-l':
skipLines = args[++i]
break
case '--separator':
case '-s':
separator = args[++i]
break
case '--version':
case '-v':
version = true
break
case '--help':
help = true
break
default:
defaultArgs.push(arg)
break
}
}
return {
skipComments,
escape,
headers,
output,
quote,
skipLines,
separator,
version,
help,
defaultArgs
}
}

const argv = parseArgs()
const [filename] = argv.defaultArgs

if (argv.version) {
console.log(pkg.version)
Expand Down
11 changes: 6 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
"security": "npm audit",
"test": "ava && tsd"
},
"dependencies": {
"minimist": "^1.2.0"
},
"devDependencies": {
"@commitlint/cli": "^8.2.0",
"@commitlint/config-conventional": "^8.0.0",
Expand Down