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

Function serialize

packages/firebase-core/utils.ts:11–110  ·  view source on GitHub ↗
(data: any, wrapPrimitives: boolean = false)

Source from the content-addressed store, hash-verified

9}
10
11export function serialize(data: any, wrapPrimitives: boolean = false): any {
12 if (global.isIOS) {
13 switch (typeof data) {
14 case 'string':
15 case 'boolean': {
16 return data;
17 }
18 case 'number': {
19 const hasDecimals = numberHasDecimals(data);
20 if (hasDecimals) {
21 return NSNumber.alloc().initWithDouble(data);
22 } else {
23 return NSNumber.alloc().initWithLongLong(data);
24 }
25 }
26
27 case 'object': {
28 if (data instanceof Date) {
29 return NSDate.dateWithTimeIntervalSince1970(data.getTime() / 1000);
30 }
31
32 if (!data) {
33 if (wrapPrimitives) {
34 return NSNull.new();
35 }
36 return null;
37 }
38
39 if (Array.isArray(data)) {
40 return NSArray.arrayWithArray(data.map((el) => serialize(el, wrapPrimitives)).filter((el) => el !== null));
41 }
42
43 const node = Object.fromEntries(
44 Object.entries(data)
45 .map(([key, value]) => [key, serialize(value, wrapPrimitives)])
46 .filter(([, value]) => value !== null)
47 );
48
49 return NSDictionary.dictionaryWithDictionary(node);
50 }
51
52 default:
53 if (wrapPrimitives) {
54 return NSNull.new();
55 }
56 return null;
57 }
58 }
59
60 if (global.isAndroid) {
61 let store;
62 switch (typeof data) {
63 case 'string':
64 case 'boolean': {
65 if (wrapPrimitives) {
66 if (typeof data === 'string') {
67 return new java.lang.String(data);
68 }

Callers 8

httpsCallableMethod · 0.90
httpsCallableMethod · 0.90
serializeItemsFunction · 0.90
logEventMethod · 0.90
setDefaultsMethod · 0.90
setDefaultsMethod · 0.90
customMetadataMethod · 0.90

Calls 5

numberHasDecimalsFunction · 0.70
valueOfMethod · 0.65
forEachMethod · 0.65
addMethod · 0.65
putMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…