(data?: string)
| 14 | }; |
| 15 | |
| 16 | export function decodeCursor(data?: string): FindThreadsByCursorType { |
| 17 | if (!data) return defaultCursor; |
| 18 | try { |
| 19 | const decoded = SKIP_ENCODE_CURSOR |
| 20 | ? data |
| 21 | : Buffer.from(data, 'base64').toString(); |
| 22 | const split = decoded?.split(':'); |
| 23 | if (split.length === 3) { |
| 24 | return { |
| 25 | sort: split[0] === 'asc' ? 'asc' : 'desc', |
| 26 | direction: split[1] as 'gt' | 'lt' | 'gte', |
| 27 | sentAt: split[2], |
| 28 | }; |
| 29 | } |
| 30 | } catch (error) { |
| 31 | console.error(error); |
| 32 | } |
| 33 | return defaultCursor; |
| 34 | } |
no test coverage detected