lib/Models/CatalogGroup.js
function generateUniqueKey(index, initialKey) {
  var currentCandidate = initialKey;

  var counter = 0;
  while (index[currentCandidate]) {
    var numberAtEndOfKeyMatches = currentCandidate.match(
      NUMBER_AT_END_OF_KEY_REGEX
    );
    if (numberAtEndOfKeyMatches !== null) {
      var nextNumber = parseInt(numberAtEndOfKeyMatches[1], 10) + 1;

      currentCandidate = currentCandidate.replace(
        NUMBER_AT_END_OF_KEY_REGEX,
        "(" + nextNumber + ")"
      );
    } else {
      currentCandidate += " (1)";
    }

    // This loop should always find something eventually, but because it's a bit dangerous looping endlessly...
    counter++;
    if (counter >= 100000) {
      throw new DeveloperError(
        "Was not able to find a unique key for " +
          initialKey +
          " after 100000 iterations." +
          " This is probably because the regex for matching keys was somehow unable to work for that key."
      );
    }
  }

  return currentCandidate;
}
function generateUniqueKey(index, initialKey) {
  var currentCandidate = initialKey;

  var counter = 0;
  while (index[currentCandidate]) {
    var numberAtEndOfKeyMatches = currentCandidate.match(
      NUMBER_AT_END_OF_KEY_REGEX
    );
    if (numberAtEndOfKeyMatches !== null) {
      var nextNumber = parseInt(numberAtEndOfKeyMatches[1], 10) + 1;

      currentCandidate = currentCandidate.replace(
        NUMBER_AT_END_OF_KEY_REGEX,
        "(" + nextNumber + ")"
      );
    } else {
      currentCandidate += " (1)";
    }

    // This loop should always find something eventually, but because it's a bit dangerous looping endlessly...
    counter++;
    if (counter >= 100000) {
      throw new DeveloperError(
        "Was not able to find a unique key for " +
          initialKey +
          " after 100000 iterations." +
          " This is probably because the regex for matching keys was somehow unable to work for that key."
      );
    }
  }

  return currentCandidate;
}
function generateUniqueKey ( index , initialKey ) { var currentCandidate = initialKey ; var counter = 0 ; while ( index [ currentCandidate ] ) { var numberAtEndOfKeyMatches = currentCandidate . match ( NUMBER_AT_END_OF_KEY_REGEX ) ; if ( numberAtEndOfKeyMatches !== null ) { var nextNumber = parseInt ( numberAtEndOfKeyMatches [ 1 ] , 10 ) + 1 ; currentCandidate = currentCandidate . replace ( NUMBER_AT_END_OF_KEY_REGEX , "(" + nextNumber + ")" ) ; } else { currentCandidate += " (1)" ; } // This loop should always find something eventually, but because it's a bit dangerous looping endlessly... counter ++ ; if ( counter >= 100000 ) { throw new DeveloperError ( "Was not able to find a unique key for " + initialKey + " after 100000 iterations." + " This is probably because the regex for matching keys was somehow unable to work for that key." ) ; } } return currentCandidate ; }
Generates a unique key from a non-unique one by adding a number after it. If the key already has a number added,
it will increment that number.
@private
@param index An index to check for uniqueness.
@param initialKey The key to start from.
@returns {String} A new, unique key.
Generates a unique key from a non - unique one by adding a number after it . If the key already has a number added it will increment that number .