浏览代码

feat: support array in `$randData` function

Ahmad Kholid 3 年之前
父节点
当前提交
3948240169
共有 1 个文件被更改,包括 5 次插入0 次删除
  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';