MCPcopy Create free account
hub / github.com/caseywebdev/react-list / describeValue

Function describeValue

docs/index.js:20581–20631  ·  view source on GitHub ↗
(value, maxLength)

Source from the content-addressed store, hash-verified

20579 });
20580 }
20581 function describeValue(value, maxLength) {
20582 switch (typeof value) {
20583 case "string":
20584 return (
20585 (value = JSON.stringify(value)),
20586 value.length > maxLength
20587 ? 5 > maxLength
20588 ? '"..."'
20589 : value.slice(0, maxLength - 4) + '..."'
20590 : value
20591 );
20592 case "object":
20593 if (null === value) return "null";
20594 if (isArrayImpl(value)) return "[...]";
20595 if (value.$$typeof === REACT_ELEMENT_TYPE)
20596 return (maxLength = getComponentNameFromType(value.type))
20597 ? "<" + maxLength + ">"
20598 : "<...>";
20599 var name = objectName(value);
20600 if ("Object" === name) {
20601 name = "";
20602 maxLength -= 2;
20603 for (var propName in value)
20604 if (value.hasOwnProperty(propName)) {
20605 var jsonPropName = JSON.stringify(propName);
20606 jsonPropName !== '"' + propName + '"' &&
20607 (propName = jsonPropName);
20608 maxLength -= propName.length - 2;
20609 jsonPropName = describeValue(
20610 value[propName],
20611 15 > maxLength ? maxLength : 15
20612 );
20613 maxLength -= jsonPropName.length;
20614 if (0 > maxLength) {
20615 name += "" === name ? "..." : ", ...";
20616 break;
20617 }
20618 name +=
20619 ("" === name ? "" : ",") + propName + ":" + jsonPropName;
20620 }
20621 return "{" + name + "}";
20622 }
20623 return name;
20624 case "function":
20625 return (maxLength = value.displayName || value.name)
20626 ? "function " + maxLength
20627 : "function";
20628 default:
20629 return String(value);
20630 }
20631 }
20632 function describePropValue(value, maxLength) {
20633 return "string" !== typeof value || needsEscaping.test(value)
20634 ? "{" + describeValue(value, maxLength - 2) + "}"

Callers 2

describePropValueFunction · 0.85
describePropertiesDiffFunction · 0.85

Calls 2

getComponentNameFromTypeFunction · 0.85
objectNameFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…