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

Function dataDeserialize

packages/core/utils/native-helper.ios.ts:8–41  ·  view source on GitHub ↗
(nativeData?: any)

Source from the content-addressed store, hash-verified

6import { SDK_VERSION } from './constants';
7
8export function dataDeserialize(nativeData?: any) {
9 if (isNullOrUndefined(nativeData)) {
10 // some native values will already be js null values
11 // calling types.getClass below on null/undefined will cause crash
12 return null;
13 } else {
14 switch (getClass(nativeData)) {
15 case 'NSNull':
16 return null;
17 case 'NSMutableDictionary':
18 case 'NSDictionary': {
19 const obj = {};
20 const length = nativeData.count;
21 const keysArray = nativeData.allKeys as NSArray<any>;
22 for (let i = 0; i < length; i++) {
23 const nativeKey = keysArray.objectAtIndex(i);
24 obj[nativeKey] = dataDeserialize(nativeData.objectForKey(nativeKey));
25 }
26 return obj;
27 }
28 case 'NSMutableArray':
29 case 'NSArray': {
30 const array = [];
31 const len = nativeData.count;
32 for (let i = 0; i < len; i++) {
33 array[i] = dataDeserialize(nativeData.objectAtIndex(i));
34 }
35 return array;
36 }
37 default:
38 return nativeData;
39 }
40 }
41}
42
43export function dataSerialize(data: any, wrapPrimitives: boolean = false) {
44 switch (typeof data) {

Callers

nothing calls this directly

Calls 3

isNullOrUndefinedFunction · 0.90
getClassFunction · 0.90
objectForKeyMethod · 0.80

Tested by

no test coverage detected