The Wikipedia page for PackBits algorithm has a JS implementation example and other links.
It has the following comment which includes a JSFiddle as well:
/**
* Helper functions to create readable input and output
*
* Also, see this fiddle for interactive PackBits decoder:
* https://jsfiddle.net/volter9/tj04ejdt/
*/
A PackBits data stream consists of packets with a one-byte header followed by data. The header is a signed byte; the data can be signed, unsigned, or packed (such as MacPaint pixels).
In the following table, n is the value of the header byte as a signed integer.
Header byte Data following the header byte
0 to 127 (1 + n) literal bytes of data
-1 to -127 One byte of data, repeated (1 – n) times in the decompressed output
-128 No operation (skip and treat next byte as a header byte)
It is a fairly simple runlength encoding algorithm.
See: https://github.com/fiahfy/packbits for an implementation in Typescript.
https://en.wikipedia.org/wiki/PackBits