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

@lllllxt/storage-idb-message

v1.0.1

Published

基于LocalStorage + IndexedDB 封装的消息传递的模块

Downloads

2

Readme

storage-idb-message

基于 LocalStorage + IndexedDB 封装的消息传递的模块,在同源(不跨域)的前提下,用于同一页面多个 iframe、跨 tab 页面、移动端不同 webview 页面之间的消息传递

做这玩意的初衷

本来我是只用 LocalStorage 做消息传递的, 但后来某次在 Chrome 上传递的数据>5M 导致数据丢失,于是乎就有了用 LocalStorage 做指令,IndexedDB 做数据存储这个想法了

参考:

LocalStorage 储存空间在 2.5MB 到 10MB 之间(各家浏览器不同),而 IndexedDB 比 LocalStorage 大得多,一般来说不少于 250MB,甚至没有上限。

通过 npm 安装

npm i @lllllxt/storage-idb-message
import StorageIdbMessage from '@lllllxt/storage-idb-message'

const StorageIdbMessage = request('@lllllxt/storage-idb-message')

const _SIM = new StorageIdbMessage(opts: Opts)

// 监听指令
_SIM.response = (orderName, data) => {
    console.log(orderName, data)
})

// 发送指令
_SIM.send(YourOrder, AnyData)

通过<script>标签引用

storage-idb-message.min.js

此方法是向 window 对象中注册一个 StorageIdbMessage 对象

参数(Opts)

| 参数 | 描述 | | ---------- | -------------------------------------------------- | | storageKey | 指令的 LocalStorage key 名称 | | clearIdb | 默认 true,是否在 response 后清除 IndexedDB 的数据 | | force | 默认 false,调用 clearCache 清除缓存 |

方法

| 方法 | 描述 | | ---------------------------------- | ------------------------ | | send(order: String, data: any) | 发送 | | response(order: String, data: any) | 响应其他页面传过来的指令 |

静态方法

| 方法 | 描述 | | -------------------------------------------------- | ------------------- | | clearCache(successFn?: Function, errFn?: Function) | 清除 indexedDB 缓存 |

License

This project is licensed under the MIT License