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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ry0513/utils

v0.0.4

Published

personal utils

Downloads

408

Readme

个人使用的小工具箱

安装

npm i @ry0513/utils
# 或者
pnpm i @ry0513/utils

方法

extName

用于获取文件扩展名

类型

extName(path: string, withDot?: boolean): string

例子

import { extName } from "@ry0513/utils";
console.log(extName("/path/AAA00.jpg")); // jpg
console.log(extName("/path/AAA00.jpg", true)); // .jpg

baseName

用于获取文件名

类型

baseName(path: string, ext?: boolean): string

例子

import { baseName } from "@ry0513/utils";
console.log(baseName("/path/AAA00.jpg")); // AAA00
console.log(baseName("/path/AAA00.jpg", true)); // AAA00.jpg

Worker

用于 Web Worker 的连接池,创建实例时不会创建线程;当有新任务加入时会检测存在的线程数,若线程数不超过最大时则会创建新的线程并执行该任务,否则会加入任务队列等待执行;当一个线程完成任务时会检测任务队列,若队列不为空时会按顺序取出下一个任务继续执行(复用该线程),若队列为空则会自动终止

类型

new Worker(path: string | URL, options?:WorkerPoolsOptions)

type WorkerPoolsOptions = {
    maxWorkers?: number;
    credentials?: WorkerOptions["credentials"];
    type?: WorkerOptions["type"];
};

例子

import { Worker } from "@ry0513/utils";
// 假设 worker.js 计算文件MD5的并返回
const pools = new Worker("./worker.js", {
  maxWorkers: 8,
  type: "module",
});
// vite 需要 new URL() 导入
// https://cn.vitejs.dev/guide/features.html#web-workers
// const pools = new Worker(new URL("./worker", import.meta.url), {
//  maxWorkers: 8,
//  type: "module"
//});
// 假设 fileList 等待计算的文件列表
fileList.map(async (file) => {
  try {
    file.MD5 = await pools.addTask(file);
  } catch (error) {
    file.MD5 = null;
    console.error(error);
  }
});

// pools.terminateAll(); // 若有需要,可以直接终止全部线程