@graphql-mesh/string-interpolation 0.5.14 → 0.5.16

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.
@@ -88,17 +88,12 @@ class Interpolator {
88
88
  return [];
89
89
  }
90
90
  parse(str, data = {}) {
91
- const strOrEmptyStr = str || '';
92
- const rules = this.parseRules(strOrEmptyStr);
91
+ if (str == null) {
92
+ return str;
93
+ }
94
+ const rules = this.parseRules(str);
93
95
  if (rules && rules.length > 0) {
94
- const result = this.parseFromRules(strOrEmptyStr, data, rules);
95
- if (rules.length === 1 &&
96
- result === '' &&
97
- strOrEmptyStr.startsWith('{') &&
98
- strOrEmptyStr.endsWith('}')) {
99
- return undefined;
100
- }
101
- return result;
96
+ return this.parseFromRules(str, data, rules);
102
97
  }
103
98
  return str;
104
99
  }
@@ -107,10 +102,13 @@ class Interpolator {
107
102
  }
108
103
  applyRule(str, rule, data = {}) {
109
104
  const dataToReplace = this.applyData(rule.key, data);
105
+ if (dataToReplace == null && str === rule.replace) {
106
+ return dataToReplace;
107
+ }
110
108
  if (dataToReplace !== undefined) {
111
109
  const modifiedData = this.applyModifiers(rule.modifiers, dataToReplace, data);
112
110
  // If the entire string is just the placeholder, return the value
113
- if (str === rule.replace && modifiedData != null) {
111
+ if (str === rule.replace) {
114
112
  return modifiedData;
115
113
  }
116
114
  // For objects embedded in a larger string, JSON stringify them
@@ -84,17 +84,12 @@ export class Interpolator {
84
84
  return [];
85
85
  }
86
86
  parse(str, data = {}) {
87
- const strOrEmptyStr = str || '';
88
- const rules = this.parseRules(strOrEmptyStr);
87
+ if (str == null) {
88
+ return str;
89
+ }
90
+ const rules = this.parseRules(str);
89
91
  if (rules && rules.length > 0) {
90
- const result = this.parseFromRules(strOrEmptyStr, data, rules);
91
- if (rules.length === 1 &&
92
- result === '' &&
93
- strOrEmptyStr.startsWith('{') &&
94
- strOrEmptyStr.endsWith('}')) {
95
- return undefined;
96
- }
97
- return result;
92
+ return this.parseFromRules(str, data, rules);
98
93
  }
99
94
  return str;
100
95
  }
@@ -103,10 +98,13 @@ export class Interpolator {
103
98
  }
104
99
  applyRule(str, rule, data = {}) {
105
100
  const dataToReplace = this.applyData(rule.key, data);
101
+ if (dataToReplace == null && str === rule.replace) {
102
+ return dataToReplace;
103
+ }
106
104
  if (dataToReplace !== undefined) {
107
105
  const modifiedData = this.applyModifiers(rule.modifiers, dataToReplace, data);
108
106
  // If the entire string is just the placeholder, return the value
109
- if (str === rule.replace && modifiedData != null) {
107
+ if (str === rule.replace) {
110
108
  return modifiedData;
111
109
  }
112
110
  // For objects embedded in a larger string, JSON stringify them
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-mesh/string-interpolation",
3
- "version": "0.5.14",
3
+ "version": "0.5.16",
4
4
  "description": "Dynamic string manipulation",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {