dist/tests.js
/**
   * validate option definitions
   * @param {boolean} [caseInsensitive=false] - whether arguments will be parsed in a case insensitive manner
   * @returns {string}
   */
validate option definitions
@param {boolean} [caseInsensitive=false] - whether arguments will be parsed in a case insensitive manner
@returns {string}
validate option definitions @param { boolean } [ caseInsensitive = false ] - whether arguments will be parsed in a case insensitive manner @returns { string }
validate (caseInsensitive) {
    const someHaveNoName = this.some(def => !def.name);
    if (someHaveNoName) {
      halt(
        'INVALID_DEFINITIONS',
        'Invalid option definitions: the `name` property is required on each definition'
      );
    }
    const someDontHaveFunctionType = this.some(def => def.type && typeof def.type !== 'function');
    if (someDontHaveFunctionType) {
      halt(
        'INVALID_DEFINITIONS',
        'Invalid option definitions: the `type` property must be a setter fuction (default: `Boolean`)'
      );
    }
    let invalidOption;
    const numericAlias = this.some(def => {
      invalidOption = def;
      return t.isDefined(def.alias) && t.isNumber(def.alias)
    });
    if (numericAlias) {
      halt(
        'INVALID_DEFINITIONS',
        'Invalid option definition: to avoid ambiguity an alias cannot be numeric [--' + invalidOption.name + ' alias is -' + invalidOption.alias + ']'
      );
    }
    const multiCharacterAlias = this.some(def => {
      invalidOption = def;
      return t.isDefined(def.alias) && def.alias.length !== 1
    });
    if (multiCharacterAlias) {
      halt(
        'INVALID_DEFINITIONS',
        'Invalid option definition: an alias must be a single character'
      );
    }
    const hypenAlias = this.some(def => {
      invalidOption = def;
      return def.alias === '-'
    });
    if (hypenAlias) {
      halt(
        'INVALID_DEFINITIONS',
        'Invalid option definition: an alias cannot be "-"'
      );
    }
    const duplicateName = hasDuplicates(this.map(def => caseInsensitive ? def.name.toLowerCase() : def.name));
    if (duplicateName) {
      halt(
        'INVALID_DEFINITIONS',
        'Two or more option definitions have the same name'
      );
    }
    const duplicateAlias = hasDuplicates(this.map(def => caseInsensitive && t.isDefined(def.alias) ? def.alias.toLowerCase() : def.alias));
    if (duplicateAlias) {
      halt(
        'INVALID_DEFINITIONS',
        'Two or more option definitions have the same alias'
      );
    }
    const duplicateDefaultOption = hasDuplicates(this.map(def => def.defaultOption));
    if (duplicateDefaultOption) {
      halt(
        'INVALID_DEFINITIONS',
        'Only one option definition can be the defaultOption'
      );
    }
    const defaultBoolean = this.some(def => {
      invalidOption = def;
      return def.isBoolean() && def.defaultOption
    });
    if (defaultBoolean) {
      halt(
        'INVALID_DEFINITIONS',
        `A boolean option ["${invalidOption.name}"] can not also be the defaultOption.`
      );
    }
  }
validate ( caseInsensitive ) { const someHaveNoName = this . some ( def => ! def . name ) ; if ( someHaveNoName ) { halt ( 'INVALID_DEFINITIONS' , 'Invalid option definitions: the `name` property is required on each definition' ) ; } const someDontHaveFunctionType = this . some ( def => def . type && typeof def . type !== 'function' ) ; if ( someDontHaveFunctionType ) { halt ( 'INVALID_DEFINITIONS' , 'Invalid option definitions: the `type` property must be a setter fuction (default: `Boolean`)' ) ; } let invalidOption ; const numericAlias = this . some ( def => { invalidOption = def ; return t . isDefined ( def . alias ) && t . isNumber ( def . alias ) } ) ; if ( numericAlias ) { halt ( 'INVALID_DEFINITIONS' , 'Invalid option definition: to avoid ambiguity an alias cannot be numeric [--' + invalidOption . name + ' alias is -' + invalidOption . alias + ']' ) ; } const multiCharacterAlias = this . some ( def => { invalidOption = def ; return t . isDefined ( def . alias ) && def . alias . length !== 1 } ) ; if ( multiCharacterAlias ) { halt ( 'INVALID_DEFINITIONS' , 'Invalid option definition: an alias must be a single character' ) ; } const hypenAlias = this . some ( def => { invalidOption = def ; return def . alias === '-' } ) ; if ( hypenAlias ) { halt ( 'INVALID_DEFINITIONS' , 'Invalid option definition: an alias cannot be "-"' ) ; } const duplicateName = hasDuplicates ( this . map ( def => caseInsensitive ? def . name . toLowerCase ( ) : def . name ) ) ; if ( duplicateName ) { halt ( 'INVALID_DEFINITIONS' , 'Two or more option definitions have the same name' ) ; } const duplicateAlias = hasDuplicates ( this . map ( def => caseInsensitive && t . isDefined ( def . alias ) ? def . alias . toLowerCase ( ) : def . alias ) ) ; if ( duplicateAlias ) { halt ( 'INVALID_DEFINITIONS' , 'Two or more option definitions have the same alias' ) ; } const duplicateDefaultOption = hasDuplicates ( this . map ( def => def . defaultOption ) ) ; if ( duplicateDefaultOption ) { halt ( 'INVALID_DEFINITIONS' , 'Only one option definition can be the defaultOption' ) ; } const defaultBoolean = this . some ( def => { invalidOption = def ; return def . isBoolean ( ) && def . defaultOption } ) ; if ( defaultBoolean ) { halt ( 'INVALID_DEFINITIONS' , ` ${ invalidOption . name } ` ) ; } }
validate option definitions
 @param {boolean} [caseInsensitive=false] - whether arguments will be parsed in a case insensitive manner
 @returns {string}
validate option definitions @param { boolean } [ caseInsensitive = false ] - whether arguments will be parsed in a case insensitive manner @returns { string }