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

Function serialize

packages/firebase-database/index.ios.ts:27–65  ·  view source on GitHub ↗
(data: any)

Source from the content-addressed store, hash-verified

25}
26
27export function serialize(data: any): any {
28 switch (typeof data) {
29 case 'string':
30 case 'boolean': {
31 return data;
32 }
33 case 'number': {
34 const hasDecimals = numberHasDecimals(data);
35 if (hasDecimals) {
36 return NSNumber.numberWithDouble(data);
37 } else {
38 return NSNumber.numberWithLongLong(data);
39 }
40 }
41
42 case 'object': {
43 if (data instanceof Date) {
44 return data.toString();
45 }
46 if (!data) {
47 return NSNull.new();
48 }
49
50 if (Array.isArray(data)) {
51 return NSArray.arrayWithArray((<any>data).map(serialize));
52 }
53
54 const node = {} as any;
55 Object.keys(data).forEach((key) => {
56 const value = data[key];
57 node[key] = serialize(value);
58 });
59 return NSDictionary.dictionaryWithDictionary(node);
60 }
61
62 default:
63 return NSNull.new();
64 }
65}
66function serializeItems(data) {
67 if (data instanceof ServerValue) {
68 return data.native;

Callers 2

serializeItemsFunction · 0.70
pushMethod · 0.70

Calls 3

numberHasDecimalsFunction · 0.70
toStringMethod · 0.65
forEachMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…