UNPKG

jsoneo

Version:

A powerful JSON enhancement library that supports all JSON primitives, Date, RegExp, Symbol, Functions, Map, Set, TypedArray and much more! Almost everything in JavaScript.

41 lines (40 loc) 2.28 kB
declare const TYPED_ARRAY_CTORS: { Int8Array: Int8ArrayConstructor; Uint8Array: Uint8ArrayConstructor; Uint8ClampedArray: Uint8ClampedArrayConstructor; Int16Array: Int16ArrayConstructor; Uint16Array: Uint16ArrayConstructor; Int32Array: Int32ArrayConstructor; Uint32Array: Uint32ArrayConstructor; Float32Array: Float32ArrayConstructor; Float64Array: Float64ArrayConstructor; BigInt64Array: BigInt64ArrayConstructor; BigUint64Array: BigUint64ArrayConstructor; }; export declare const TypedArrays: (Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor | BigInt64ArrayConstructor | BigUint64ArrayConstructor)[]; /** ArrayBuffer -> Base64 */ export declare function arrayBufferToBase64(buf: ArrayBuffer): string; /** Base64 -> ArrayBuffer */ export declare function base64ToArrayBuffer(base64: string): ArrayBuffer; export declare function serializeTypedArray<T extends AnyTypedArray>(data: T): SerializedTypedArray<GetTypedArrayName<T>>; /** Serialize ArrayBuffer, DataView, TypedArray to a serialized result */ export declare function serializeBinary<T extends AnyTypedArray | ArrayBuffer | DataView>(value: T | ArrayBuffer | DataView): T extends ArrayBuffer | DataView ? SerializedArrayBuffer : T extends AnyTypedArray ? SerializedTypedArray<GetTypedArrayName<T>> : never; export declare function deserializeBinary<T extends AnyTypedArray>(obj: SerializedTypedArray<GetTypedArrayName<T>> | SerializedArrayBuffer): T extends never ? ArrayBuffer | DataView : T; type TypedArrayNames = keyof typeof TYPED_ARRAY_CTORS; type AnyTypedArray = InstanceType<(typeof TypedArrays)[number]>; interface SerializedTypedArray<N extends TypedArrayNames> { kind: 'TypedArray'; type: N; base64: string; byteLength: number; length: number; } interface SerializedArrayBuffer { kind: 'ArrayBuffer' | 'DataView'; base64: string; byteLength: number; } type GetTypedArrayName<T extends AnyTypedArray> = { [K in keyof typeof TYPED_ARRAY_CTORS]: InstanceType<(typeof TYPED_ARRAY_CTORS)[K]> extends T ? K : never; }[keyof typeof TYPED_ARRAY_CTORS]; export {};