From 42576cbd600ceaa5894fb6fdc8b7c06b0ec1838e Mon Sep 17 00:00:00 2001 From: Anirudh Buvanesh Date: Tue, 22 Mar 2022 14:08:41 +0530 Subject: [PATCH] Eliminate dependency on minimist --- bin/csv-parser | 91 ++++++++++++++++++++++++++++++++++++----------- package-lock.json | 11 +++--- package.json | 3 -- 3 files changed, 77 insertions(+), 28 deletions(-) diff --git a/bin/csv-parser b/bin/csv-parser index f895a8e..57c28e1 100755 --- a/bin/csv-parser +++ b/bin/csv-parser @@ -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) diff --git a/package-lock.json b/package-lock.json index 4ab0c38..72403d0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "csv-parser", - "version": "2.3.3", + "version": "3.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -871,9 +871,9 @@ "dev": true }, "@types/glob": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.1.1.tgz", - "integrity": "sha512-1Bh06cbWJUHMC97acuD6UMG29nMt0Aqz1vF3guLfG+kHHJhy3AyohZFFxYk2f7Q1SQIrNwvncxAE0N/9s70F2w==", + "version": "7.2.0", + "resolved": "https://nexus.soma.salesforce.com/nexus/content/groups/npm-all/@types/glob/-/glob-7.2.0.tgz", + "integrity": "sha512-ZUxbzKl0IfJILTS6t7ip5fQQM/J3TJYubDm3nMbgubNNYS62eXeUpoLUC8/7fJNiFYHTrGPQn7hspDUzIHX3UA==", "dev": true, "requires": { "@types/events": "*", @@ -5797,7 +5797,8 @@ "minimist": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", + "dev": true }, "minimist-options": { "version": "3.0.2", diff --git a/package.json b/package.json index 7e22065..f303372 100644 --- a/package.json +++ b/package.json @@ -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",