MCPcopy
hub / github.com/facebook/react / getIODescription

Function getIODescription

packages/shared/ReactIODescription.js:10–84  ·  view source on GitHub ↗
(value: mixed)

Source from the content-addressed store, hash-verified

8 */
9
10export function getIODescription(value: mixed): string {
11 if (!__DEV__) {
12 return '';
13 }
14 try {
15 switch (typeof value) {
16 case 'object':
17 // Test the object for a bunch of common property names that are useful identifiers.
18 // While we only have the return value here, it should ideally be a name that
19 // describes the arguments requested.
20 if (value === null) {
21 return '';
22 } else if (value instanceof Error) {
23 // eslint-disable-next-line react-internal/safe-string-coercion
24 return String(value.message);
25 } else if (typeof value.url === 'string') {
26 return value.url;
27 } else if (typeof value.href === 'string') {
28 return value.href;
29 } else if (typeof value.src === 'string') {
30 return value.src;
31 } else if (typeof value.currentSrc === 'string') {
32 return value.currentSrc;
33 } else if (typeof value.command === 'string') {
34 return value.command;
35 } else if (
36 typeof value.request === 'object' &&
37 value.request !== null &&
38 typeof value.request.url === 'string'
39 ) {
40 return value.request.url;
41 } else if (
42 typeof value.response === 'object' &&
43 value.response !== null &&
44 typeof value.response.url === 'string'
45 ) {
46 return value.response.url;
47 } else if (
48 typeof value.id === 'string' ||
49 typeof value.id === 'number' ||
50 typeof value.id === 'bigint'
51 ) {
52 // eslint-disable-next-line react-internal/safe-string-coercion
53 return String(value.id);
54 } else if (typeof value.name === 'string') {
55 return value.name;
56 } else {
57 const str = value.toString();
58 if (
59 str.startsWith('[object ') ||
60 str.length < 5 ||
61 str.length > 500
62 ) {
63 // This is probably not a useful description.
64 return '';
65 }
66 return str;
67 }

Callers 5

logComponentAwaitErroredFunction · 0.90
logComponentAwaitFunction · 0.90
logIOInfoErroredFunction · 0.90
logIOInfoFunction · 0.90
serializeAsyncInfoFunction · 0.90

Calls 1

toStringMethod · 0.65

Tested by

no test coverage detected