MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / dataSerialize

Function dataSerialize

packages/core/utils/native-helper-for-android.ts:87–144  ·  view source on GitHub ↗
(data?: any, wrapPrimitives?: boolean)

Source from the content-addressed store, hash-verified

85}
86
87export function dataSerialize(data?: any, wrapPrimitives?: boolean) {
88 let store;
89 switch (typeof data) {
90 case 'string':
91 case 'boolean': {
92 if (wrapPrimitives) {
93 if (typeof data === 'string') {
94 return new java.lang.String(data);
95 }
96 return new java.lang.Boolean(data);
97 }
98 return data;
99 }
100 case 'number': {
101 const hasDecimals = numberHasDecimals(data);
102 if (numberIs64Bit(data)) {
103 if (hasDecimals) {
104 return java.lang.Double.valueOf(data);
105 } else {
106 return java.lang.Long.valueOf(data);
107 }
108 } else {
109 if (hasDecimals) {
110 return java.lang.Float.valueOf(data);
111 } else {
112 return java.lang.Integer.valueOf(data);
113 }
114 }
115 }
116
117 case 'object': {
118 if (!data) {
119 return null;
120 }
121
122 if (data instanceof Date) {
123 return new java.util.Date(data.getTime());
124 }
125
126 if (Array.isArray(data)) {
127 store = new java.util.ArrayList();
128 data.forEach((item) => store.add(dataSerialize(item, wrapPrimitives)));
129 return store;
130 }
131
132 if (data.native) {
133 return data.native;
134 }
135
136 store = new java.util.HashMap();
137 Object.keys(data).forEach((key) => store.put(key, dataSerialize(data[key], wrapPrimitives)));
138 return store;
139 }
140
141 default:
142 return null;
143 }
144}

Callers

nothing calls this directly

Calls 5

numberHasDecimalsFunction · 0.90
numberIs64BitFunction · 0.90
forEachMethod · 0.80
addMethod · 0.65
keysMethod · 0.65

Tested by

no test coverage detected