/**
 * Normalizes the given value according to the given typed array.
 *
 * @param {number} value - The float value in the range `[0,1]` to normalize.
 * @param {TypedArray} array - The typed array that defines the data type of the value.
 * @return {number} The normalize value.
 */
export function typed_array_value_normalize(value, array) {
    // taken from https://github.com/mrdoob/three.js/blob/da275a4e00536723155b68518944de5eb7945550/src/math/MathUtils.js#L435

    switch (array.constructor) {

        case Float32Array:

            return value;

        case Uint32Array:

            return Math.round(value * 4294967295.0);

        case Uint16Array:

            return Math.round(value * 65535.0);

        case Uint8Array:

            return Math.round(value * 255.0);

        case Int32Array:

            return Math.round(value * 2147483647.0);

        case Int16Array:

            return Math.round(value * 32767.0);

        case Int8Array:

            return Math.round(value * 127.0);

        default:

            throw new Error('Invalid component type.');

    }

}