t-comm
Version:
专业、稳定、纯粹的工具库
47 lines (43 loc) • 1.21 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var clickCount = 0;
var simpleMorseTimer;
/**
* 简单的摩斯密码,只有点击
* @param param {object} 参数
*
* @example
* ```ts
* simpleMorse({
* target: 5, // 目标值
* callback: () => console.log('test'),
* timeout: 300, // 超时取消
* debug: false,
* })
* ```
*/
function simpleMorse(_ref) {
var _ref$target = _ref.target,
target = _ref$target === void 0 ? 5 : _ref$target,
_ref$callback = _ref.callback,
callback = _ref$callback === void 0 ? function () {
console.log('[Simple Morse]');
} : _ref$callback,
_ref$timeout = _ref.timeout,
timeout = _ref$timeout === void 0 ? 300 : _ref$timeout,
_ref$debug = _ref.debug,
debug = _ref$debug === void 0 ? false : _ref$debug;
clickCount = clickCount + 1;
clearTimeout(simpleMorseTimer);
if (debug) {
console.log('[simpleMorse: clickCount]', clickCount);
}
if (clickCount >= target) {
callback === null || callback === void 0 ? void 0 : callback();
clickCount = 0;
}
simpleMorseTimer = setTimeout(function () {
clickCount = 0;
}, timeout);
}
exports.simpleMorse = simpleMorse;