|
| 1 | +module Impl: { |
| 2 | + open Js.TypedArray2 |
| 3 | + |
| 4 | + type t |
| 5 | + |
| 6 | + type case = |
| 7 | + | String(string) |
| 8 | + | Buffer(Buffer.t) |
| 9 | + | Uint8Array(Uint8Array.t) |
| 10 | + | Int8Array(Int8Array.t) |
| 11 | + | Uint8ClampedArray(Uint8ClampedArray.t) |
| 12 | + | Uint16Array(Uint16Array.t) |
| 13 | + | Int16Array(Int16Array.t) |
| 14 | + | Uint32Array(Uint32Array.t) |
| 15 | + | Int32Array(Uint32Array.t) |
| 16 | + | Float32Array(Float32Array.t) |
| 17 | + | Float64Array(Float64Array.t) |
| 18 | + | DataView(DataView.t) |
| 19 | + | Unknown(t) |
| 20 | + |
| 21 | + let string: string => t |
| 22 | + let buffer: Buffer.t => t |
| 23 | + let int8Array: Int8Array.t => t |
| 24 | + let uInt8Array: Uint8Array.t => t |
| 25 | + let uInt8ClampedArray: Uint8ClampedArray.t => t |
| 26 | + let uInt16Array: Uint16Array.t => t |
| 27 | + let int16Array: Int16Array.t => t |
| 28 | + let uInt32Array: Uint32Array.t => t |
| 29 | + let int32Array: Int32Array.t => t |
| 30 | + let float32Array: Float32Array.t => t |
| 31 | + let float64Array: Float64Array.t => t |
| 32 | + let dataView: DataView.t => t |
| 33 | + let classify: t => case |
| 34 | +} = { |
| 35 | + open Js.TypedArray2 |
| 36 | + |
| 37 | + @unboxed |
| 38 | + type rec t = BinaryLike('a): t |
| 39 | + |
| 40 | + type case = |
| 41 | + | String(string) |
| 42 | + | Buffer(Buffer.t) |
| 43 | + | Uint8Array(Uint8Array.t) |
| 44 | + | Int8Array(Int8Array.t) |
| 45 | + | Uint8ClampedArray(Uint8ClampedArray.t) |
| 46 | + | Uint16Array(Uint16Array.t) |
| 47 | + | Int16Array(Int16Array.t) |
| 48 | + | Uint32Array(Uint32Array.t) |
| 49 | + | Int32Array(Uint32Array.t) |
| 50 | + | Float32Array(Float32Array.t) |
| 51 | + | Float64Array(Float64Array.t) |
| 52 | + | DataView(DataView.t) |
| 53 | + | Unknown(t) |
| 54 | + |
| 55 | + let string: string => t = x => BinaryLike(x) |
| 56 | + let buffer: Buffer.t => t = x => BinaryLike(x) |
| 57 | + let int8Array: Int8Array.t => t = x => BinaryLike(x) |
| 58 | + let uInt8Array: Uint8Array.t => t = x => BinaryLike(x) |
| 59 | + let uInt8ClampedArray: Uint8ClampedArray.t => t = x => BinaryLike(x) |
| 60 | + let uInt16Array: Uint16Array.t => t = x => BinaryLike(x) |
| 61 | + let int16Array: Int16Array.t => t = x => BinaryLike(x) |
| 62 | + let uInt32Array: Uint32Array.t => t = x => BinaryLike(x) |
| 63 | + let int32Array: Int32Array.t => t = x => BinaryLike(x) |
| 64 | + let float32Array: Float32Array.t => t = x => BinaryLike(x) |
| 65 | + let float64Array: Float64Array.t => t = x => BinaryLike(x) |
| 66 | + let dataView: DataView.t => t = x => BinaryLike(x) |
| 67 | + |
| 68 | + let classify: t => case = x => |
| 69 | + switch x { |
| 70 | + | BinaryLike(binaryLike) => |
| 71 | + if Js.typeof(binaryLike) === "string" { |
| 72 | + String(Obj.magic(binaryLike)) |
| 73 | + } else if Buffer.isBuffer(binaryLike) { |
| 74 | + Buffer(Obj.magic(binaryLike)) |
| 75 | + } else if Util.Types.isInt8Array(binaryLike) { |
| 76 | + Int8Array(Obj.magic(binaryLike)) |
| 77 | + } else if Util.Types.isUint8Array(binaryLike) { |
| 78 | + Uint8Array(Obj.magic(binaryLike)) |
| 79 | + } else if Util.Types.isUint8ClampedArray(binaryLike) { |
| 80 | + Uint8ClampedArray(Obj.magic(binaryLike)) |
| 81 | + } else if Util.Types.isInt16Array(binaryLike) { |
| 82 | + Int16Array(Obj.magic(binaryLike)) |
| 83 | + } else if Util.Types.isUint16Array(binaryLike) { |
| 84 | + Uint16Array(Obj.magic(binaryLike)) |
| 85 | + } else if Util.Types.isInt32Array(binaryLike) { |
| 86 | + Int32Array(Obj.magic(binaryLike)) |
| 87 | + } else if Util.Types.isUint32Array(binaryLike) { |
| 88 | + Uint32Array(Obj.magic(binaryLike)) |
| 89 | + } else if Util.Types.isFloat32Array(binaryLike) { |
| 90 | + Float32Array(Obj.magic(binaryLike)) |
| 91 | + } else if Util.Types.isFloat64Array(binaryLike) { |
| 92 | + Float64Array(Obj.magic(binaryLike)) |
| 93 | + } else if Util.Types.isDataView(binaryLike) { |
| 94 | + DataView(Obj.magic(binaryLike)) |
| 95 | + } else if Util.Types.isStringObject(binaryLike) { |
| 96 | + String(Obj.magic(binaryLike)) |
| 97 | + } else { |
| 98 | + Unknown(Obj.magic(binaryLike)) |
| 99 | + } |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +include Impl |
0 commit comments