New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

message-port-wrapper

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

message-port-wrapper

Simplified IPC communication for MessagePort.

latest
Source
npmnpm
Version
0.1.3
Version published
Maintainers
1
Created
Source

MessagePort

Simplified IPC communication for MessagePort.

Installation

npm install message-port

Usage

const wrapper1 = MessagePortWrapper(port1);
const wrapper2 = MessagePortWrapper(port2);

wrapper1.on('test', () => 'foo');
wrapper2.on('test', (data: any) => data);


const data1 = await wrapper1<string>('test', 'test'); // 'foo'
const data2 = await wrapper2.call('test', 'test'); // 'test'

API

interface CallFunc {
  /**
   * invoke a handler with return value
   */
  <R = any, T = any>(channel: string, data: T): Promise<R>;
}

export interface MessagePortWrapper extends CallFunc {
  /**
   * invoke a handler without return value
   */
  send: <T = any>(channel: string, data: T) => void;
  invoke: CallFunc;
  /**
   * add a handler
   */
  on: <T = any, R = any>(channel: string, handler: InvokeHandler<T, R>) => void;
  /**
   * add a handler with once
   */
  once: <T = any, R = any>(
    channel: string,
    handler: InvokeHandler<T, R>
  ) => void;
  /**
   * remove a handler
   */
  removeHandler: (channel: string) => void;
  /**
   * remove all handlers
   */
  removeAllHandlers: () => void;
}

Jest

Jest tests are set up to run with npm test or yarn test.

Keywords

electron

FAQs

Package last updated on 12 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts