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

deez-argv

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deez-argv

A package for deserializing argument lists

  • 1.0.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

deez-argv

A left-pad inspired package for deserializing an argument list to a Record

Install via the plethora of available package managers!!!!

$ npm i deez-argv
$ yarn add deez-argv
$ pnpm i deez-argv
$ bun i deez-argv

By default process.argv is passed if no argument is given.

const args = deserializeArgumentList();
// ^? Record<string, string>

You can also pass a custom argument list with a custom starting point

const args = deserializeArgumentList(['--foo', 'bar', '-baz=qar'], 0);
// ^? Record<string, string>

The starting point otherwise defaults to 2 for compatibility with process.argv.

You can then pass that object to whatever validation you desire.

const argSchema = z.object({foo: z.string(), baz: z.string()});
const args = argSchema.parse(deserializeArgumentList());
// ^? {foo:string, baz:string}

- and -- denotes an argument that should be parsed. If an argument is followed by another argument, it is assumed to be a boolean flag. Otherwise values can be passed either with a = or with a space. You can use commas to pass multiple values into an array.

$ node index.js --foo bar -biz --baz=qar --qux --shows interstellar,bum, pirates
const args = deserializeArgumentList();
// ^? Record<string, string>
assert.deepStrictEqual(args, {
  foo: 'bar',
  biz: true,
  baz: 'qar',
  qux: true,
  shows: ['interstellar', 'bum', 'pirates'],
});

Obviously this library could handle validation and mapping for you, kind of like the Rust Clap-crate, but for now it's just a simple deserializer.

FAQs

Package last updated on 29 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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