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

@saryz/portal-bridge

v1.1.15

Published

portal 桥接工具

Readme

@saryz/portal-bridge

用于iframe双向通信的封装

未来计划

返回promise以便可以在 async/await 时使用使代码逻辑更清晰

安装 install

npm i @saryz/portal-bridge -S

快速使用 Quick to use

监听 listen

javascript

<script src="[path]/node_modules/@saryz/portal-bridge/dist/portal-bridge.min.js">代码</script>
// js使用的时候 需要PortalBridge对象
PortalBridge.PortalReceive.listen([key], [callback]) // 接收消息
PortalBridge.PortalSend.postToParent([key],[params],[callback]) // 发送消息

es6

import { PortalReceive } from "@saryz/portal-bridge"

// key 为子父约定 
PortalReceive.listen(key, ({ data }) => {
  // do something
})

触发 trigger

子->父 postToParent(子触发父方法)

import { PortalSend } from "@saryz/portal-bridge"

const params = { ... }
// key 为子父约定 
PortalSend.postToParent(key, params)

父->子 postToIframe(父触发子方法)

import { PortalSend } from "@saryz/portal-bridge"

const params = { ... }
// iframe:HTMLIFrameElement 
// const iframe = this.$refs.iframe // Vue
// const iframe = document.getElementById('iframe') // js
PortalSend.postToIframe(iframe, key, params)

回调 callback

获取父页面数据 Get the parent page data

/**** parent.js ****/
const key = 'getUserInfo'
const iframe = this.$refs.iframe
const params = { name: 'saryz', ... }
PortalReceive.listen(key, (data) => {
  console.log('Received data from iframe', data)
  PortalSend.postToIframe(iframe, key, params)
})

/**** child.js * example vue ****/
methods: {
  // get the parent page data 获取父页面数据
  getUserInfo()
  {
    const params = { msg: 'Please give me the user information' }
    const key = 'getUserInfo'
    PortalSend.postToParent(key, params, (data) => {
      console.log('parent page data', data)
      // do something
    })
  }
}

获取子页面数据 Get the child page data

/**** child.js ****/
const key = 'submit'
const params = { name: 'saryz', ... }
PortalReceive.listen(key, (data) => {
  console.log('father need me', data)
  // do something or What also not stem
  PortalSend.postToParent(key, params )
})

/**** father.js * example vue ****/
methods: {
  // get the parent page data 获取父页面数据
  submit()
  {
    const params = { msg: 'Mahler gobi submit!' }
    const key = 'submit'
    const iframe = this.$refs.iframe
    PortalSend.postToIframe(iframe, key, params, ({data}) => {
      console.log('child data', data) // { name: 'saryz', ... }
      // do something
    })
  }
}

接口 interface

/**
 * 监听
 */
listen(methodName: string, callback: PortalBridgeCallback): void;

/**
* 发消息给iframe中的子页面
* @param iframe 必填,iframe对应的dom
* @param methodName 必填,通信名
* @param data 非必填,要传输的数据
* @param callback 非必填,通信回调,用于直接接收子级返回数据
*/
postToIframe(iframe: HTMLIFrameElement, methodName: string, data?: any, callback?: PortalBridgeCallback | undefined): void;

/**
* 发消息给父级页面
* @param methodName 必填,通信名
* @param data 非必填,要传输的数据
* @param callback 非必填,通信回调,用于直接接收父级返回数据
*/
postToParent(methodName: string, data?: any, callback?: PortalBridgeCallback | undefined): void;