@hyperfrontend/immutable-api-utils/built-in-copy/typed-arraystyped-arrays
Locked, prototype-pollution-resistant copies of the global ArrayBuffer, SharedArrayBuffer, DataView, and TypedArray constructors.
Factory wrappers for Uint8Array, Uint8ClampedArray, Uint16Array, Uint32Array, Int8Array, Int16Array, Int32Array, Float32Array, Float64Array, BigInt64Array, BigUint64Array, plus ArrayBuffer, SharedArrayBuffer, and DataView, are captured at module-load time and frozen into a tamper-proof namespace, so binary buffer construction stays trustworthy even if the globals are later patched. Effective only when imported before any untrusted code has had a chance to mutate the prototype chain.
API Reference
ƒ Functions
new ArrayBuffer().Parameters
| Name | Type | Description |
|---|---|---|
§byteLength | number | The size, in bytes, of the array buffer to create. |
Returns
ArrayBufferExample
Creating ArrayBuffer
const buffer = createArrayBuffer(16)
// => ArrayBuffer { byteLength: 16 }new BigInt64Array().Parameters
| Name | Type | Description |
|---|---|---|
§length | number | The length of the array. |
Returns
BigInt64ArrayExample
Creating BigInt64Array
const bigInts = createBigInt64Array(2)
bigInts[0] = -9223372036854775808n // Min value
bigInts[1] = 9223372036854775807n // Max valuenew BigUint64Array().Parameters
| Name | Type | Description |
|---|---|---|
§length | number | The length of the array. |
Returns
BigUint64ArrayExample
Creating BigUint64Array
const bigUints = createBigUint64Array(2)
bigUints[0] = 0n
bigUints[1] = 18446744073709551615n // Max valuecreateDataView(buffer: ArrayBuffer | SharedArrayBuffer, byteOffset?: number, byteLength?: number): DataView
new DataView().Parameters
Returns
DataViewExample
Creating DataView for binary data
const buffer = createArrayBuffer(8)
const view = createDataView(buffer)
view.setInt32(0, 42, true) // little-endian
view.getInt32(0, true) // => 42new Float32Array().Parameters
| Name | Type | Description |
|---|---|---|
§length | number | The length of the array. |
Returns
Float32ArrayExample
Creating Float32Array
const floats = createFloat32Array(3)
floats[0] = 3.14
floats[1] = -273.15new Float64Array().Parameters
| Name | Type | Description |
|---|---|---|
§length | number | The length of the array. |
Returns
Float64ArrayExample
Creating Float64Array
const doubles = createFloat64Array(2)
doubles[0] = Math.PI
doubles[1] = Number.MAX_VALUEnew Int16Array().Parameters
| Name | Type | Description |
|---|---|---|
§length | number | The length of the array. |
Returns
Int16ArrayExample
Creating Int16Array
const shorts = createInt16Array(2)
shorts[0] = -32768 // Min value
shorts[1] = 32767 // Max valuenew Int32Array().Parameters
| Name | Type | Description |
|---|---|---|
§length | number | The length of the array. |
Returns
Int32ArrayExample
Creating Int32Array
const ints = createInt32Array(2)
ints[0] = -2147483648 // Min value
ints[1] = 2147483647 // Max valuenew Int8Array().Parameters
| Name | Type | Description |
|---|---|---|
§length | number | The length of the array. |
Returns
Int8ArrayExample
Creating Int8Array
const signed = createInt8Array(2)
signed[0] = -128 // Min value
signed[1] = 127 // Max valuenew Uint16Array().Parameters
| Name | Type | Description |
|---|---|---|
§length | number | The length of the array. |
Returns
Uint16ArrayExample
Creating Uint16Array
const shorts = createUint16Array(2)
shorts[0] = 65535 // Max value for 16-bit unsignednew Uint32Array().Parameters
| Name | Type | Description |
|---|---|---|
§length | number | The length of the array. |
Returns
Uint32ArrayExample
Creating Uint32Array
const ints = createUint32Array(4)
ints[0] = 0xFFFFFFFF // Max 32-bit unsigned valuenew Uint8Array(). Supports all standard Uint8Array constructor overloads:
createUint8Array(length)- Creates array of given lengthcreateUint8Array(arrayLike)- Creates from array-like or iterablecreateUint8Array(buffer, byteOffset?, length?)- Creates view over buffer
Parameters
| Name | Type | Description |
|---|---|---|
§length | number | The length of the array to create. |
Returns
Uint8ArrayExample
Creating Uint8Array
const bytes = createUint8Array(4)
bytes[0] = 255
// From array
const fromArray = createUint8Array([0x48, 0x65, 0x6c, 0x6c, 0x6f])new Uint8ClampedArray().Parameters
| Name | Type | Description |
|---|---|---|
§length | number | Number of elements to allocate in the clamped array. |
Returns
Uint8ClampedArrayExample
Creating Uint8ClampedArray for pixels
const pixels = createUint8ClampedArray(4) // RGBA
pixels[0] = 300 // Clamped to 255
pixels[1] = -10 // Clamped to 0