Browse Source

feat: add "getLength" function

Ahmad Kholid 3 years ago
parent
commit
06b0e33e14
2 changed files with 6 additions and 22 deletions
  1. 6 2
      src/utils/reference-data/mustache-replacer.js
  2. 0 20
      test.html

+ 6 - 2
src/utils/reference-data/mustache-replacer.js

@@ -34,13 +34,17 @@ export const functions = {
   randint(min = 0, max = 100) {
     return Math.round(Math.random() * (+max - +min) + +min);
   },
+  getLength(str) {
+    return str.length ?? str;
+  },
 };
 
 export function extractStrFunction(str) {
-  const extractedStr = /^\$\s*(\w+)\s*\((.*)\)/.exec(str.trim());
+  const extractedStr = /^\$\s*(\w+)\s*\((.*)\)/.exec(
+    str.trim().replace(/\r?\n|\r/g, '')
+  );
 
   if (!extractedStr) return null;
-
   const { 1: name, 2: funcParams } = extractedStr;
   const params = funcParams
     .split(/,(?=(?:[^"]*"[^"]*")*[^"]*$)/)

+ 0 - 20
test.html

@@ -1,20 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-  <meta charset="utf-8">
-  <meta name="viewport" content="width=device-width, initial-scale=1">
-  <title>Dialog</title>
-</head>
-<body>
-  <script type="text/javascript">
-    setTimeout(() => {
-      alert('anu');
-    }, 2000);
-  </script>
-  <style type="text/css">
-    html {
-      background-color: black;
-    }
-  </style>
-</body>
-</html>