You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Replace with the variable value from the variables object
105
+
returnvariables[variableName];
106
+
}else{
107
+
// If the variable is not provided, use the default value (if available)
108
+
// If defaultValue is undefined (i.e., not provided in the template), this will return an empty string
109
+
returndefaultValue||'UNKNOWN';
110
+
}
111
+
});
112
+
}
113
+
// // Example usage:
114
+
// const inputString = "This string has {{VARIABLE_NAME}} and {{MISSING_VARIABLE|default value}} to be {{foo.bar|default name}} replaced {{no_default.field}}.";
115
+
116
+
// // Suppose VARIABLE_NAME is provided, but MISSING_VARIABLE is not
117
+
// const variables = {
118
+
// VARIABLE_NAME: "some value",
119
+
// 'foo.bar': 'nihao'
120
+
// // MISSING_VARIABLE is not provided, so its default value from the template should be used
121
+
// // no_default.field is not provided, the template have no default either, so it becomes "UNKNOWN"
122
+
// };
123
+
124
+
// const result = replaceVariableNameWithValueWithDefault(inputString, variables);
125
+
// console.log(result):
126
+
// // This string has some value and default value to be nihao replaced UNKNOWN.
0 commit comments