@contrail/util 1.0.26 → 1.0.28

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,19 +10,17 @@ class StringUtil {
10
10
  return slugName;
11
11
  }
12
12
  static parseVariables(variableString, data, quoteStrings = false) {
13
- const regExp = /\{([^}]+)\}/;
14
- let done = false;
15
- let currentVariableString = variableString;
16
- while (!done) {
17
- const match = regExp.exec(currentVariableString);
18
- if (!match) {
19
- done = true;
20
- break;
21
- }
22
- const variableLevels = match[1].split('.');
13
+ const regExp = /\{([^}]+)\}/g;
14
+ const replacedString = variableString.replace(regExp, (match, group) => {
15
+ const variableLevels = group.split('.');
23
16
  let replacementValue = data;
24
17
  for (let i = 0; i < variableLevels.length; i++) {
25
- replacementValue = replacementValue[variableLevels[i]];
18
+ if (replacementValue) {
19
+ replacementValue = replacementValue[variableLevels[i]];
20
+ }
21
+ else {
22
+ replacementValue = undefined;
23
+ }
26
24
  }
27
25
  if (quoteStrings && StringUtil.isString(replacementValue)) {
28
26
  replacementValue = JSON.stringify(replacementValue);
@@ -37,11 +35,15 @@ class StringUtil {
37
35
  }
38
36
  replacementValue = '[' + replacementValue + ']';
39
37
  }
40
- currentVariableString = currentVariableString.replace(match[0], replacementValue);
41
- }
42
- return currentVariableString;
38
+ if (Object.prototype.toString.call(replacementValue) === '[object Object]') {
39
+ replacementValue = JSON.stringify(replacementValue);
40
+ }
41
+ return replacementValue;
42
+ });
43
+ return replacedString;
43
44
  }
44
45
  static convertToCamelCase(str) {
46
+ str = str.replace(/-/g, ' ');
45
47
  return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
46
48
  return index === 0 ? word.toLowerCase() : word.toUpperCase();
47
49
  }).replace(/\s+/g, '');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/util",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
4
4
  "description": "General javascript utilities",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",