Skip to content

parameter-reducers@2.1.0

Latest
Compare
Choose a tag to compare
@ForbesLindesay ForbesLindesay released this 04 Oct 11:41
9942138

New Features

  • Add param.enumString utility to easily specify a parameter that can only have one of a list of defined values. (#14)

    Usage:

    import {startChain, param, parse} from 'parameter-reducers';
    
    const params = startChain().addParam(
      param.enumString(['-l', '--level'], 'level', [
        'info',
        'warn',
        'error',
      ] as const),
    );
    
    const {level = 'error'} = parse(params, process.argv.slice(2)).extract();
    
    if (level === 'info') {
      console.info('Some info');
    }
    if (level === 'info' || 'warn') {
      console.warn('Some warning');
    }
    console.warn('Some error');
  • Add param.positionalEnumString utility to easily specify a positional parameter that can only have one of a list of defined values. (#14)

    Usage:

    import {startChain, param, parse} from 'parameter-reducers';
    
    const params = startChain().addParam(
      param.positionalEnumString('env', ['staging', 'production'] as const),
    );
    
    const {env = 'staging'} = parse(params, process.argv.slice(2)).extract();
    
    if (env === 'staging') {
      console.info('Deploying to staging');
    }
    if (env === 'production') {
      console.warn('Deploying to production');
    }