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

@seed-fe/global

v1.0.1

Published

A library that exposes variables to the global scope.

Readme

@seed-fe/global

向全局作用域暴露变量。

安装

# 使用 npm
npm install @seed-fe/global

# 使用 yarn
yarn add @seed-fe/global

# 使用 pnpm (推荐)
pnpm add @seed-fe/global

使用

import global from '@seed-fe/global';

// 设置全局变量
global.set('myApp', 'config', { apiUrl: 'https://api.example.com' });

// 获取全局变量
const config = global.get('myApp', 'config');
// 或直接访问 myApp.config 对象

// 检查全局变量是否存在
if (global.has('myApp', 'config')) {
  // 存在
}

// 删除全局变量
global.remove('myApp', 'config');

// 删除整个命名空间
global.remove('myApp');

// 一次性设置多个变量
global.setMany('myApp', {
  version: '1.0.0',
  debug: true,
  config: { apiUrl: 'https://api.example.com' }
});

// 获取命名空间下的所有变量
const allValues = global.getAll('myApp');
// allValues = { version: '1.0.0', debug: true, config: { apiUrl: 'https://api.example.com' } }

特性

保护机制

该库使用代理机制保护全局变量,防止直接修改:

// 设置全局变量
global.set('myApp', 'version', '1.0.0');

// 尝试直接修改(会被阻止并显示警告)
window.myApp.version = '2.0.0'; // 不会生效

// 正确的修改方式
global.set('myApp', 'version', '2.0.0');

这种保护机制确保了全局变量只能通过库提供的API进行修改,避免了意外覆盖或修改的风险。

API

set(scope, key, value)

设置全局变量。

  • scope: 命名空间,字符串类型
  • key: 变量名,字符串类型
  • value: 变量值,任意类型
  • 返回: 设置的值
global.set('myApp', 'config', { apiUrl: 'https://api.example.com' });

setMany(scope, values)

一次性设置多个全局变量。

  • scope: 命名空间,字符串类型
  • values: 包含多个键值对的对象
  • 返回: 设置的对象
global.setMany('myApp', {
  version: '1.0.0',
  debug: true,
  config: { apiUrl: 'https://api.example.com' }
});

get(scope, key)

获取全局变量。

  • scope: 命名空间,字符串类型
  • key: 变量名,字符串类型
  • 返回: 变量值,如果不存在则返回 undefined
const config = global.get('myApp', 'config');

getAll(scope)

获取命名空间下的所有变量。

  • scope: 命名空间,字符串类型
  • 返回: 包含所有键值对的对象,如果命名空间不存在则返回 undefined
const allValues = global.getAll('myApp');

has(scope, key?)

检查全局变量是否存在。

  • scope: 命名空间,字符串类型
  • key: 可选,变量名,字符串类型
  • 返回: 布尔值,表示变量是否存在
// 检查特定变量是否存在
if (global.has('myApp', 'config')) {
  // 存在
}

// 检查命名空间是否存在
if (global.has('myApp')) {
  // 存在
}

remove(scope, key?)

删除全局变量。

  • scope: 命名空间,字符串类型
  • key: 可选,变量名,字符串类型
  • 返回: 布尔值,表示是否成功删除
// 删除特定变量
global.remove('myApp', 'config');

// 删除整个命名空间
global.remove('myApp');

许可证

MIT