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

@violets/core

v1.0.8

Published

常用方法扩展

Readme

@violets/core

1.类

Guid

Guid 提供uuid 生成功能 | 名称 | 类型 | 说明 | | :------------: | :------: | :------------: | | Guid.NewGuid() | 静态方法 | 创建Guid字符串 | | Guid.Empty | 静态属性 | 返回空Guid |

使用举例:

import {Guid} from "@violet/core";

let guid= Guid.NewGuid();
let empty= Guid.Empty; 
//00000000-0000-0000-0000-000000000000
Task

Task 提供对Promise 的某些封装

| 方法名 | 参数 | 返回值 | 说明 | | :----------------: | :---------------------------------------------: | :------------: | :--------------------------: | | Task.Delay | millisecondDelay:number 等待时长 | Promise | 等待一段时间,替代 setTimeout | | Task.Delay | millisecondDelay:等待时长,cancelToken:取消token | Promise | 等待一段时间,替代 setTimeout | | Task.FromResult | data:T 返回数据 | Promise | 从结果返回一个任务 | | Task.CompletedTask | 无 | Promise | 返回一个R状态Promise | | Task.Run | Action:()=>void | Promise | 开启一个新任务 | | Task.Run | Func:()=>T | Promise | 开启一个新任务 | | Task.WaitAll | ...promise:Promise[] | Promise<any[]> | 等待所有Promise完成 |

CancellationToken

可取消Token

| 名称 | 类型 | 说明 | | ----------- | --------------------------- | ---------------- | | IsCancel | 只读属性 | 任务是否被取消 | | CancelEvent | Action[] 方法数组,只读属性 | 被取消时触发订阅 | | Cancel() | 方法,无参数 | 触发任务取消 |

CopyTextToClipboard

函数:将字符串拷贝到粘贴板中

CopyTextToClipboard(text:string)

IMenuItem

接口,字段定义如下:

| 名称 | 类型 | 说明 | | ------ | -------- | ------------ | | icon | string | 菜单图标 | | name | string | 菜单名称 | | action | ()=>void | 菜单事件委托 |

ResignMenu

函数:注册菜单显示

function ResignMenu(menu:IMenuItem[] , e:MouseEvent);

2. 异常处理类

Retry

函数支持,异步函数一定返回Promise对象,同步函数根据fn是否为异步返回对应结果

| 名称 | 参数 | 参数说明 | | -------- | ----------------------------- | ---- | | Retry | fn: () => T, maxRetry: number | fn:要执行的代码,maxRetry最大重试次数 | | Retry | fn:()=>any,maxRetry:number | fn:要执行的代码,maxRetry最大重试次数 | | Retry | fn: () => any, maxRetry: number, handler: (e: Error) => any | fn:执行代码,maxRetry最大重试次数,handler错误处理 | | RetryAsync | fn: () => T, maxRetry: number | fn:要执行的代码,maxRetry最大重试次数 | | RetryAsync | fn:()=>any,maxRetry:number | fn:要执行的代码,maxRetry最大重试次数 | | RetryAsync | fn: () => any, maxRetry: number, handler: (e: Error) => any | fn:执行代码,maxRetry最大重试次数,handler错误处理 |

Retryable装饰器

@Retryable(maxRetry: number, handler: Function) maxRetry最大重试次数,handler异常处理

export function Retryable(maxRetry: number, canThrow: boolean) mexRetry最大重试次数,canThrow是否抛出异常

TryCatch

函数支持,异步函数一定返回Promise对象,同步函数根据fn是否为异步返回对应结果

| 名称 | 参数 | 参数说明 | | ---------------- | --------------------------------------------- | ------------------------------ | | TryCatch | fn: () =>any | fn:要执行的代码 | | TryCatch | error: (e: Error) => any | fn:要执行的代码,error:异常处理 | | TryCatch | fn: () => T, error handler: (e: Error) => any | fn:执行代码,handler错误处理 | | TryCatch | fn: () => T, | fn:要执行的代码 | | TryCatchAsync | fn: () =>any | fn:要执行的代码 | | TryCatchAsync | error: (e: Error) => any | fn:要执行的代码,error:异常处理 | | TryCatchAsync | fn: () => T, error handler: (e: Error) => any | fn:执行代码,handler错误处理 | | TryCatchAsync | fn: () => T, | fn:要执行的代码 |

Tryable 装饰器

@Tryable(errorhandler: Function) errorhandler:异常处理

@Tryable(writeToConsole: boolean) writeToConsole是否记录异常到控制台

TimeOutAync

TimeOutAsync(fn: () => any, millisecond: number) fn执行在一定时间内