Selaa lähdekoodia

feat: support array in `$randData` function

Ahmad Kholid 3 vuotta sitten
vanhempi
commit
3948240169
1 muutettua tiedostoa jossa 5 lisäystä ja 0 poistoa
  1. 5 0
      src/utils/referenceData/mustacheReplacer.js

+ 5 - 0
src/utils/referenceData/mustacheReplacer.js

@@ -72,6 +72,11 @@ export const functions = {
     return +value - +subtractBy;
   },
   randData(str) {
+    if (Array.isArray(str)) {
+      const index = Math.floor(Math.random() * str.length);
+      return str[index];
+    }
+
     const getRand = (data) => data[Math.floor(Math.random() * data.length)];
     const lowercase = 'abcdefghijklmnopqrstuvwxyz';
     const uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';