
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
@ionepub/node-timer
Advanced tools
本插件目的在于方便在nodejs中使用秒级的倒计时。
js版参见:https://github.com/ionepub/js-timer
npm i @ionepub/node-timer --save
var Timer = require('@ionepub/node-timer');
Timer.run(function(day, hour, minute, second, is_end){
console.log(day+'d', hour+'h', minute+'m', second+'s', is_end);
if(is_end){
console.log("已结束");
}
});
插件有4个配置项:
string字符串,返回的数字格式为两位字符,如09;可选值int,返回整数,如9true,可选值falsetrue,可选值false需要注意的是,即使withHour或withDay设置为false,在回调函数的返回值中,依然会返回day和hour参数,但是参数值始终为零(即不计算)。
自定义配置的几个方法:
// 使用默认配置
Timer.init();
// 倒计时30秒
Timer.init({time:30});
// 其他例子
Timer.init({time:30, format: 'int', withHour: true, withDay: false});
Timer.settings.time = 30;
Timer.settings.withDay = false;
Timer.run()方法的第一个参数也支持自定义配置
// 使用默认配置
Timer.run();
// 倒计时30秒
Timer.run({time:30});
// 其他例子
Timer.run({time:30, format: 'int', withHour: true, withDay: false});
Timer.run({time:30, format: 'int', withHour: true, withDay: false}, function(day, hour, minute, second, is_end){
console.log(day+'d', hour+'h', minute+'m', second+'s', is_end);
if(is_end){
console.log("已结束");
}
});
Timer.run()方法支持1-2个参数,第一个参数为配置项对象或回调方法;当第一个参数为配置项时,第二个参数为回调方法。
// 使用默认配置
Timer.run(function(day, hour, minute, second, is_end){
console.log(day+'d', hour+'h', minute+'m', second+'s', is_end);
if(is_end){
console.log("已结束");
}
});
// 无回调
Timer.run({time:30, format: 'int', withHour: true, withDay: false});
// 自定义配置和回调
Timer.run({time:30, format: 'int', withHour: true, withDay: false}, function(day, hour, minute, second, is_end){
console.log(day+'d', hour+'h', minute+'m', second+'s', is_end);
if(is_end){
console.log("已结束");
}
});
为了更方便使用,插件提供了diff()方法,支持填入开始时间(秒)和结束时间参数,以此设置倒计时瞄数。
diff()方法必须传递两个整数,且startTime必须小于endTime。
Timer.diff(1516676419, 1516676457);
Timer.diff(0, 30).run(function(day, hour, minute, second, is_end){
console.log(day+'d', hour+'h', minute+'m', second+'s', is_end);
});
插件的init()、run()和diff()方法均支持链式调用,但是需要注意一下调用顺序。
init()或者diff()在run()之后,这个方法的设置是无效的Timer.init().run(function(day, hour, minute, second, is_end){
console.log(day+'d', hour+'h', minute+'m', second+'s', is_end);
});
Timer.init({time:30}).run(function(day, hour, minute, second, is_end){
console.log(day+'d', hour+'h', minute+'m', second+'s', is_end);
});
Timer.diff(0, 30).run(function(day, hour, minute, second, is_end){
console.log(day+'d', hour+'h', minute+'m', second+'s', is_end);
});
分步调用也是可以的:
// 倒计时30秒
Timer.init({time:30});
Timer.run(function(day, hour, minute, second, is_end){
console.log(day+'d', hour+'h', minute+'m', second+'s', is_end);
});
// 倒计时40秒
Timer.diff(0, 40);
Timer.run(function(day, hour, minute, second, is_end){
console.log(day+'d', hour+'h', minute+'m', second+'s', is_end);
});
插件支持在同一页面中有多个倒计时,例如:
Timer.diff(0,10).run(function(day, hour, minute, second, is_end){
console.log(day+'d', hour+'h', minute+'m', second+'s', is_end);
if(is_end){
console.log("已结束");
}
})
Timer.diff(0,5).run(function(day, hour, minute, second, is_end){
console.log(day+'d', hour+'h', minute+'m', second+'s', is_end);
if(is_end){
console.log("已结束");
}
})
FAQs
A simple countdown timer module.
We found that @ionepub/node-timer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.