MCPcopy Create free account
hub / github.com/NativeScript/NativeScript / dataSerialize

Function dataSerialize

packages/core/utils/native-helper.ios.ts:43–92  ·  view source on GitHub ↗
(data: any, wrapPrimitives: boolean = false)

Source from the content-addressed store, hash-verified

41}
42
43export function dataSerialize(data: any, wrapPrimitives: boolean = false) {
44 switch (typeof data) {
45 case 'string':
46 case 'boolean': {
47 return data;
48 }
49 case 'number': {
50 const hasDecimals = numberHasDecimals(data);
51 if (numberIs64Bit(data)) {
52 if (hasDecimals) {
53 return NSNumber.alloc().initWithDouble(data);
54 } else {
55 return NSNumber.alloc().initWithLongLong(data);
56 }
57 } else {
58 if (hasDecimals) {
59 return NSNumber.alloc().initWithFloat(data);
60 } else {
61 return data;
62 }
63 }
64 }
65
66 case 'object': {
67 if (data instanceof Date) {
68 return NSDate.dateWithTimeIntervalSince1970(data.getTime() / 1000);
69 }
70
71 if (!data) {
72 return null;
73 }
74
75 if (Array.isArray(data)) {
76 return NSArray.arrayWithArray(data.map((el) => dataSerialize(el, wrapPrimitives)).filter((el) => el !== null));
77 }
78
79 const node = Object.fromEntries(
80 Object.entries(data)
81 .map(([key, value]) => [key, dataSerialize(value, wrapPrimitives)])
82 .filter(([, value]) => value !== null),
83 );
84
85 // cast to any avoids signature overload on tsc build
86 return NSDictionary.dictionaryWithDictionary(node as any);
87 }
88
89 default:
90 return null;
91 }
92}
93
94function getCurrentAppPath(): string {
95 if (!global.__dirname) {

Callers 2

openWindowMethod · 0.90

Calls 4

numberHasDecimalsFunction · 0.90
numberIs64BitFunction · 0.90
mapMethod · 0.65
filterMethod · 0.45

Tested by

no test coverage detected