| 4 | const { isView } = ArrayBuffer; |
| 5 | |
| 6 | const to_idb = (value) => { |
| 7 | if (value == null) return stringify(["null", 0]); |
| 8 | /* eslint-disable no-fallthrough */ |
| 9 | switch (typeof value) { |
| 10 | case "object": { |
| 11 | if (isView(value)) return stringify(["memoryview", [...value]]); |
| 12 | if (value instanceof ArrayBuffer) |
| 13 | return stringify(["bytearray", [...new Uint8Array(value)]]); |
| 14 | } |
| 15 | case "string": |
| 16 | case "number": |
| 17 | case "boolean": |
| 18 | return stringify(["generic", value]); |
| 19 | default: |
| 20 | throw new TypeError(`Unexpected value: ${String(value)}`); |
| 21 | } |
| 22 | }; |
| 23 | |
| 24 | const from_idb = (value) => { |
| 25 | const [kind, result] = parse(value); |