New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

minimist-string

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

minimist-string

A minimist extension to parse command line sentences as strings

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

minimist-string

minimist-string is a minimist wrapper that is able to pasrse command line sentences as strings. The problem with minimist is that you need to give the arguments in an array with every argument in separated strings (as in node's process.argv). The following wouldn't work:

console.log(minimist(['foo --bar "Hello!"']));
// { _: [ 'foo --bar "Hello!"' ] } wich is not what we want

The next logical step is doing:

console.log(minimist('foo --bar "Hello!"'.split(' ')));
// { _: [ 'foo' ], bar: '"Hello!"' }

That actually returns what we expect. The problem comes when the user-defined string has spaces:

console.log(minimist('foo --bar "Hello world!"'.split(' ')));
// { _: [ 'foo', 'world!"' ], bar: '"Hello' }

Only "Hello gets to the bar parameter, while the rest of it gets to argv._, wich is a disaster. minimist-string solves this problem:

Usage

npm install --save minimist-string
const parseSentence = require('minimist-string');

console.log(parseSentence('foo --bar "Hello world!"'));
// { _: [ 'foo' ], bar: 'Hello world!' }

It even works with escaped quotes!

console.log(parseSentence('foo --bar "Hello \\"world\\"!"'));
// { _: [ 'foo' ], bar: 'Hello "world"!' }

Keywords

minimist

FAQs

Package last updated on 09 Feb 2017

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