Socket
Socket
Sign inDemoInstall

mri

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    mri

Quickly scan for CLI flags and arguments


Version published
Weekly downloads
7.8M
increased by0.56%
Maintainers
1
Install size
8.45 kB
Created
Weekly downloads
 

Package description

What is mri?

The mri npm package is a lightweight option parsing library. It allows for easy parsing of command-line options, providing a simple API to access command-line arguments in a structured way. It's designed for performance and simplicity, making it a great choice for projects that require basic yet efficient argument parsing without the overhead of more complex libraries.

What are mri's main functionalities?

Basic Option Parsing

This code demonstrates how to parse command-line arguments using mri. It slices the process.argv array to ignore the first two entries (node path and script path), then parses the remaining arguments into an options object.

const mri = require('mri');
const args = process.argv.slice(2);
const options = mri(args);
console.log(options);

Specifying Option Types

This example shows how to specify the types of options (boolean, string) and aliases for them. This helps in parsing the command-line arguments more accurately according to the expected types and aliases.

const mri = require('mri');
const args = process.argv.slice(2);
const cliOptions = {
  boolean: ['help', 'version'],
  string: ['output'],
  alias: { h: 'help', v: 'version', o: 'output' }
};
const options = mri(args, cliOptions);
console.log(options);

Other packages similar to mri

Readme

Source

mri Build Status

Quickly scan for CLI flags and arguments

This is a very basic, fast, and lightweight alternative to minimist. It only exists because I find that I usually don't need most of what minimist has to offer.

For now, there's no configuration options. Instead, mri just parses raw CLI flags (single or group) and assigns a value to those keys.

Note: Defaults, aliases, and type-casting are not supported. However, this may change in the future. :thinking:

Install

$ npm install --save mri

Usage

$ demo-cli --foo --bar=baz -mtv -- hello world
const mri = require('mri');

const args = process.argv.slice(2);

mri(args);
//=> { _: ['hello', 'world'], foo:true, bar:'baz', m:true, t:true, v:true }

API

mri(args)

args

Type: array
Default: []

An array of arguments to parse. For CLI usage, send process.argv.slice(2). See process.argv for info.

License

MIT © Luke Edwards

Keywords

FAQs

Last updated on 16 Apr 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc