npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

transfer-webview-channel

v1.0.4

Published

A lightweight library for handling communication between webview and native apps

Readme

transfer-webview-channel

一个轻量级的WebView与原生应用通信库。

安装

npm install transfer-webview-channel

特性

  • 轻量级,无外部依赖
  • 支持双向通信
  • 支持超时处理
  • 支持自定义数据解析
  • Promise风格的API

使用方法

初始化

import transfer from 'transfer-webview-channel';

// 定义数据传输实现方法
const transferImpl = (data) => {
    // 实现与原生端的通信
    window.webkit.messageHandlers.nativeHandler.postMessage(data);
};

// 初始化
await transfer.init(transferImpl);

发送消息

// 基本使用
const result = await transfer.transferData({
    id: 'uniqueId',           // 必需,消息唯一标识
    actionType: 'getData',    // 可选,动作类型
    data: 'someData',         // 可选,传输的数据
    ext: 'extraInfo'          // 可选,额外信息
});

// 设置超时
const result = await transfer.transferData(
    {
        id: 'uniqueId',
        data: 'someData'
    },
    true,       // 是否等待响应
    5000        // 超时时间(ms)
);

// 不等待响应
await transfer.transferData(
    {
        id: 'uniqueId',
        data: 'someData'
    },
    false       // 不等待响应
);

自定义数据解析

// 自定义数据解析方法
const customParser = (data) => {
    // 实现自定义解析逻辑
    return JSON.parse(data);
};

// 初始化时传入自定义解析方法
await transfer.init(transferImpl, customParser);

API

init(transferfun, parseDatafun)

初始化通信库。

  • transferfun: (必需) 实现与原生端通信的方法
  • parseDatafun: (可选) 自定义数据解析方法,默认使用 JSON.parse

transferData(params, isAwait, maxTime)

发送数据并等待响应。

  • params: (必需) 传输的数据对象
    • id: (必需) 消息唯一标识
    • actionType: (可选) 动作类型
    • data: (可选) 传输的数据
    • ext: (可选) 额外信息
  • isAwait: (可选) 是否等待响应,默认为 true
  • maxTime: (可选) 超时时间(ms),默认为 3000ms,设为 -1 则永不超时

原生

请务必将原生端的实现与通信库进行匹配,最重要的是id的匹配,如果不返回id,那么通信库将无法识别响应。

许可证

ISC