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

event-ratel

v1.0.2

Published

一个微前端使用的postmessage消息透传库

Readme

EventRatel

介绍

一个微前端使用的postmessage消息透传库,支持iframe和主框架之间的消息通信,同时支持获取父页面的cookie、localStorage和sessionStorage。

安装教程

支持三种不同的引入方式:ES模块(import)、CommonJS(require)和UMD(script标签)。以下是每种引入方式的使用方法:

  1. 使用ES模块(import) 对于使用ES模块的环境,如现代前端框架或支持ES6的浏览器:

    // 方式1: 默认导入
    import EventRatel from 'event-ratel';
    
    // 使用
    const eventRatel = new EventRatel();
    // 或者使用单例模式
    const eventRatel = EventRatel.getInstance();
    
  2. 使用CommonJS(require) 对于Node.js环境或使用CommonJS模块系统:

    // 方式1: 默认导入
    const EventRatel = require('event-ratel');
    
    // 使用
    const eventRatel = new EventRatel();
    // 或者使用单例模式
    const eventRatel = EventRatel.getInstance();
    
  3. 使用UMD(script标签) 对于直接在浏览器中使用script标签引入:

    <!-- 引入UMD版本 -->
    <script src="https://unpkg.com/event-ratel/dist/index.umd.min.js"></script>
    <script>
    // 使用全局变量EventRatel
    const eventRatel = new EventRatel();
    // 或者使用单例模式
    const eventRatel = EventRatel.getInstance();
    </script>
    

使用说明

  1. 发送透传消息
    eventRatel.emit('someEvent', data)
    eventRatel.emit('someEvent', data, 'iframeId') //指定iframe监听
    eventRatel.emitParent('someEvent', data) // 只给父级窗口发送消息
    eventRatel.on('someEvent', (data) => {
        console.log('Received:', data);
    })
    eventRatel.off('someEvent')
    
    这里的off事件,需要把on监听的方法单独抽离出来,跟vuebus监听是一样的用法,例如:
    created() {
        eventRatel.on("someEvent", this.handleMessage);
    },
    methods: {
        handleMessage(data) {
            console.log(data);
        },
    },
    beforeDestroy() {
        eventRatel.off("someEvent", this.handleMessage);
    },
  2. 获取父页面的cookie【返回一个Promise】
    eventRatel.getParentCookie(key) // 获取指定key的cookie,不传获取全部
  3. 获取父页面的localStorage【返回一个Promise】
    eventRatel.getParentLocalStorage(key) // 获取指定key的localStorage,不传获取全部
  4. 获取父页面的sessionStorage【返回一个Promise】
    eventRatel.getParentSessionStorage(key) // 获取指定key的sessionStorage,不传获取全部

实例化参数配置

```
const instance = EventRatel.getInstance({
    securityMode: true,
    trustedOrigins: ['https://example.com', 'https://*.example2.com']
});
```
功能说明
  1. 安全模式开关:通过 securityMode 参数控制,默认为 false(开放模式)

  2. 信任域名列表:通过 trustedOrigins 参数配置,支持:

     精确匹配:https://example.com
     通配符匹配:https://*.example2.com
     全部允许:*
     空数组或不传时:安全模式下不传时只能同源域名下进行消息透传

参与贡献

  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request

特技

  1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
  2. Gitee 官方博客 blog.gitee.com
  3. 你可以 https://gitee.com/explore 这个地址来了解 Gitee 上的优秀开源项目
  4. GVP 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
  5. Gitee 官方提供的使用手册 https://gitee.com/help
  6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 https://gitee.com/gitee-stars/