我想知道一种检查给定字符串ms()
格式是否正确而不是无效时间的方法。
const ms = require('ms')
const str = 'abc'
setTimeout(function(){
//Do something
}, ms(str))
目的是str
在功能超时开始之前检测有效或无效的MS时间。
根据消息来源,NaN
返回无效参数。因此,您可以执行以下操作:
const ms = require('ms');
const str = 'abc';
const msVal = ms(str);
if (!isNaN(msVal)) {
setTimeout(() => {
//Do something
}, msVal);
} else {
// handle invalid format
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句