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

@forward-widget/libs

v2.1.0

Published

[![NPM Version](https://img.shields.io/npm/v/@forward-widget/libs)](https://www.npmjs.com/package/@forward-widget/libs) ![NPM License](https://img.shields.io/npm/l/@forward-widget/libs)

Readme

@forward-widget/libs

NPM Version NPM License

Forward Widget 开发工具库

🚀 简介

@forward-widget/libs 是一个专为 Forward Widget 开发者设计的工具库,提供了完整的类型定义和测试工具,帮助开发者更高效地构建和测试 Widget 应用。

📦 安装

npm install @forward-widget/libs
# 或
yarn add @forward-widget/libs
# 或
pnpm add @forward-widget/libs

🛠️ 使用方法

环境类型定义

TypeScript 项目

在你的项目中创建一个 .d.ts 文件,引入类型定义:

// forward-widget-env.d.ts
/// <reference types="@forward-widget/libs/env" />

这样你就可以在 TypeScript 代码中获得完整的类型支持:

// 现在可以使用 Widget 相关的类型和全局变量
WidgetMetadata = {
  name: "My Widget",
  version: "1.0.0",
  // ... 其他配置
};

async function loadDetail(url: string) {
  const resp = await Widget.http.get('https://api.example.com/data')

  const result: VideoItem = {
    // ...
  }
  // ...
  return result
}

JavaScript 项目

对于 JavaScript 项目,你可以使用 JSDoc 来获得类型提示:

/**
 * @type {import('@forward-widget/libs/env')}
 */


WidgetMetadata = {
  name: "My Widget",
  version: "1.0.0",
  // ... 其他配置
};

async function loadDetail(url) {
  const resp = await Widget.http.get('https://api.example.com/data')
  /**
   * @type {import('@forward-widget/libs/env').VideoItem}
   */
  const result = {
    // ...
  }
  // ...
  return result
}

单元测试

@forward-widget/libs 提供了 WidgetAdaptor 来模拟 Widget 运行环境,方便进行单元测试。

Rstest 为例:

import { expect, test, beforeAll } from "@rstest/core";

beforeAll(async () => {
  const { WidgetAdaptor } = await import("@forward-widget/libs/widget-adaptor");
  rstest.stubGlobal("Widget", WidgetAdaptor);
});

test("测试 HTTP 请求", async () => {
  const response = await Widget.http.get("https://api.example.com/data");
  expect(response).toBeDefined();
  expect(response.status).toBe(200);
});

TMDB

如果需要使用到 Widget.tmdb 下的方法,需要环境变量中配置 TMDB_API_KEY

# .env
TMDB_API_KEY=xxxx
// rstest.config.ts

import { defineConfig } from "@rstest/core";

export default defineConfig({
  testEnvironment: "node",
  pool: {
    type: "forks",
    execArgv: ["--env-file=.env"], // 通过指定 env-file 加载环境变量
  },
});

🤝 贡献

欢迎提交 Issue 和 Pull Request 来改善这个项目。

📄 许可证

MIT License