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

@virid/std

v0.4.0

Published

The virid standard library provides commonly used features in development

Readme

@virid/std

@virid/std@virid/core的官方标准库,负责提供一组开箱即用的实用消息控制流操作。提供了原生的异步流、消息组、防抖节流等支持。

🔌启用插件

import { createVirid, Component, System, EventMessage } from "@virid/core";
import { nextTick, StdPlugin } from "@virid/std";

const app = createVirid().use(StdPlugin, {});

🛠️ @virid/std 核心 API 概览

nextTick

  • 功能:类似于vue中的nextTick,但该Tick指的是一个virid的宏观Tick,因此,当执行时该Tick内的所有同步System已经全部执行完毕,对于异步控制,则需要使用@AsyncQueue装饰器
  • 示例:
nextTick(() => {
  IncreaseBMessage.send();
  IncreaseAMessage.send();
  IncreaseBMessage.send();
});

@AsyncQueue()

  • 功能@AsyncQueue()提供了一个开箱即用的异步消息控制,该装饰器接受一个参数key,对于key相同的message,将严格按照先后顺序执行,而不会出现异步竟态问题。
  • 示例:
@AsyncQueue("increase")
class IncreaseAMessage extends EventMessage {}
@AsyncQueue("increase")
class IncreaseBMessage extends EventMessage {}
@AsyncQueue("decrease")
class DecreaseMessage extends EventMessage {}

// 按以下顺序发送消息
// 由于IncreaseMessage和IncreaseBMessage的key是相同的,
// 即使存在异步操作,以下三条消息也必须按顺序执行
IncreaseAMessage.send();
IncreaseBMessage.send();
IncreaseAMessage.send();
// 由于DecaseMessage和其他消息之间的key不同
// DecaseMessage不会等待上述消息
// 但是,以下三条消息将按顺序执行
DecreaseMessage.send();
DecreaseMessage.send();
DecreaseMessage.send();

executeGroup

  • 功能executeGroup是一组消息的集合,将一组消息严格按照先后顺序一次性执行,并且当途中出错时取消后续逻辑。
  • 示例:
const a = await executeGroup(
[
  new IncreaseAMessage(),
  new IncreaseBMessage(),
  new IncreaseAMessage(),
  new DecreaseMessage(),
],
"first",
);
if (a) {
console.log("[ExecuteGroup] Success");
} else {
console.log("[ExecuteGroup] Failed");
}

@Debounce()/@Throttle

  • 功能:开箱即用的防抖与节流支持。只需要一行代码即可实现。
  • 示例:
// 100ms防抖:停止触发100ms后只执行一次
// 后一个参数用于聚合消息
@Debounce(100, (current, next) => {
  current.val += next.val;
})
class SetTimerAMessage extends EventMessage {
  constructor(public val: number) {
    super();
  }
}

// 100ms节流:100ms内只允许一次触发
@Throttle(500)
class IncreaseBMessage extends EventMessage {}