npm.io
0.0.13 • Published 11 months ago

computers

Licence
MIT
Version
0.0.13
Deps
0
Size
193 kB
Vulns
0
Weekly
25

computers

type-safe bi-directional communication library

Installation

bun i computers

Simple example:

// In your browser
import {web} from 'computers/web';
import type {api} from './frame.ts';

const iframe = document.querySelector('iframe');
const client = web<api>({
	self: window,
	target: frame.contentWindow,
});

client.add(10, 20);
// In your frame.ts (which the iframe loads somehow)
import {web} from 'computers/web';

const api = {
	add: (a: number, b: number) => a + b,
};

export type api = typeof api;

web(
	{
		self: window,
		target: window.parent,
	},
	api, // Pass `api` as a second argument to expose it
);

This is a project by @aidenybai & @alii