(data: any, wrapPrimitives: boolean = false)
| 41 | } |
| 42 | |
| 43 | export 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 | |
| 94 | function getCurrentAppPath(): string { |
| 95 | if (!global.__dirname) { |
no test coverage detected