function pageRangeTextToPageRanges(pageRangeText, opt_totalPageCount) {
  if (pageRangeText == '') {
    return [];
  }

  const MAX_PAGE_NUMBER = 1000000000;
  const totalPageCount =
      opt_totalPageCount ? opt_totalPageCount : MAX_PAGE_NUMBER;

  const regex = /^\s*([0-9]*)\s*-\s*([0-9]*)\s*$/;
  const parts = pageRangeText.split(/,|\u3001/);

  const pageRanges = [];
  for (let i = 0; i < parts.length; ++i) {
    const match = parts[i].match(regex);
    if (match) {
      if (!isPositiveInteger(match[1]) && match[1] !== '')
        return PageRangeStatus.SYNTAX_ERROR;
      if (!isPositiveInteger(match[2]) && match[2] !== '')
        return PageRangeStatus.SYNTAX_ERROR;
      const from = match[1] ? parseInt(match[1], 10) : 1;
      const to = match[2] ? parseInt(match[2], 10) : totalPageCount;
      if (from > to)
        return PageRangeStatus.SYNTAX_ERROR;
      if (to > totalPageCount)
        return PageRangeStatus.LIMIT_ERROR;
      pageRanges.push({'from': from, 'to': to});
    } else {
      if (!isPositiveInteger(parts[i]))
        return PageRangeStatus.SYNTAX_ERROR;
      const singlePageNumber = parseInt(parts[i], 10);
      if (singlePageNumber > totalPageCount)
        return PageRangeStatus.LIMIT_ERROR;
      pageRanges.push({'from': singlePageNumber, 'to': singlePageNumber});
    }
  }
  return pageRanges;
}
/**
 * Returns a list of ranges in |pageRangeText|. The ranges are
 * listed in the order they appear in |pageRangeText| and duplicates are not
 * eliminated. If |pageRangeText| is not valid, PageRangeStatus.SYNTAX_ERROR
 * is returned.
 * A valid selection has a parsable format and every page identifier is
 * greater than 0 unless wildcards are used(see examples).
 * If a page is greater than |totalPageCount|, PageRangeStatus.LIMIT_ERROR
 * is returned.
 * If |totalPageCount| is 0 or undefined function uses impossibly large number
 * instead.
 * Wildcard the first number must be larger than 0 and less or equal then
 * |totalPageCount|. If it's missed then 1 is used as the first number.
 * Wildcard the second number must be larger then the first number. If it's
 * missed then |totalPageCount| is used as the second number.
 * Example: "1-4, 9, 3-6, 10, 11" is valid, assuming |totalPageCount| >= 11.
 * Example: "1-4, -6" is valid, assuming |totalPageCount| >= 6.
 * Example: "2-" is valid, assuming |totalPageCount| >= 2, means from 2 to the
 *          end.
 * Example: "4-2, 11, -6" is invalid.
 * Example: "-" is valid, assuming |totalPageCount| >= 1.
 * Example: "1-4dsf, 11" is invalid regardless of |totalPageCount|.
 * @param {string} pageRangeText The text to be checked.
 * @param {number=} opt_totalPageCount The total number of pages.
 * @return {!PageRangeStatus|!Array<{from: number, to: number}>}
 */
Returns a list of ranges in |pageRangeText|. The ranges are
listed in the order they appear in |pageRangeText| and duplicates are not
eliminated.
Returns a list of ranges in |pageRangeText| . The ranges are listed in the order they appear in |pageRangeText| and duplicates are not eliminated .
function pageRangeTextToPageRanges(pageRangeText, opt_totalPageCount) {
  if (pageRangeText == '') {
    return [];
  }
  const MAX_PAGE_NUMBER = 1000000000;
  const totalPageCount =
      opt_totalPageCount ? opt_totalPageCount : MAX_PAGE_NUMBER;
  const regex = /^\s*([0-9]*)\s*-\s*([0-9]*)\s*$/;
  const parts = pageRangeText.split(/,|\u3001/);
  const pageRanges = [];
  for (let i = 0; i < parts.length; ++i) {
    const match = parts[i].match(regex);
    if (match) {
      if (!isPositiveInteger(match[1]) && match[1] !== '')
        return PageRangeStatus.SYNTAX_ERROR;
      if (!isPositiveInteger(match[2]) && match[2] !== '')
        return PageRangeStatus.SYNTAX_ERROR;
      const from = match[1] ? parseInt(match[1], 10) : 1;
      const to = match[2] ? parseInt(match[2], 10) : totalPageCount;
      if (from > to)
        return PageRangeStatus.SYNTAX_ERROR;
      if (to > totalPageCount)
        return PageRangeStatus.LIMIT_ERROR;
      pageRanges.push({'from': from, 'to': to});
    } else {
      if (!isPositiveInteger(parts[i]))
        return PageRangeStatus.SYNTAX_ERROR;
      const singlePageNumber = parseInt(parts[i], 10);
      if (singlePageNumber > totalPageCount)
        return PageRangeStatus.LIMIT_ERROR;
      pageRanges.push({'from': singlePageNumber, 'to': singlePageNumber});
    }
  }
  return pageRanges;
}
function pageRangeTextToPageRanges ( pageRangeText , opt_totalPageCount ) { if ( pageRangeText == '' ) { return [ ] ; } const MAX_PAGE_NUMBER = 1000000000 ; const totalPageCount = opt_totalPageCount ? opt_totalPageCount : MAX_PAGE_NUMBER ; const regex = / ^\s*([0-9]*)\s*-\s*([0-9]*)\s*$ / ; const parts = pageRangeText . split ( / ,|\u3001 / ) ; const pageRanges = [ ] ; for ( let i = 0 ; i < parts . length ; ++ i ) { const match = parts [ i ] . match ( regex ) ; if ( match ) { if ( ! isPositiveInteger ( match [ 1 ] ) && match [ 1 ] !== '' ) return PageRangeStatus . SYNTAX_ERROR ; if ( ! isPositiveInteger ( match [ 2 ] ) && match [ 2 ] !== '' ) return PageRangeStatus . SYNTAX_ERROR ; const from = match [ 1 ] ? parseInt ( match [ 1 ] , 10 ) : 1 ; const to = match [ 2 ] ? parseInt ( match [ 2 ] , 10 ) : totalPageCount ; if ( from > to ) return PageRangeStatus . SYNTAX_ERROR ; if ( to > totalPageCount ) return PageRangeStatus . LIMIT_ERROR ; pageRanges . push ( { 'from' : from , 'to' : to } ) ; } else { if ( ! isPositiveInteger ( parts [ i ] ) ) return PageRangeStatus . SYNTAX_ERROR ; const singlePageNumber = parseInt ( parts [ i ] , 10 ) ; if ( singlePageNumber > totalPageCount ) return PageRangeStatus . LIMIT_ERROR ; pageRanges . push ( { 'from' : singlePageNumber , 'to' : singlePageNumber } ) ; } } return pageRanges ; }
Returns a list of ranges in |pageRangeText|.
Returns a list of ranges in |pageRangeText| .