@capacitor/synapse

中文文档
1.0.4发布于 2025/07/11ISCTypeScriptESM + CJS零依赖近 30 天下载 779.6万

Example

原始使用文档

Synapse

Example

You have plugins that exist for both Capacitor and Cordova. They share the same API for the most part; as in they both expose a ping method that takes a string and returns that string with the word "_pong" appeneded to it. You can use synapse to create a single call in ODC that will use which ever plugin is available to the built app. Adding this to your plugins does not alter their ability to be used in the normal fashion they would be directly in a Capacitor or Cordova app.

Capacitor Usage of MyPlugin

import { MyPlugin } from 'capacitor-my-plugin';
...
async function buttonClick() {
  try {
    const resp = await MyPlugin.ping({text: "Hello World"});
    console.log(resp); // "Hello World_pong"
  } catch (error) {
    console.error(error);
  }
}

Cordova Usage of MyPlugin

function buttonClick() {
  window.cordova.plugins.MyPlugin.ping(
    {text: "Hello World"},
    function(response) {
      console.log(response); // "Hello World_pong"
    },
    function(error) {
      console.error(error);
    }
  )
}

Synapse Usage of MyPlugin

function buttonClick() {
  window.CapacitorUtils.Synapse.MyPlugin.ping(
    {text: "Hello World"},
    function(response) {
      console.log(response); // "Hello World_pong"
    },
    function(error) {
      console.error(error);
    }
  )
}

While similar to the way you call cordova plugins, the synapse call will use the appropriate plugin for the platform it is running on. If the app is built with Capacitor, it will use the Capacitor plugin. If the app is built with Cordova, it will use the Cordova plugin.

版本与发布记录

@capacitor/synapse 共发布 6 个版本,首次发布于 2024/11/22;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.4latest2025/07/111.3 年前
1.0.32025/06/161.4 年前
1.0.22025/02/201.7 年前
1.0.2-dev.1dev2025/02/141.7 年前
1.0.12024/11/222 年前
1.0.02024/11/222 年前

关于 @capacitor/synapse 的常见问题

@capacitor/synapse 是什么?

Example

如何安装 @capacitor/synapse?

在项目目录运行 npm install @capacitor/synapse,或使用 pnpm add / yarn add / bun add。

@capacitor/synapse 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capacitor/synapse 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capacitor/synapse 可以商用吗?

@capacitor/synapse 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@capacitor/synapse 的下载量有多少?

根据 npm 官方下载统计,@capacitor/synapse 在 2026/10/09 – 2026/11/07 这 30 天内被下载 7,795,743 次,日均约 259,858 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capacitor/synapse 还在维护吗?

最新版本 1.0.4 发布于 2025/07/11(1.3 年前);至今共发布 6 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/11/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。