Skip to content

Commit 166caec

Browse files
committed
Optimization by calling String constructor once
1 parent 36e656b commit 166caec

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/adapter/templates/getStringyProps.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,22 @@ export const getStringyProps = remoteFunction(function (this: unknown, maxLength
1515
}
1616

1717
for (const [key, value] of Object.entries(this)) {
18-
if (
19-
typeof value === 'object' &&
20-
value &&
21-
!String(value.toString).includes('[native code]') &&
22-
!String(this).includes('[object ')
23-
) {
24-
out[key] = String(value).slice(0, maxLength);
18+
if (typeof value === 'object' && value && !String(value.toString).includes('[native code]')) {
19+
const str = String(value);
20+
if (!str.startsWith('[object ')) {
21+
out[key] = str.slice(0, maxLength);
22+
}
2523
}
2624
}
2725

2826
return out;
2927
});
3028

3129
export const getToStringIfCustom = remoteFunction(function (this: unknown, maxLength: number) {
32-
if (
33-
typeof this === 'object' &&
34-
this &&
35-
!String(this.toString).includes('[native code]') &&
36-
!String(this).includes('[object ')
37-
) {
38-
return String(this).slice(0, maxLength);
30+
if (typeof this === 'object' && this && !String(this.toString).includes('[native code]')) {
31+
const str = String(this);
32+
if (!str.startsWith('[object ')) {
33+
return str.slice(0, maxLength);
34+
}
3935
}
4036
});

0 commit comments

Comments
 (0)