UNPKG

@webviz/subsurface-viewer

Version:

3D visualization component for subsurface reservoir data

45 lines (44 loc) 1.78 kB
/** * Utility types and functions for working with JavaScript TypedArrays. * * - TypedIntArray: All integer TypedArray types. * - TypedFloatArray: All floating-point TypedArray types. * - TypedArray: Union of all supported TypedArray types. * - isTypedArray: Type guard for TypedArray (excluding DataView). * - isNumberArray: Type guard for number[] arrays. * - TConstructor: Generic constructor type for TypedArrays. * - toTypedArray: Converts number[] or TypedArray to a specific TypedArray type. */ /** * All supported integer TypedArray types. */ export type TypedIntArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array; /** * All supported floating-point TypedArray types. */ export type TypedFloatArray = Float32Array | Float64Array; /** * Union of all supported TypedArray types (integer and float). */ export type TypedArray = TypedIntArray | TypedFloatArray; /** * Type guard: Returns true if value is a TypedArray (but not DataView). */ export declare function isTypedArray(value: unknown): value is TypedArray; /** * Type guard: Returns true if value is an array of numbers. */ export declare function isNumberArray(value: unknown): value is number[]; /** * Generic constructor type for any class. */ export type TConstructor<T> = new (...args: any) => T; /** * Converts a number[] or TypedArray to a specific TypedArray type. * If the input is already of the correct type, it is returned as-is. * * @param data - The input data (number[] or TypedArray) * @param type - The targeted TypedArray (e.g., Float32Array) * @returns The data as the specified TypedArray type */ export declare function toTypedArray<T extends TypedArray>(data: TypedArray | number[], type: TConstructor<T>): T;