lib/prompt-filters.js
function (input, sep, choices) {
    debug('requiredTextListFilter(%s, %s, %s)', input, sep, (choices ? JSON.stringify(choices) : 'undefined'));
    // if we already have a list, just return it. We may
    // want to add validation that the items are in the
    // choices list
    if (_.isArray(input) && input.length > 0) return input;
    if (!_.isString(input)) return undefined;
    var retv = input.split(new RegExp('s*\\' + sep + '\\s*'));
    // remove any empty input items
    retv = retv.filter(function (r) {
      return (!_.isEmpty(r));
    });
    // If a choice list is provided we will return only items
    // that match the choice in a case insensitive way, using
    // whatever case is provided in the choice list.
    if (choices !== undefined) {
      var lcretv = retv.map(function (lc) {
        return lc.toLocaleLowerCase();
      });
      retv = choices.filter(function (c) {
        return (lcretv.indexOf(c.toLocaleLowerCase()) > -1);
      });
    }
    if (_.isEmpty(retv)) return undefined;
    return retv;
  }
function (input, sep, choices) {
    debug('requiredTextListFilter(%s, %s, %s)', input, sep, (choices ? JSON.stringify(choices) : 'undefined'));
    // if we already have a list, just return it. We may
    // want to add validation that the items are in the
    // choices list
    if (_.isArray(input) && input.length > 0) return input;
    if (!_.isString(input)) return undefined;
    var retv = input.split(new RegExp('s*\\' + sep + '\\s*'));
    // remove any empty input items
    retv = retv.filter(function (r) {
      return (!_.isEmpty(r));
    });
    // If a choice list is provided we will return only items
    // that match the choice in a case insensitive way, using
    // whatever case is provided in the choice list.
    if (choices !== undefined) {
      var lcretv = retv.map(function (lc) {
        return lc.toLocaleLowerCase();
      });
      retv = choices.filter(function (c) {
        return (lcretv.indexOf(c.toLocaleLowerCase()) > -1);
      });
    }
    if (_.isEmpty(retv)) return undefined;
    return retv;
  }
function ( input , sep , choices ) { debug ( 'requiredTextListFilter(%s, %s, %s)' , input , sep , ( choices ? JSON . stringify ( choices ) : 'undefined' ) ) ; // if we already have a list, just return it. We may // want to add validation that the items are in the // choices list if ( _ . isArray ( input ) && input . length > 0 ) return input ; if ( ! _ . isString ( input ) ) return undefined ; var retv = input . split ( new RegExp ( 's*\\' + sep + '\\s*' ) ) ; // remove any empty input items retv = retv . filter ( function ( r ) { return ( ! _ . isEmpty ( r ) ) ; } ) ; // If a choice list is provided we will return only items // that match the choice in a case insensitive way, using // whatever case is provided in the choice list. if ( choices !== undefined ) { var lcretv = retv . map ( function ( lc ) { return lc . toLocaleLowerCase ( ) ; } ) ; retv = choices . filter ( function ( c ) { return ( lcretv . indexOf ( c . toLocaleLowerCase ( ) ) > - 1 ) ; } ) ; } if ( _ . isEmpty ( retv ) ) return undefined ; return retv ; }
Given some input text, a separator and an optional list of
choices, we split the input using the separator. We remove
any empty items from the list.

If choices are provided then we only provide values that
match the choices in a case insensitive way and we return
in the order provided in the choices list and using the
case provided in the choices list.

An empty list is not allowed (undefined will be returned.)

@param input
@param sep
@param choices
@returns {(string[]|undefined)}
Given some input text a separator and an optional list of choices we split the input using the separator . We remove any empty items from the list .