JS to ArrayBuffer to JS

Usage no npm install needed!

<script type="module">
  import jmao from '';


xxx (currently published as jmao)

This dangerous module converts any arbitrary JS into an ArrayBuffer, and converts any such ArrayBuffer back to JS. That's in the browser. In Node, it transparently uses Buffers.

It includes special handling for browserify's Node Buffer, and for ndarrays.

why johnny?

A couple of reasons.

Browsers speak ArrayBuffers at the lowest level. I wanted to to send and recieve data that way. I use ndarrays and TypedArrays a lot, so I wanted to easily send them over the network, and between windows / processes. Stringifying large ArrayBuffers is not ideal. But sending metadata such as can accompany any old JSON is nice. The twain have met. Now I can shoot straight JS data types from one tab to another, and over the network.

So you can

This module exports two functions:

var xxx = require('jmao')
var deconstruct = xxx.deconstruct
var construct = xxx.construct


var obj = {id: 'HK289hns918hNPN8yphp', body: new Float32Array(64)}
var event = {name: 'data', data: obj}
var buffer = deconstruct(event)
//  ArrayBuffer {}
window.parent.postMessage(buffer, '*')


window.onmesssage = function(evt){
  var buffer =
  var event = construct(
  var data =