(data: any)
| 25 | } |
| 26 | |
| 27 | export 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 | } |
| 66 | function serializeItems(data) { |
| 67 | if (data instanceof ServerValue) { |
| 68 | return data.native; |
no test coverage detected
searching dependent graphs…