(nativeData?: any)
| 6 | import { SDK_VERSION } from './constants'; |
| 7 | |
| 8 | export 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 | |
| 43 | export function dataSerialize(data: any, wrapPrimitives: boolean = false) { |
| 44 | switch (typeof data) { |
nothing calls this directly
no test coverage detected