index.js
function filterByVersion(browsers, version) {
  version = String(version);

  if (version === 'latest' || version === 'oldest') {
    const filtered = numericVersions(browsers);
    const i = version === 'latest' ? filtered.length - 1 : 0;
    const value = filtered[i].short_version;
    return filtered.filter((el) => el.short_version === value);
  }

  const splits = version.split('..');

  if (splits.length === 2) {
    const versions = browsers.map((el) => el.short_version);
    const start = splits[0];
    const end = splits[1];

    let startIndex = 0;
    let endIndex = browsers.length - 1;

    if (end === 'latest') endIndex = numericVersions(browsers).length - 1;
    else endIndex = versions.lastIndexOf(end);

    if (start < 0) startIndex = endIndex + Number(start);
    else if (start !== 'oldest') startIndex = versions.indexOf(start);

    if (startIndex < 0) {
      throw new Error(`Unable to find start version: ${start}`);
    }
    if (endIndex < 0) throw new Error(`Unable to find end version: ${end}`);

    return browsers.slice(startIndex, endIndex + 1);
  }

  return browsers.filter((el) => {
    return el.short_version === version || el.short_version === `${version}.0`;
  });
}
function filterByVersion(browsers, version) {
  version = String(version);

  if (version === 'latest' || version === 'oldest') {
    const filtered = numericVersions(browsers);
    const i = version === 'latest' ? filtered.length - 1 : 0;
    const value = filtered[i].short_version;
    return filtered.filter((el) => el.short_version === value);
  }

  const splits = version.split('..');

  if (splits.length === 2) {
    const versions = browsers.map((el) => el.short_version);
    const start = splits[0];
    const end = splits[1];

    let startIndex = 0;
    let endIndex = browsers.length - 1;

    if (end === 'latest') endIndex = numericVersions(browsers).length - 1;
    else endIndex = versions.lastIndexOf(end);

    if (start < 0) startIndex = endIndex + Number(start);
    else if (start !== 'oldest') startIndex = versions.indexOf(start);

    if (startIndex < 0) {
      throw new Error(`Unable to find start version: ${start}`);
    }
    if (endIndex < 0) throw new Error(`Unable to find end version: ${end}`);

    return browsers.slice(startIndex, endIndex + 1);
  }

  return browsers.filter((el) => {
    return el.short_version === version || el.short_version === `${version}.0`;
  });
}
function filterByVersion ( browsers , version ) { version = String ( version ) ; if ( version === 'latest' || version === 'oldest' ) { const filtered = numericVersions ( browsers ) ; const i = version === 'latest' ? filtered . length - 1 : 0 ; const value = filtered [ i ] . short_version ; return filtered . filter ( ( el ) => el . short_version === value ) ; } const splits = version . split ( '..' ) ; if ( splits . length === 2 ) { const versions = browsers . map ( ( el ) => el . short_version ) ; const start = splits [ 0 ] ; const end = splits [ 1 ] ; let startIndex = 0 ; let endIndex = browsers . length - 1 ; if ( end === 'latest' ) endIndex = numericVersions ( browsers ) . length - 1 ; else endIndex = versions . lastIndexOf ( end ) ; if ( start < 0 ) startIndex = endIndex + Number ( start ) ; else if ( start !== 'oldest' ) startIndex = versions . indexOf ( start ) ; if ( startIndex < 0 ) { throw new Error ( ` ${ start } ` ) ; } if ( endIndex < 0 ) throw new Error ( ` ${ end } ` ) ; return browsers . slice ( startIndex , endIndex + 1 ) ; } return browsers . filter ( ( el ) => { return el . short_version === version || el . short_version === ` ${ version } ` ; } ) ; }
Filter out entries whose version does not match a given version from a
list of objects describing the OS and browser platforms on Sauce Labs.

@param {Array} browsers The array to filter
@param {(Number|String)} version The version to test against
@return {Array} The filtered array
@private
Filter out entries whose version does not match a given version from a list of objects describing the OS and browser platforms on Sauce Labs .