MCPcopy Index your code
hub / github.com/NativeScript/firebase / serialize

Function serialize

packages/firebase-analytics/index.android.ts:22–88  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

20}
21
22function serialize(data) {
23 switch (typeof data) {
24 case 'string':
25 case 'boolean':
26 case 'number': {
27 return data;
28 }
29
30 case 'object': {
31 if (data === null) {
32 return null;
33 }
34
35 if (Array.isArray(data)) {
36 const store = new java.util.ArrayList();
37 data.forEach((item) => {
38 const value = serialize(item);
39 switch (typeof value) {
40 case 'object':
41 if (value instanceof android.os.Bundle) {
42 store.add(value);
43 }
44 if (value instanceof java.util.ArrayList) {
45 store.add(value);
46 }
47
48 break;
49 }
50 });
51 return store;
52 }
53
54 const store = new android.os.Bundle();
55 Object.keys(data).forEach((key) => {
56 const value = serialize(data[key]);
57 switch (typeof value) {
58 case 'boolean':
59 store.putBoolean(key, value);
60 break;
61 case 'number':
62 if (numberHasDecimals(value)) {
63 store.putDouble(key, value);
64 } else {
65 store.putLong(key, value);
66 }
67 break;
68 case 'string':
69 store.putString(key, value);
70 break;
71 case 'object':
72 if (value instanceof android.os.Bundle) {
73 store.putBundle(key, value);
74 } else if (value instanceof java.util.ArrayList) {
75 store.putParcelableArrayList(key, value);
76 } else {
77 store.putString(key, null);
78 }
79 break;

Callers 2

logEventMethod · 0.70

Calls 4

numberHasDecimalsFunction · 0.70
forEachMethod · 0.65
addMethod · 0.65
putStringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…