Socket
Socket
Sign inDemoInstall

args-flags

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.1.0

2

index.d.ts
export const args: string[]
export const flags: Record<string, string>
export const flags: Record<string, boolean | number | string>
const args = []
const flags = Object.fromEntries(
process.argv
.slice(2)
.filter((arg) => {
const isFlag = arg.includes('=')
if (!isFlag) {
args.push(arg)
}
return isFlag
})
.map((arg) => {
const [key, value] = arg.split('=')
return [key.slice(2), value]
})
)
const flags = {}
process.argv.slice(2).forEach((arg) => {
if (!arg.includes('--')) {
args.push(arg)
return
}
let [key, value] = arg.split('=')
const isNumber = !isNaN(value)
const isFloat = value.includes('.')
if (isNumber) {
if (isFloat) {
value = parseFloat(value)
} else {
value = Number(value)
}
}
if (value === 'true') {
value = true
}
if (value === 'false') {
value = false
}
if (value === undefined) {
value = true
}
flags[key.slice(2)] = value
})
module.exports = { args, flags }
{
"name": "args-flags",
"version": "1.0.0",
"version": "1.1.0",
"author": "Travis Arnold",

@@ -5,0 +5,0 @@ "description": "A simple command line argument parser.",

# args-flags
A no frills command line parser for Node.
A simple command line argument parser.

@@ -17,8 +17,24 @@ ## Install

```json
{
"scripts": {
"build": "node scripts/build.js README.mdx > README.md"
}
}
```
Now we have access to the arguments and flags in `scripts/build.js` derived from `process.argv`:
```js
#!/bin/env node
import { args, flags } from 'args-flags'
import { watch } from 'chokidar'
const [optionOne, optionTwo] = args
flags.watch
if (flags.watch) {
watch('./src').on('change', () => {
console.log('source changed')
})
}
```
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc