UNPKG

@webreflection/coincident

Version:

An Atomics based Proxy to simplify, and synchronize, Worker related tasks

25 lines (20 loc) 636 B
import { BIGINT } from 'js-proxy/types'; import { toConstructorName } from '../utils/shared.js'; import createEncoder from '../utils/encoder.js'; import numeric from '../window/types.js'; const { stringify } = JSON; export const encode = value => { switch (value[0]) { case numeric.view: { const { constructor, buffer } = value[1]; value[1] = [toConstructorName(constructor), [...new Uint8Array(buffer)]]; break; } case numeric[BIGINT]: { value[1] = value[1].toString(); break; } } return stringify(value); }; export const encoder = createEncoder(encode);