minimist-options

WebJar for minimist-options

Лицензия

Лицензия

MIT
Группа

Группа

org.webjars.npm
Идентификатор

Идентификатор

minimist-options
Последняя версия

Последняя версия

4.1.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

minimist-options
WebJar for minimist-options
Ссылка на сайт

Ссылка на сайт

https://www.webjars.org
Система контроля версий

Система контроля версий

https://github.com/vadimdemedes/minimist-options

Скачать minimist-options

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.npm/minimist-options/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>minimist-options</artifactId>
    <version>4.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/minimist-options/
implementation 'org.webjars.npm:minimist-options:4.1.0'
// https://jarcasting.com/artifacts/org.webjars.npm/minimist-options/
implementation ("org.webjars.npm:minimist-options:4.1.0")
'org.webjars.npm:minimist-options:jar:4.1.0'
<dependency org="org.webjars.npm" name="minimist-options" rev="4.1.0">
  <artifact name="minimist-options" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='minimist-options', version='4.1.0')
)
libraryDependencies += "org.webjars.npm" % "minimist-options" % "4.1.0"
[org.webjars.npm/minimist-options "4.1.0"]

Зависимости

compile (3)

Идентификатор библиотеки Тип Версия
org.webjars.npm : arrify jar [1.0.1,2)
org.webjars.npm : is-plain-obj jar [1.1.0,2)
org.webjars.npm : kind-of jar [6.0.3,7)

Модули Проекта

Данный проект не имеет модулей.

minimist-options test

Write options for minimist and yargs in a comfortable way. Supports string, boolean, number and array options.

Installation

$ npm install --save minimist-options

Usage

const buildOptions = require('minimist-options');
const minimist = require('minimist');

const options = buildOptions({
	name: {
		type: 'string',
		alias: 'n',
		default: 'john'
	},

	force: {
		type: 'boolean',
		alias: ['f', 'o'],
		default: false
	},

	score: {
		type: 'number',
		alias: 's',
		default: 0
	},

	arr: {
		type: 'array',
		alias: 'a',
		default: []
	},

	strings: {
		type: 'string-array',
		alias: 's',
		default: ['a', 'b']
	},

	booleans: {
		type: 'boolean-array',
		alias: 'b',
		default: [true, false]
	},

	numbers: {
		type: 'number-array',
		alias: 'n',
		default: [0, 1]
	},

	published: 'boolean',

	// Special option for positional arguments (`_` in minimist)
	arguments: 'string'
});

const args = minimist(process.argv.slice(2), options);

instead of:

const minimist = require('minimist');

const options = {
	string: ['name', '_'],
	number: ['score'],
	array: [
		'arr',
		{key: 'strings', string: true},
		{key: 'booleans', boolean: true},
		{key: 'numbers', number: true}
	],
	boolean: ['force', 'published'],
	alias: {
		n: 'name',
		f: 'force',
		s: 'score',
		a: 'arr'
	},
	default: {
		name: 'john',
		f: false,
		score: 0,
		arr: []
	}
};

const args = minimist(process.argv.slice(2), options);

Array options

The array types are only supported by yargs.

minimist does not explicitly support array type options. If you set an option multiple times, it will indeed yield an array of values. However, if you only set it once, it will simply give the value as is, without wrapping it in an array. Thus, effectively ignoring {type: 'array'}.

{type: 'array'} is shorthand for {type: 'string-array'}. To have values coerced to boolean or number, use boolean-array or number-array, respectively.

License

MIT © Vadim Demedes

Версии библиотеки

Версия
4.1.0
3.0.2