Bit-TypedArray
Bit-TypedArray copied to clipboard
Complete implementation of standard typed arrays
Current code only partially implements standard features of typed arrays. This issue provides a place to track progress and view it all in one shot.
PRs welcome!
Constructor
- [x]
new TypedArray() - [x]
new TypedArray(length) - [x]
new TypedArray(typedArray) - [x]
new TypedArray(object) - [ ]
new TypedArray(buffer): see here
Unrelevant (= won't implement)
- [x]
new TypedArray(buffer, byteOffset): see here - [x]
new TypedArray(buffer, byteOffset, length): see here
Static properties
- [x]
BYTES_PER_ELEMENT - [x]
name - [ ]
get BitArray[@@species]
Static methods
- [x]
from() - [x]
of()
Instance properties
- [x]
buffer - [x]
byteLength - [x]
byteOffset - [x]
length
Instance methods
- [x]
at(): see here for discussion - [ ]
copyWithin() - [ ]
entries() - [ ]
every() - [ ]
fill() - [ ]
filter() - [ ]
find() - [ ]
findIndex() - [x]
forEach() - [ ]
includes() - [ ]
indexOf() - [ ]
join() - [ ]
keys() - [ ]
lastIndexOf() - [ ]
map() - [ ]
reduce() - [ ]
reduceRight() - [ ]
reverse() - [x]
set() - [ ]
slice() - [ ]
some() - [ ]
sort() - [ ]
subarray() - [x]
values() - [x]
toString(): see here for note on implementation. - [x]
[@@iterator]()
Irrelevant (= won't implement)
- [x]
toLocaleString(): there is no local variation to displaying 1s or 0s.
Fwiw, I got a hacky horrible inefficient version of "ArrayBuffer to BitArray" to work via the following
const vals = []
for(const b of new Uint8Array(buffer)) {
for (let i = 0; i < 8; i++) {
vals.push(!!(b & (1 << i)))
}
}
let arr = BitArray.from(vals)
Obviously the correct version doesn't have so much unnecessary byte->string->byte conversion :)
Indeed! :)
Tbh, I have not yet made my mind whether it makes sense to construct a BitArray by passing an array buffer to the constructor. FFS...
I actually have a use case! I have a settings object in my react app; it has a great number of boolean or near boolean enums. I want to store the user settings in a query param, so I load the settings into a bit array, and then turn that into base64 from that array buffer. This allows the settings to be shared or survive a page reload. To deserialize, I load the bas64 string back into array buffer, and then into the bitarray to reconstruct the settings.
@rollie42, in order to not pollute this general-purpose issue, I have created a specific issue here.