yelda-webchat 1.1.19 → 1.1.20

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yelda-webchat",
3
- "version": "1.1.19",
3
+ "version": "1.1.20",
4
4
  "description": "Website Chat Plugin",
5
5
  "main": "./dist/js/yeldaWebchatInjector.min.js",
6
6
  "license": "MIT",
@@ -25,6 +25,23 @@ const isStrLikelyEncoded = (str) => {
25
25
  return hasNonASCII || hasPercentEncoding
26
26
  }
27
27
 
28
+ /**
29
+ * Check whether the string is stringified object
30
+ * @param {String} str
31
+ * @returns {Boolean}
32
+ */
33
+ const isStringifiedObject = (str) => {
34
+ try {
35
+ // Replace single quotes with double quotes
36
+ const jsonString = str.replace(/'/g, '"')
37
+ // Attempt to parse the string
38
+ const obj = JSON.parse(jsonString)
39
+ return typeof obj === 'object' && obj !== null
40
+ } catch (error) {
41
+ return false // Parsing failed, not a valid JSON string
42
+ }
43
+ }
44
+
28
45
  /**
29
46
  * Execute the function by name with the arguments
30
47
  * @param {String} functionName
@@ -110,9 +127,16 @@ class YeldaChat {
110
127
  } catch(err) {
111
128
  return ''
112
129
  }
130
+ } else if (isStringifiedObject(arg)) {
131
+ try{
132
+ return JSON.parse(arg.replace(/'/g, '"'))
133
+ } catch(err) {
134
+ return ''
135
+ }
113
136
  }
114
137
  return arg.replace(/^['"]|['"]$/g, '') // Remove surrounding quotes if any
115
138
  })
139
+
116
140
  return { functionName, args }
117
141
  }
118
142