@graphql-mesh/string-interpolation 0.5.15 → 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.
- package/cjs/interpolator.js +9 -4
- package/esm/interpolator.js +9 -4
- package/package.json +1 -1
package/cjs/interpolator.js
CHANGED
|
@@ -88,10 +88,12 @@ class Interpolator {
|
|
|
88
88
|
return [];
|
|
89
89
|
}
|
|
90
90
|
parse(str, data = {}) {
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
if (str == null) {
|
|
92
|
+
return str;
|
|
93
|
+
}
|
|
94
|
+
const rules = this.parseRules(str);
|
|
93
95
|
if (rules && rules.length > 0) {
|
|
94
|
-
return this.parseFromRules(
|
|
96
|
+
return this.parseFromRules(str, data, rules);
|
|
95
97
|
}
|
|
96
98
|
return str;
|
|
97
99
|
}
|
|
@@ -100,10 +102,13 @@ class Interpolator {
|
|
|
100
102
|
}
|
|
101
103
|
applyRule(str, rule, data = {}) {
|
|
102
104
|
const dataToReplace = this.applyData(rule.key, data);
|
|
105
|
+
if (dataToReplace == null && str === rule.replace) {
|
|
106
|
+
return dataToReplace;
|
|
107
|
+
}
|
|
103
108
|
if (dataToReplace !== undefined) {
|
|
104
109
|
const modifiedData = this.applyModifiers(rule.modifiers, dataToReplace, data);
|
|
105
110
|
// If the entire string is just the placeholder, return the value
|
|
106
|
-
if (str === rule.replace
|
|
111
|
+
if (str === rule.replace) {
|
|
107
112
|
return modifiedData;
|
|
108
113
|
}
|
|
109
114
|
// For objects embedded in a larger string, JSON stringify them
|
package/esm/interpolator.js
CHANGED
|
@@ -84,10 +84,12 @@ export class Interpolator {
|
|
|
84
84
|
return [];
|
|
85
85
|
}
|
|
86
86
|
parse(str, data = {}) {
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
if (str == null) {
|
|
88
|
+
return str;
|
|
89
|
+
}
|
|
90
|
+
const rules = this.parseRules(str);
|
|
89
91
|
if (rules && rules.length > 0) {
|
|
90
|
-
return this.parseFromRules(
|
|
92
|
+
return this.parseFromRules(str, data, rules);
|
|
91
93
|
}
|
|
92
94
|
return str;
|
|
93
95
|
}
|
|
@@ -96,10 +98,13 @@ export class Interpolator {
|
|
|
96
98
|
}
|
|
97
99
|
applyRule(str, rule, data = {}) {
|
|
98
100
|
const dataToReplace = this.applyData(rule.key, data);
|
|
101
|
+
if (dataToReplace == null && str === rule.replace) {
|
|
102
|
+
return dataToReplace;
|
|
103
|
+
}
|
|
99
104
|
if (dataToReplace !== undefined) {
|
|
100
105
|
const modifiedData = this.applyModifiers(rule.modifiers, dataToReplace, data);
|
|
101
106
|
// If the entire string is just the placeholder, return the value
|
|
102
|
-
if (str === rule.replace
|
|
107
|
+
if (str === rule.replace) {
|
|
103
108
|
return modifiedData;
|
|
104
109
|
}
|
|
105
110
|
// For objects embedded in a larger string, JSON stringify them
|