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

@pisell/pisellos

v0.0.397

Published

一个可扩展的前端模块化SDK框架,支持插件系统

Readme

PisellOS 前端 SDK 框架

PisellOS 是一个灵活的、可扩展的前端 SDK 框架,专为构建模块化应用设计。它支持插件系统,允许在不同运行环境中无缝集成功能。

特性

  • 模块化架构:支持各种功能模块(如购物车、结账流程等)的插入和管理
  • 插件系统:通过插件提供环境抽象,解决跨环境兼容性问题
  • 事件驱动:基于事件总线的模块间通信机制
  • 类型安全:使用 TypeScript 构建,提供完整的类型定义
  • 轻量级:核心框架轻量,按需加载模块

安装

npm install pisell-os

快速开始

基本用法

import PisellOSCore, { plugins, modules } from "pisell-os";

// 创建 PisellOS 实例
const pisellOS = new PisellOSCore({
	debug: true, // 开启调试日志
	plugins: [{ plugin: plugins.window }, { plugin: plugins.request }],
	modules: [
		{
			module: modules.cart,
			options: {
				plugins: ["window", "request"], // 依赖的插件
			},
		},
	],
});

// 获取购物车模块并使用
const cartModule = pisellOS.getModuleExports("cart");
await cartModule.addItem({
	id: "product-001",
	name: "商品1",
	price: 99.9,
	quantity: 1,
});

// 使用插件
const windowPlugin = pisellOS.getPlugin("window");
windowPlugin.localStorage.setItem("key", "value");

架构

PisellOS 的核心架构包括四个主要部分:

  1. 核心框架:负责模块和插件的注册、管理和生命周期控制
  2. 插件系统:为不同环境提供统一接口,如 window、request 等
  3. 模块系统:提供业务功能实现,可依赖插件和其他模块
  4. 解决方案:解决方案是 pisell_os 中对业务流程层的抽象,用于将多个独立的模块(Module)编排成一个完整的业务解决方案。 它本质上是一个特殊的“业务 orchestrator”,负责协调模块调用、控制数据流动和处理统一状态管理。

核心 API

// 创建实例
const pisellOS = new PisellOSCore(options);

// 注册插件
pisellOS.registerPlugin(plugin, options);

// 注册模块
pisellOS.registerModule(module, options);

// 获取插件
const plugin = pisellOS.getPlugin<PluginType>(name);

// 获取模块
const module = pisellOS.getModule<ModuleType>(name);

// 获取模块导出的 API
const api = pisellOS.getModuleExports<ApiType>(name);

// 事件机制
pisellOS.on(event, handler);
pisellOS.emit(event, data);

内置插件

PisellOS 提供了几个内置插件以简化开发:

  • window:提供 window 对象模拟,包括 localStorage、setTimeout 等
  • request:提供网络请求功能,支持各种 HTTP 方法和拦截器

内置模块

  • cart:购物车模块,提供商品管理、数量更新等功能

自定义扩展

创建自定义插件

import { Plugin } from "pisell-os";

class MyPlugin implements Plugin {
	name = "my-plugin";
	version = "1.0.0";

	initialize() {
		console.log("My plugin initialized");
	}

	destroy() {
		console.log("My plugin destroyed");
	}

	// 自定义方法
	myMethod() {
		return "Hello from my plugin";
	}
}

export default new MyPlugin();

创建自定义模块

import { Module, PisellCore } from "pisell-os";

class MyModule implements Module {
	name = "my-module";
	version = "1.0.0";

	private core: PisellCore;

	// 导出 API
	exports = {
		doSomething: () => this.doSomething(),
	};

	initialize(core: PisellCore) {
		this.core = core;
		console.log("My module initialized");
	}

	destroy() {
		console.log("My module destroyed");
	}

	private doSomething() {
		return "Hello from my module";
	}
}

export default new MyModule();

开发

# 安装依赖
npm install

# 构建项目
npm run build

# 运行示例
npm run example

# 开发模式
npm run dev

许可

MIT License