项目作者: b4dnewz

项目描述 :
Convert an object to a suitable argv array
高级语言: TypeScript
项目地址: git://github.com/b4dnewz/object-to-argv.git
创建时间: 2019-07-31T19:13:41Z
项目社区:https://github.com/b4dnewz/object-to-argv

开源协议:MIT License

下载


object-to-argv

Convert an object to a suitable argv array

@b4dnewz/object-to-argv">NPM version Build Status Coverage percentage

Install

  1. npm install @b4dnewz/object-to-argv

Usage

  1. import objectToArgv from "@b4dnewz/object-to-argv"
  2. objectToArgv({
  3. c: true,
  4. baz: false,
  5. foo: "bar",
  6. arr: ["a", "b"]
  7. })
  8. // ["-c", "--no-baz", "--foo", "bar", "--arr", "a", "b"]

You can also add positional arguments setting the value to null

  1. objectToArgv({
  2. foo: null,
  3. bar: true
  4. })
  5. // ["foo", "--bar"]

Options

Here a list of options that can be used when converting objects to argv array, simply pass them as second argument to the conversion function.

normalize

When enabled it will normalize the object key names and the final argv flags to kebab-case, by default is true.

  1. objectToArgv({ fooBar: true })
  2. // ["--foo-bar"]
  3. objectToArgv({ fooBar: true }, {
  4. normalize: false
  5. })
  6. // ["--fooBar"]

booleanNegation

When enabled it will add --no prefix before the boolean flags, otherwise if disabled it will simply omit the keys that have a falsy value, by default is true.

  1. objectToArgv({ foo: false })
  2. // ["--no-foo"]
  3. objectToArgv({ foo: false }, {
  4. booleanNegation: false
  5. })
  6. // []

arraySeparator

This option allow to customize the separator used for array values, when false it will output each array element in it’s own place, otherwise if is a string it will be used as separator.

  1. objectToArgv({ foo: ["bar", "baz"] })
  2. // ["--foo", "bar", "baz"]
  3. objectToArgv({ foo: ["bar", "baz"] }, {
  4. arraySeparator: ","
  5. })
  6. // ["--foo", "bar,baz"]

License

MIT © Filippo Conti