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

octopus-platform

v0.2.0

Published

平台兼容性磨平

Readme

Octopus Platform

octopus-platform 是一个支持多端兼容的跨平台模板。使用插件化机制,支持扩展API。

实现

  • [x] 插件化配置
  • [x] 兼容H5端/微信小程序/支付宝小程序/抖音小程序(已验证)

暂未实现

  • [ ] 兼容淘宝小程序
  • [ ] 支持 IndexDB
  • [ ] 支持 IntersectionObserver

安装

npm install octopus-platform -S

使用

创建 platform 类

import {
  OctopusPlatform,
  installPlugin,
  type OctopusPlatformPlugins,
  type OctopusPlatformPluginOptions,
  pluginCanvas,
  pluginDecode,
  pluginDownload,
  pluginFsm,
  pluginImage,
  pluginNow,
  pluginOfsCanvas,
  pluginPath,
  pluginRAF,
} from "octopus-platform";

export type PlatformProperties =
  | "now"
  | "path"
  | "remote"
  | "local"
  | "decode"
  | "image"
  | "rAF"
  | "getCanvas"
  | "getOfsCanvas";

class EnhancedPlatform extends OctopusPlatform<PlatformProperties> {
  now!: OctopusPlatformPlugins["now"];

  path!: OctopusPlatformPlugins["path"];

  remote!: OctopusPlatformPlugins["remote"];

  local!: OctopusPlatformPlugins["local"];

  decode!: OctopusPlatformPlugins["decode"];

  image!: OctopusPlatformPlugins["image"];

  rAF!: OctopusPlatformPlugins["rAF"];

  getCanvas!: OctopusPlatformPlugins["getCanvas"];

  getOfsCanvas!: OctopusPlatformPlugins["getOfsCanvas"];

  constructor() {
    super(
      [
        pluginCanvas,
        pluginOfsCanvas,
        pluginDecode,
        pluginDownload,
        pluginFsm,
        pluginImage,
        pluginNow,
        pluginPath,
        pluginRAF,
      ],
      __VERSION__
    );

    this.init();
  }

  installPlugin(
    plugin: OctopusPlatformPluginOptions<PlatformProperties>
  ) {
    installPlugin<PlatformProperties>(this, plugin);
  }
}

export const platform = new EnhancedPlatform();

platform 版本信息

// 当前库的版本
platform.platformVersion
// 使用这个库的应用版本
platform.version

platform 全局信息

// 当前在哪个平台(微信小程序、支付宝小程序、H5)
platform.globals.env
// 当前平台的全局对象(wx、my、window)
platform.globals.br
// 当前设备的设备像素比
platform.globals.dpr

自定义插件

import { definePlugin } from "octopus-platform";

export default definePlugin<"now">({  
  name: "now",
  install() {
    const { env, br } = this.globals;
    // performance可以提供更高精度的时间测量,且不受系统时间的调整(如更改系统时间或同步时间)的影响
    const perf =
      env === "h5" || env === "tt" ? performance : br.getPerformance();

    if (typeof perf?.now === "function") {
      // 支付宝小程序的performance.now()获取的是当前时间戳,单位是微秒。
      if (perf.now() - Date.now() > 1) {
        return () => perf.now() / 1000;
      }

      // H5环境下,performance.now()获取的不是当前时间戳,而是从页面加载开始的时间戳,单位是毫秒。
      return () => perf.now();
    }

    return () => Date.now();
  },
});

// 安装插件参考上面的 OctopusPlatform 实现

platform.now()

LICENSE

MIT