[working] add grid filter
This commit is contained in:
@ -27,10 +27,30 @@ function throttle(method, delay = 100, context = g, ...args) {
|
||||
}
|
||||
}
|
||||
|
||||
function debounce(method, delay = 100, context = g, ...args) {
|
||||
if (method == null) {
|
||||
return;
|
||||
}
|
||||
method.tiid && clearTimeout(method.tiid);
|
||||
method.tiid = setTimeout(() => method.apply(context, args), delay);
|
||||
}
|
||||
|
||||
function truncate(v) {
|
||||
return (v > 0 ? Math.floor : Math.ceil)(v);
|
||||
}
|
||||
|
||||
function distinct(array, key, filter) {
|
||||
const dict = Object.create(null);
|
||||
for (let item of array) {
|
||||
const v = typeof filter === 'function' ? filter(item) : item[key];
|
||||
const val = v?.value ?? v;
|
||||
if (!Object.prototype.hasOwnProperty.call(dict, val)) {
|
||||
dict[val] = v;
|
||||
}
|
||||
}
|
||||
return Object.values(dict);
|
||||
}
|
||||
|
||||
function isEmail(text) {
|
||||
return /^\w[-\w.+]*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(text);
|
||||
}
|
||||
@ -65,7 +85,9 @@ export {
|
||||
isMobile,
|
||||
// functions
|
||||
throttle,
|
||||
debounce,
|
||||
truncate,
|
||||
distinct,
|
||||
isEmail,
|
||||
isPhone
|
||||
}
|
Reference in New Issue
Block a user