Skip to content

Commit 3ce19dc

Browse files
committed
chore: add guard clause
1 parent 471adb3 commit 3ce19dc

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/utils/str.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,19 @@ export function renderTextWithSubstitutes(template, data, substitutionMap = {})
117117

118118
// Helper function for recursive substitution
119119
function substituteNested(obj) {
120-
lodash.forIn(obj, (value, key) => {
120+
if (!lodash.isPlainObject(obj)) {
121+
return;
122+
}
123+
// eslint-disable-next-line no-restricted-syntax
124+
for (const [key, value] of Object.entries(obj)) {
121125
if (lodash.isPlainObject(value)) {
122126
substituteNested(value);
123127
} else if (Array.isArray(value)) {
124128
value.forEach((val) => substituteNested(val));
125129
} else if (substitutionMap[value]) {
126130
obj[key] = substitutionMap[value];
127131
}
128-
});
132+
}
129133
}
130134

131135
substituteNested(renderData);

0 commit comments

Comments
 (0)