-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use custom toString() methods to generate object descriptions
Closes #1284
- Loading branch information
1 parent
d816d6a
commit 9633741
Showing
6 changed files
with
105 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/*--------------------------------------------------------- | ||
* Copyright (C) Microsoft Corporation. All rights reserved. | ||
*--------------------------------------------------------*/ | ||
|
||
import { remoteFunction } from '.'; | ||
|
||
/** | ||
* Gets a mapping of property names with a custom `.toString()` method | ||
* to their string representations. | ||
*/ | ||
export const getStringyProps = remoteFunction(function (this: unknown, maxLength: number) { | ||
const out: Record<string, string> = {}; | ||
if (typeof this !== 'object' || !this) { | ||
return out; | ||
} | ||
|
||
for (const [key, value] of Object.entries(this)) { | ||
if (typeof value === 'object' && value && !String(this.toString).includes('[native code]')) { | ||
out[key] = String(value).slice(0, maxLength); | ||
} | ||
} | ||
|
||
return out; | ||
}); | ||
|
||
export const getToStringIfCustom = remoteFunction(function (this: unknown, maxLength: number) { | ||
if (typeof this === 'object' && this && !String(this.toString).includes('[native code]')) { | ||
return String(this).slice(0, maxLength); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters