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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@zgcos/micro-app

v1.0.1

Published

ZGCOS micro-app utility library

Downloads

179

Readme

@zgcos/micro-app

ZGCOS micro-app utility library

Installation

npm install @zgcos/micro-app
# or
pnpm add @zgcos/micro-app
# or
yarn add @zgcos/micro-app

Usage

import { configUtils } from "@zgcos/micro-app";

// 初始化开发环境配置
// 从 rawWindow 中获取 SITE_CONFIG 配置和 _logoutHandle
configUtils.initDev();

// 挂载 rawWindow 上的指定属性/方法到 window
configUtils.mountGlobals(["SITE_CONFIG", "_logoutHandle"]);

// 解绑指定的全局属性/方法
configUtils.unMountGlobals(["_logoutHandle"]);

默认导出方式

import microApp from "@zgcos/micro-app";

microApp.configUtils.initDev();
microApp.configUtils.mountGlobals(["SITE_CONFIG"]);
microApp.configUtils.unMountGlobals(["SITE_CONFIG"]);

API

configUtils.initDev()

初始化开发环境配置。从 rawWindow 中获取 SITE_CONFIG 配置并合并到当前 window.SITE_CONFIG,同时复制 _logoutHandle 方法。

功能说明:

  • window.rawWindow.SITE_CONFIG 获取配置并合并到 window.SITE_CONFIG
  • 复制 window.rawWindow._logoutHandlewindow._logoutHandle
  • 如果出现跨域限制或其他错误,会在控制台输出警告信息

示例:

import { configUtils } from "@zgcos/micro-app";

// 在应用启动时调用
configUtils.initDev();

// 之后可以使用 window.SITE_CONFIG 和 window._logoutHandle
console.log(window.SITE_CONFIG);
window._logoutHandle?.();

configUtils.mountGlobals(keys: string[])

rawWindow 上指定的属性/方法挂载到当前 window

参数:

  • keys: 需要挂载的属性名数组

行为:

  • rawWindow 不存在时会直接警告并跳过
  • 属性存在则挂载;不存在则警告;异常会单独警告

configUtils.unMountGlobals(keys: string[])

将当前 window 上指定的属性/方法卸载(删除)。

参数:

  • keys: 需要卸载的属性名数组

行为:

  • 属性存在则删除;不存在则警告;异常会单独警告

类型声明

该库扩展了全局 Window 接口,添加了以下类型:

  • window.rawWindow: 原始窗口对象,可能包含 SITE_CONFIG_logoutHandle
  • window.SITE_CONFIG: 站点配置对象
  • window._logoutHandle: 登出处理函数

注意事项

  • 如果 rawWindow 不存在或无法访问(可能由于跨域限制),方法会静默失败并输出警告
  • 配置合并采用对象展开语法,rawWindow.SITE_CONFIG 的配置会覆盖现有的 window.SITE_CONFIG 配置