Socket
Book a DemoInstallSign in
Socket

hsjssdk

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

hsjssdk

hookshort web native bridge

0.0.2
unpublished
latest
npmnpm
Version published
Weekly downloads
0
Maintainers
0
Weekly downloads
 
Created
Source

HSJSSDK

HSJSSDK 是一个简单的 HookShort JavaScript SDK,用于与 JS 桥接进行交互。它提供了一个方便的接口来调用桥接方法,并处理响应。

安装

你可以通过 npm 安装 HSJSSDK:

npm install HSJSSDK

使用

导入 SDK

在你的 JavaScript 或 TypeScript 项目中,你可以通过以下方式导入 HSJSSDK:

import HSJSSDK from 'HSJSSDK';
// 或者
import { invokeJsBridge } from 'HSJSSDK';

调用桥接方法

使用 invokeJsBridge 方法调用桥接方法。以下是一个示例:

async function callBridge() {
  try {
    const response = await invokeJsBridge('someMethod', { key: 'value' });
    console.log(response);
  } catch (error) {
    console.error('Error invoking bridge:', error);
  }
}

callBridge();

类型定义(TypeScript)

如果你在 TypeScript 项目中使用 HSJSSDK,SDK 提供了类型定义,确保你可以获得类型检查和自动补全。

import { invokeJsBridge, InvokeJsBridgeResponse } from 'HSJSSDK';

async function callBridge() {
  const response: InvokeJsBridgeResponse<{ someData: string }> = await invokeJsBridge('someMethod', { key: 'value' });
  console.log(response);
}

API

invokeJsBridge(name: string, data?: Record<string, any>, opts?: { timeout?: number | boolean }): Promise<InvokeJsBridgeResponse<T>>

  • name: 要调用的桥接方法的名称。
  • data: 传递给桥接方法的数据(可选)。
  • opts: 选项对象(可选)。
    • timeout: 超时时间(以毫秒为单位),默认为 3000 毫秒。如果设置为 false,则禁用超时。

返回值

返回一个 Promise,解析为 InvokeJsBridgeResponse<T> 类型的响应对象。

InvokeJsBridgeResponse<T>

  • success: 表示调用是否成功的布尔值。
  • data: 返回的数据,类型为 Tnull

贡献

欢迎任何形式的贡献!请提交问题、请求功能或直接提交拉取请求。

许可证

此项目使用 MIT 许可证。有关详细信息,请查看 LICENSE 文件。

FAQs

Package last updated on 15 Nov 2024

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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.