@domql/utils 2.5.167 → 2.5.168

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.
@@ -46,14 +46,15 @@ const brackRegex = {
46
46
  2: /\{\{\s*((?:\.\.\/)+)?([^}\s]+)\s*\}\}/g,
47
47
  3: /\{\{\{\s*((?:\.\.\/)+)?([^}\s]+)\s*\}\}\}/g
48
48
  };
49
- const replaceLiteralsWithObjectFields = (str, state, options = {}) => {
49
+ function replaceLiteralsWithObjectFields(str, options = {}, forcedState) {
50
50
  if (!str.includes(options.bracketsLength === 3 ? "{{{" : "{{"))
51
51
  return str;
52
52
  const reg = brackRegex[options.bracketsLength || 2];
53
+ const obj = forcedState || this.state || {};
53
54
  return str.replace(reg, (_, parentPath, variable) => {
54
55
  if (parentPath) {
55
56
  const parentLevels = parentPath.match(options.bracketsLength === 3 ? /\.\.\.\//g : /\.\.\//g).length;
56
- let parentState = state;
57
+ let parentState = obj;
57
58
  for (let i = 0; i < parentLevels; i++) {
58
59
  parentState = parentState.parent;
59
60
  if (!parentState) {
@@ -63,11 +64,11 @@ const replaceLiteralsWithObjectFields = (str, state, options = {}) => {
63
64
  const value = parentState[variable.trim()];
64
65
  return value !== void 0 ? `${value}` : "";
65
66
  } else {
66
- const value = state[variable.trim()];
67
+ const value = obj[variable.trim()];
67
68
  return value !== void 0 ? `${value}` : "";
68
69
  }
69
70
  });
70
- };
71
+ }
71
72
  const lowercaseFirstLetter = (inputString) => {
72
73
  return `${inputString.charAt(0).toLowerCase()}${inputString.slice(1)}`;
73
74
  };
@@ -14,14 +14,15 @@ const brackRegex = {
14
14
  2: /\{\{\s*((?:\.\.\/)+)?([^}\s]+)\s*\}\}/g,
15
15
  3: /\{\{\{\s*((?:\.\.\/)+)?([^}\s]+)\s*\}\}\}/g
16
16
  };
17
- const replaceLiteralsWithObjectFields = (str, state, options = {}) => {
17
+ function replaceLiteralsWithObjectFields(str, options = {}, forcedState) {
18
18
  if (!str.includes(options.bracketsLength === 3 ? "{{{" : "{{"))
19
19
  return str;
20
20
  const reg = brackRegex[options.bracketsLength || 2];
21
+ const obj = forcedState || this.state || {};
21
22
  return str.replace(reg, (_, parentPath, variable) => {
22
23
  if (parentPath) {
23
24
  const parentLevels = parentPath.match(options.bracketsLength === 3 ? /\.\.\.\//g : /\.\.\//g).length;
24
- let parentState = state;
25
+ let parentState = obj;
25
26
  for (let i = 0; i < parentLevels; i++) {
26
27
  parentState = parentState.parent;
27
28
  if (!parentState) {
@@ -31,11 +32,11 @@ const replaceLiteralsWithObjectFields = (str, state, options = {}) => {
31
32
  const value = parentState[variable.trim()];
32
33
  return value !== void 0 ? `${value}` : "";
33
34
  } else {
34
- const value = state[variable.trim()];
35
+ const value = obj[variable.trim()];
35
36
  return value !== void 0 ? `${value}` : "";
36
37
  }
37
38
  });
38
- };
39
+ }
39
40
  const lowercaseFirstLetter = (inputString) => {
40
41
  return `${inputString.charAt(0).toLowerCase()}${inputString.slice(1)}`;
41
42
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.5.167",
3
+ "version": "2.5.168",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -25,7 +25,7 @@
25
25
  "build": "npm run build:cjs; npm run build:esm",
26
26
  "prepublish": "rimraf -I dist; npm run build; npm run copy:package:cjs"
27
27
  },
28
- "gitHead": "3851b6d1029397dcf61c44682be5b9c234993e74",
28
+ "gitHead": "6c935c3d1ff70096bb532e9c5426ffc5af0677dc",
29
29
  "devDependencies": {
30
30
  "@babel/core": "^7.12.0"
31
31
  }
package/string.js CHANGED
@@ -29,13 +29,14 @@ const brackRegex = {
29
29
  3: /\{\{\{\s*((?:\.\.\/)+)?([^}\s]+)\s*\}\}\}/g
30
30
  }
31
31
 
32
- export const replaceLiteralsWithObjectFields = (str, state, options = {}) => {
32
+ export function replaceLiteralsWithObjectFields (str, options = {}, forcedState) {
33
33
  if (!str.includes(options.bracketsLength === 3 ? '{{{' : '{{')) return str
34
34
  const reg = brackRegex[options.bracketsLength || 2]
35
+ const obj = forcedState || this.state || {}
35
36
  return str.replace(reg, (_, parentPath, variable) => {
36
37
  if (parentPath) {
37
38
  const parentLevels = parentPath.match(options.bracketsLength === 3 ? /\.\.\.\//g : /\.\.\//g).length
38
- let parentState = state
39
+ let parentState = obj
39
40
  for (let i = 0; i < parentLevels; i++) {
40
41
  parentState = parentState.parent
41
42
  if (!parentState) {
@@ -45,7 +46,7 @@ export const replaceLiteralsWithObjectFields = (str, state, options = {}) => {
45
46
  const value = parentState[variable.trim()]
46
47
  return value !== undefined ? `${value}` : ''
47
48
  } else {
48
- const value = state[variable.trim()]
49
+ const value = obj[variable.trim()]
49
50
  return value !== undefined ? `${value}` : ''
50
51
  }
51
52
  })