@peacefultruth/butterfly

11.0.0 • Public • Published

butterfly

process arguments from a data description.

just pass me the description of the process argv, I will return you the parsed format.

yarn add @peacefultruth/butterfly
import butterfly from '@peacefultruth/butterfly';

const process_arguments = (
  process.argv || (
    [
      'node',
      'entry.js',

      'blah',
      '3.14',
      '-b',
      '4.14',
      '--blah',
      '5.14',

      'blahblah',
      '100',
      '-bb',
      '200',
      '--blahblah',
      '300',
      '--blah-blah',
      '400',
    ]
  )
);

expect(
  butterfly(
    {
      blah: {
        aliases: ['-b', '--blah'],
        is_multiple_lazy: true,
        type: Number,
        value: -1,
      },
      blahblah: {
        aliases: ['-bb', '--blahblah', '--blah-blah'],
        is_multiple_lazy: true,
        type: Number,
        value: -1,
      },
    },
    process_arguments
  )
).toEqual(
  {
    blah: {
      aliases: ['-b', '--blah'],
      is_multiple_lazy: true,
      type: Number,
      value: [3.14, 4.14, 5.14],
    },
    blahblah: {
      aliases: ['-bb', '--blahblah', '--blah-blah'],
      is_multiple_lazy: true,
      type: Number,
      value: [100, 200, 300, 400],
    },
  }
)

Readme

Keywords

none

Package Sidebar

Install

npm i @peacefultruth/butterfly

Weekly Downloads

3

Version

11.0.0

License

MIT

Unpacked Size

227 kB

Total Files

33

Last publish

Collaborators

  • peacefultruth