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

funcstore

v0.1.0

Published

Hello World.

Readme

FuncStore

一个用于存储、管理和执行 JavaScript 函数的 TypeScript 库。支持通过 Service Worker 动态提供函数代码。

特性

  • 函数存储: 使用 IndexedDB 存储完整的 JavaScript 函数代码
  • 动态执行: 通过 Blob URL 和动态 import 执行函数
  • Service Worker 支持: 通过自定义 URL 路径访问函数代码
  • TypeScript 支持: 完整的类型定义
  • 函数管理: 增删改查、搜索、标签分类
  • 安全执行: 代码语法验证和错误处理

安装

npm install funcstore
# 或
pnpm add funcstore

基本使用

创建 FuncStore 实例

import { FuncStore } from 'funcstore'

const funcStore = new FuncStore({
  databaseName: 'MyFunctions', // 可选,默认 'FuncStore'
  tableName: 'functions'       // 可选,默认 'functions'
})

注册函数

// 注册一个计算器函数
const functionId = await funcStore.registerFunction({
  name: 'calculator',
  description: '基础计算器',
  code: `
// 计算器函数
function calculator(operation, a, b) {
  switch (operation) {
    case '+': return a + b;
    case '-': return a - b;
    case '*': return a * b;
    case '/': return a / b;
    default: throw new Error('不支持的操作');
  }
}

export default calculator;
  `,
  tags: ['math', 'utility']
})

执行函数

// 直接执行函数
const result = await funcStore.executeFunction(functionId, ['+', 10, 5])
console.log(result.result) // 15

// 通过函数名执行
const result2 = await funcStore.executeFunctionByName('calculator', ['*', 3, 4])
console.log(result2.result) // 12

函数管理

// 获取所有函数
const allFunctions = await funcStore.getAllFunctions()

// 搜索函数
const mathFunctions = await funcStore.searchFunctionsByTag('math')
const calculators = await funcStore.searchFunctions('calculator')

// 删除函数
await funcStore.deleteFunction(functionId)

Service Worker 支持

启用 Service Worker

// 生成 Service Worker 文件内容
const swCode = FuncStore.generateServiceWorkerCode()

// 将 swCode 保存为 funcstore-sw.js 文件到网站根目录

// 启用 Service Worker
const success = await funcStore.enableServiceWorker('/funcstore-sw.js')

通过 URL 访问函数

启用 Service Worker 后,函数可以通过特殊 URL 访问:

// 假设函数 ID 是 'func_123'
const functionUrl = '/funcstore/func_123.js'

// 通过动态导入使用
const module = await import(functionUrl)
const result = module.default('+', 10, 5)

通过 Service Worker 执行

// 直接通过 Service Worker 执行函数
const result = await funcStore.executeFunctionViaServiceWorker(functionId, ['+', 10, 5])

函数代码格式

函数代码应该是完整的 JavaScript 模块:

// ✅ 正确的格式 - 完整的 JavaScript 文件
function myFunction(a, b) {
  return a + b;
}

// 默认导出
export default myFunction;

// 或命名导出
export { myFunction };
// ✅ 异步函数示例
async function fetchData(url) {
  const response = await fetch(url);
  return await response.json();
}

export default fetchData;
// ✅ 带控制台输出的函数
function debugFunction(value) {
  console.log('调试信息:', value);
  return value * 2;
}

export default debugFunction;

API 参考

FuncStore

构造函数

new FuncStore(config?: FuncStoreConfig)

主要方法

  • registerFunction(functionDef) - 注册新函数
  • updateFunction(id, updates) - 更新函数
  • getFunction(id) - 获取函数定义
  • getAllFunctions() - 获取所有函数
  • executeFunction(id, args) - 执行函数
  • executeFunctionByName(name, args) - 通过名称执行函数
  • deleteFunction(id) - 删除函数
  • searchFunctions(keyword) - 搜索函数
  • searchFunctionsByTag(tag) - 按标签搜索
  • enableServiceWorker(swPath?) - 启用 Service Worker
  • executeFunctionViaServiceWorker(id, args) - 通过 SW 执行
  • exportFunction(id) - 导出函数为 JSON
  • importFunction(jsonString) - 从 JSON 导入函数

类型定义

interface JSFunctionDef {
  id: string
  name: string
  description?: string
  code: string  // 完整的 JavaScript 文件代码
  parameters?: FunctionParameter[]
  returnType?: string
  tags?: string[]
  createdAt?: Date
  updatedAt?: Date
  version?: string
}

interface FunctionExecutionResult {
  success: boolean
  result?: any
  error?: string
  executionTime: number
}

演示应用

查看 apps/funcstore-demo 目录中的完整演示应用,展示了所有功能的使用方法。

cd apps/funcstore-demo
pnpm dev

许可证

SEE LICENSE IN LICENSE