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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lesterchn/csa

v1.0.1

Published

Cross site accessor

Downloads

2

Readme

CsaAccessor iFrame/Frame 跨站/跨域访问器

初始化

yarn add @lesterchn/csa
npm i @lesterchn/csa
yarn add @lesterchn/csa

创建主站访问器

import { createMasterAccessor } from "@lesterchn/csa";

const master = createMasterAccessor({ el: "#frame" });

// 导出从站调用的方法
master.expose = {
  getMaster() {
    return `invoke getMaster`;
  },
  sayMaster(name: string) {
    return `master: ${name}`;
  },
};

// 连接成功后
master.ready(() => {
  console.log("slave 已准备好了");
  // 调用方法1
  console.log("调用getFrame返回值:", frame.call("getFrame"));
  // 调用方法2,并携带参数
  console.log("调用sayFrame返回值:", frame.call("sayFrame", "我是Master"));
  // 发送/推送普通消息
  frame.emit("frame:xxx", new Date().toLocaleDateString());
});

// 监听消息
master.on('master:xxx', (message: string) {
  console.log(message);
});

/** 监听一次性消息 */
master.on('master:xxx2', (message: string, args2: string) {
  /// todo
}, true)

创建从站访问器

import { createMasterAccessor } from "@lesterchn/csa";

const frame = createFrameAccessor();
// 到处主站调用的方法
frame.expose = {
  getFrame() {
    return `getSlave invoke`;
  },
  sayFrame(name: string) {
    return `frame: ${name}`;
  },
};

// 连接主站成功后回调
frame.ready(() => {
  console.log("slave 已准备好了");
  // 调用主站方法1
  console.log("调用getMaster返回值:", frame.call("getMaster"));
  // 调用主站方法2,并携带参数
  console.log("调用sayMaster返回值:", frame.call("sayMaster", "我是Frame"));
   // 发送/推送普通消息
  frame.emit("frame:xxx", new Date().toLocaleDateString());
});

// 监听消息
frame.on('frame:xxx', (message: string) {
  console.log(message);
});

/** 监听一次性消息 */
frame.on('frame:xxx2', (message: string, args2: string) {
  /// todo
}, true)

浏览器引用

<script src="csa.umd.cjs"></script>
<script>
  const master = Csa.createMasterAccessor({ frame: "#frame" });
  // 导出方法
  master.expose = {
    getMaster() {
      return `invoke getMaster`;
    },
    sayMaster(name: string) {
      return `master: ${name}`;
    },
  };
</script>

<script>
  const frame = Csa.createFrameAccessor({});
  // 导出方法
  frame.expose = {
    getFrame() {
      return `getSlave invoke`;
    },
    sayFrame(name: string) {
      return `frame: ${name}`;
    },
  };
</script>