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

argcat

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

argcat - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

18

index.d.ts

@@ -20,2 +20,16 @@ export interface ParseArgsOptions {

}
export interface ParsedArgs {
/**
* Keys parsed from the args.
*/
[key: string]: string[] | true | undefined;
/**
* List of args that weren't associated with any key.
*/
'': string[];
/**
* List of args after `'--'` arg, or `undefined` if there were no `'--'` arg.
*/
'--'?: string[];
}
/**

@@ -27,4 +41,2 @@ * Parses process arguments and returns a map from an option name to its value.

*/
export declare function parseArgs(args: string[], options?: ParseArgsOptions): {
[key: string]: string[] | true;
};
export declare function parseArgs(args: string[], options?: ParseArgsOptions): ParsedArgs;

2

index.js

@@ -14,3 +14,3 @@ "use strict";

var flags = options.flags, shorthands = options.shorthands, keepShorthands = options.keepShorthands;
var result = {};
var result = { '': [] };
var key = '';

@@ -17,0 +17,0 @@ for (var i = 0; i < args.length; ++i) {

{
"name": "argcat",
"version": "1.0.0",
"version": "1.0.1",
"description": "The simplest CLI arguments parser.",

@@ -5,0 +5,0 @@ "main": "./index.js",

@@ -1,2 +0,6 @@

# argcat
<p align="center">
<a href="#readme">
<img src="./logo.png" alt="argcat" width="450"/>
</a>
</p>

@@ -41,3 +45,3 @@ The simplest CLI arguments parser.

Arguments that aren't prefixed are stored under `''` key:
Arguments that aren't prefixed with minus chars are stored under `''` key:

@@ -92,3 +96,3 @@ ```ts

Use `shorthand` mapping to expand shorthands:
Use `shorthand` mapping to expand shorthands:

@@ -100,2 +104,30 @@ ```ts

# Commands
argcat doesn't have a special treatment for commands syntax, but it can be easily emulated:
```ts
const argv = ['push', '--tags'];
const result = parseArgs(argv, { flags: ['tags'] });
// ⮕ { '': ['push'], tags: true }
```
The first element of `''` is a command:
```ts
const command = result[''].pop();
if (command === 'push') {
// Push it to the limit
}
```
Note that this approach allows user to specify options before the command:
```ts
const result = parseArgs(['--tags', 'push'], { flags: ['tags'] });
// ⮕ { '': ['push'], tags: true }
```
# Type coercion

@@ -115,3 +147,3 @@

const options = argsShape.parse(
// 😉 Use process.argv.slice(2) instead of an array here
// 🟡 This comes from process.argv.slice(2)
parseArgs(['--age', '42']),

@@ -122,1 +154,7 @@ { coerce: true }

```
<hr>
<p align="center">
Cat by <a href="https://www.instagram.com/lauragravesart/">Laura Graves</a>
</p>

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