seedersUtils.js 529 B

1234567891011121314151617181920
  1. module.exports = {
  2. generateUniqueList(size, createElementCallback) {
  3. const result = new Set();
  4. let iteration = 0;
  5. while (result.size < size) {
  6. if (iteration > size * 5) {
  7. throw new Error(`Too many iterations were run to generate unique seed data.
  8. Make sure the create element callback has enough unique values to choose from.`);
  9. }
  10. iteration += 1;
  11. const element = createElementCallback(result.size);
  12. result.add(element);
  13. }
  14. return Array.from(result);
  15. },
  16. };