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

Function getArrayKind

packages/shared/ReactPerformanceTrackProperties.js:21–50  ·  view source on GitHub ↗
(array: Object)

Source from the content-addressed store, hash-verified

19const PRIMITIVE_ARRAY = 2; // Primitive values only
20const ENTRIES_ARRAY = 3; // Tuple arrays of string and value (like Headers, Map, etc)
21function getArrayKind(array: Object): 0 | 1 | 2 | 3 {
22 let kind: 0 | 1 | 2 | 3 = EMPTY_ARRAY;
23 for (let i = 0; i < array.length; i++) {
24 const value = array[i];
25 if (typeof value === 'object' && value !== null) {
26 if (
27 isArray(value) &&
28 value.length === 2 &&
29 typeof value[0] === 'string'
30 ) {
31 // Key value tuple
32 if (kind !== EMPTY_ARRAY && kind !== ENTRIES_ARRAY) {
33 return COMPLEX_ARRAY;
34 }
35 kind = ENTRIES_ARRAY;
36 } else {
37 return COMPLEX_ARRAY;
38 }
39 } else if (typeof value === 'function') {
40 return COMPLEX_ARRAY;
41 } else if (typeof value === 'string' && value.length > 50) {
42 return COMPLEX_ARRAY;
43 } else if (kind !== EMPTY_ARRAY && kind !== PRIMITIVE_ARRAY) {
44 return COMPLEX_ARRAY;
45 } else {
46 kind = PRIMITIVE_ARRAY;
47 }
48 }
49 return kind;
50}
51
52export function addObjectToProperties(
53 object: Object,

Callers 1

addValueToPropertiesFunction · 0.85

Calls 1

isArrayFunction · 0.85

Tested by

no test coverage detected