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 🙏

© 2025 – Pkg Stats / Ryan Hefner

luban-box

v1.0.2

Published

task retry util

Downloads

7

Readme

安装

npm install luban-box

引入

import { task, encrypts, date, number } from "luban-box";

用例

/**
 * 任务队列,常规调用
 */
new task.Task({
	run() {
		//具体的任务代码,这里的count为Task的内部属性:执行次数;
		console.log("run 1 ", this.count);

		return {
			success: this.count >= 3,//返回成功失败的标志
		};
	},
	delay: 1000, //延迟多少ms执行
	retry: 5, //失败时重试的次数
	interval: 2000 //两次执行的间隔ms
})

/**
 * 任务队列,promise形式的调用
 */
new task.Task({
	async run() {
		//具体的任务代码,这里的count为Task的内部属性:执行次数;
		console.log("run 2 ", this.count);
		return {
			success: this.count >= 3,//返回成功失败的标志
			data: "task 2 " + this.count
		};
	},
	delay: 1000,
	retry: 5,
	interval: 2000
}).then((data) => {
	//处理run 1返回的数据data
	console.log("result 2", data);

	//如果有第二个任务,则创建第二个任务
	return new task.Task({
		async run() {
			console.log("run 3 ", this.count);
			return {
				success: this.count >= 2,
				data: "task 3 " + this.count
			};
		},
		delay: 1000,
		retry: 5,
		interval: 2000
	})
}).then((data) => {
	//处理run 2返回的数据data
	console.log("result 3 ", data);
});

// 加密(增加数据时效性)示例,加密后会给参数增加一个checkcode,加密后默认20s有效时间
let salt = "abc"
let params = {
	name: "lili",
	age: 20
}
encrypts.encrypt(params, salt)
console.assert(encrypts.isDecryptPassed(params, salt) == true, "加密验证失败")
setTimeout(() => {
	// 超过20秒后验证失败
	console.assert(encrypts.isDecryptPassed(params, salt) == false, "加密验证超时后失败")
}, 21000)

//时间格式化
console.log(date.format(new Date("2022-10-14T02:34:43.000Z")));
//时间加减日月年
console.assert(date.offset(new Date("2022-10-14T02:34:43.000Z"), 20, 2, 1).toISOString() == "2024-01-03T02:34:43.000Z", "时间加减日月年");

//保留小数
console.assert(number.carry(10.5555, 2) == 10.56, "保留小数错误", number.carry(10.5555, 2));
console.assert(number.carry(10.5555, 2, Math.floor) == 10.55, "保留小数错误", number.carry(10.5555, 2, Math.floor));
//数值使用英文进位,比如:1000 ==》 1k
console.assert(number.scientific(20.21) == '20', "数值使用英文进位1");
console.assert(number.scientific(1000) == '1K', "数值使用英文进位2");
console.assert(number.scientific(561235.1566) == '561K', "数值使用英文进位3");
console.assert(number.scientific(5946151.5555, 2, Math.floor) == '5.94M', "数值使用英文进位4");