@artisan-commerce/builders 0.7.0-canary.49 → 0.7.0-canary.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,7 +10,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
10
10
  var btoa__default = /*#__PURE__*/_interopDefaultLegacy(btoa);
11
11
 
12
12
  const genItems = (builder, quantity) => {
13
- const num = quantity != null ? quantity : Math.floor(Math.random() * 9) + 1;
13
+ const num = quantity != null ? quantity : faker.faker.datatype.number({ min: 1, max: 10 });
14
14
  const items = [];
15
15
  for (let i = 0; i < num; i++) {
16
16
  items.push(builder());
@@ -70,7 +70,7 @@ const genBiasBoolean = (bias) => {
70
70
  if (bias > 1 || bias < 0) {
71
71
  throw new Error(`Bias must be a number between 0 and 1. Value ${bias} is not valid`);
72
72
  }
73
- const random = Math.random();
73
+ const random = faker.faker.datatype.number({ min: 0, max: 1, precision: 4 });
74
74
  return random <= bias;
75
75
  };
76
76
  const genDocument = (digits) => {
@@ -126,16 +126,7 @@ const fillNumber = (num, max) => {
126
126
  }
127
127
  return newId;
128
128
  };
129
- const chooseRandom = (arr) => {
130
- return arr[Math.floor(Math.random() * arr.length)];
131
- };
132
- const chooseRandomEnum = (anEnum) => {
133
- const enumValues = Object.keys(anEnum);
134
- const randomIndex = Math.floor(Math.random() * enumValues.length);
135
- const randomEnumKey = enumValues[randomIndex];
136
- const randomEnumValue = anEnum[randomEnumKey];
137
- return randomEnumValue;
138
- };
129
+ const chooseRandom = faker.faker.helpers.arrayElement;
139
130
  const genSymbol = chooseRandom(["$", "S/", "$b", "Bs"]);
140
131
  const genIP = faker.faker.internet.ip;
141
132
 
@@ -179,7 +170,6 @@ var common_builder = /*#__PURE__*/Object.freeze({
179
170
  genCountry: genCountry,
180
171
  fillNumber: fillNumber,
181
172
  chooseRandom: chooseRandom,
182
- chooseRandomEnum: chooseRandomEnum,
183
173
  genSymbol: genSymbol,
184
174
  genIP: genIP,
185
175
  genItems: genItems
@@ -427,7 +417,7 @@ const buildCatalogue = (overrides = {}) => {
427
417
  }, overrides);
428
418
  };
429
419
  const genCatalogues = (quantity) => {
430
- const num = quantity != null ? quantity : Math.floor(Math.random() * 9) + 1;
420
+ const num = quantity != null ? quantity : genNumber({ min: 1, max: 10 });
431
421
  let options = [...catalogueOptions];
432
422
  const catalogues = [];
433
423
  for (let i = 0; i < num; i++) {
@@ -517,7 +507,7 @@ const buildBaseProduct = (overrides = {}) => {
517
507
  addDirectlyToCart: genBiasBoolean(0.5),
518
508
  coverUrl: "",
519
509
  description: faker.faker.lorem.lines(2),
520
- images: genCDNImages(Math.floor(Math.random() * 5 + 1)),
510
+ images: genCDNImages(genNumber({ min: 1, max: 5 })),
521
511
  measure: "unit",
522
512
  name: faker.faker.commerce.productName(),
523
513
  outOfService: false,
@@ -563,7 +553,7 @@ const buildProductAnswer = (overrides = {}, loop = 1) => {
563
553
  }, overrides);
564
554
  };
565
555
  const genProductAnswers = (quantity, loop = 1) => {
566
- const num = quantity != null ? quantity : Math.floor(Math.random() * 6) + 1;
556
+ const num = quantity != null ? quantity : genNumber({ min: 1, max: 6 });
567
557
  const productAnswers = [];
568
558
  for (let i = 0; i < num; i++) {
569
559
  const productAnswer = buildProductAnswer({}, loop);
@@ -592,7 +582,7 @@ const buildProductQuestion = (overrides = {}, loop = 1) => {
592
582
  }, overrides);
593
583
  };
594
584
  const genProductQuestions = (quantity, loop = 1) => {
595
- const num = quantity != null ? quantity : Math.floor(Math.random() * 4) + 1;
585
+ const num = quantity != null ? quantity : genNumber({ min: 1, max: 5 });
596
586
  const productQuestions = [];
597
587
  for (let i = 0; i < num; i++) {
598
588
  const productQuestion = buildProductQuestion({}, loop);
@@ -627,7 +617,7 @@ const buildCartProductAnswer = (questionId, overrides = {}) => {
627
617
  }), overrides);
628
618
  };
629
619
  const genCartProductAnswers = (quantity) => {
630
- const num = quantity != null ? quantity : Math.floor(Math.random() * 5) + 1;
620
+ const num = quantity != null ? quantity : genNumber({ min: 1, max: 5 });
631
621
  const cartProductAnswers = [];
632
622
  for (let i = 0; i < num; i++) {
633
623
  const cartProductAnswer = buildCartProductAnswer(i.toString());
@@ -1536,7 +1526,7 @@ const buildCartStore = (overrides = {}) => {
1536
1526
  }), overrides);
1537
1527
  };
1538
1528
  const genCartStores = (quantity) => {
1539
- const num = quantity != null ? quantity : Math.floor(Math.random() * 1) + 1;
1529
+ const num = quantity != null ? quantity : genNumber({ min: 1, max: 1 });
1540
1530
  const cartStores = {};
1541
1531
  for (let i = 0; i < num; i++) {
1542
1532
  const cartStore = buildCartStore();
@@ -2611,6 +2601,18 @@ var payment_builder = /*#__PURE__*/Object.freeze({
2611
2601
  genCardInscriptions: genCardInscriptions
2612
2602
  });
2613
2603
 
2604
+ const seed = (seed2) => {
2605
+ if (!faker.faker)
2606
+ throw new Error("Faker not found");
2607
+ return faker.faker.seed(seed2);
2608
+ };
2609
+
2610
+ var instance_utils = /*#__PURE__*/Object.freeze({
2611
+ __proto__: null,
2612
+ seed: seed
2613
+ });
2614
+
2615
+ exports.Builders = instance_utils;
2614
2616
  exports.accountBuilders = account_builder;
2615
2617
  exports.bannerBuilders = banner_builder;
2616
2618
  exports.billingDataBuilders = billingData_builder;