const NULL_OR_UNDEFINED = Symbol("null_or_undefined")
const DATA_TYPE_MAP = {
NUMBER: "[object Number]",
STRING: "[object String]",
OBJECT: "[object Object]",
FUNCTION: "[object Function]",
ARRAY: "[object Array]",
MAP: "[object Map]",
SET: "[object Set]",
REGEXP: "[object Regexp]",
DATE: "[object Date]"
}
function isNullOrUndefined(data){
return (data ?? NULL_OR_UNDEFINED) === NULL_OR_UNDEFINED
}
function getType(data){
return Object.prototype.toString.call(data)
}
function isNumber(data){
return getType(data) === DATA_TYPE_MAP.NUMBER
}
function isString(data){
return getType(data) === DATA_TYPE_MAP.STRING
}
function isObject(data){
return getType(data) === DATA_TYPE_MAP.OBJECT
}
function isFunction(data){
return getType(data) === DATA_TYPE_MAP.FUNCTION
}
function isArray(data){
return getType(data) === DATA_TYPE_MAP.ARRAY
}
function extend(target = {}, source = {}){
return Object.assign({}, target, source)
}
function debounce(fn, gap=1){
let timer = null
fn = isFunction(fn) ? fn : function(){}
return function(){
timer && clearTimeout(timer)
timer = setTimeout(fn.bind(this), gap*1000)
}
}
function throttel(fn, gap=1){
let prevTime = 0
fn = isFunction(fn) ? fn : function(){}
return function(){
const curTime = Date.now()
const during = curTime - prevTime
if(during >= gap*1000){
prevTime = curTime
fn.call(this)
}
}
}
function setTimePrefix(time){
return String(time).padStart(2, "0")
}