2021-01-27 07:26:31 +08:00
|
|
|
export const
|
|
|
|
isArray = Array.isArray,
|
2021-07-22 03:34:17 +08:00
|
|
|
arrayLength = array => isArray(array) && array.length,
|
2021-08-20 21:40:07 +08:00
|
|
|
isFunction = v => typeof v === 'function',
|
|
|
|
pString = value => null != value ? '' + value : '',
|
|
|
|
|
2021-11-01 18:24:11 +08:00
|
|
|
forEachObjectValue = (obj, fn) => Object.values(obj).forEach(fn),
|
|
|
|
|
2021-12-01 20:54:35 +08:00
|
|
|
forEachObjectEntry = (obj, fn) => Object.entries(obj).forEach(([key, value]) => fn(key, value)),
|
|
|
|
|
2021-08-20 21:40:07 +08:00
|
|
|
pInt = (value, defaultValue = 0) => {
|
|
|
|
value = parseInt(value, 10);
|
|
|
|
return isNaN(value) || !isFinite(value) ? defaultValue : value;
|
|
|
|
},
|
|
|
|
|
|
|
|
defaultOptionsAfterRender = (domItem, item) =>
|
2022-09-02 17:52:07 +08:00
|
|
|
item && undefined !== item.disabled && domItem?.classList.toggle('disabled', domItem.disabled = item.disabled),
|
2016-06-07 05:57:52 +08:00
|
|
|
|
2021-12-07 19:40:55 +08:00
|
|
|
// unescape(encodeURIComponent()) makes the UTF-16 DOMString to an UTF-8 string
|
2023-02-16 00:29:47 +08:00
|
|
|
b64Encode = data => btoa(unescape(encodeURIComponent(data))),
|
2021-12-07 19:40:55 +08:00
|
|
|
/* // Without deprecated 'unescape':
|
2023-02-16 00:29:47 +08:00
|
|
|
b64Encode = data => btoa(encodeURIComponent(data).replace(
|
2021-12-07 19:40:55 +08:00
|
|
|
/%([0-9A-F]{2})/g, (match, p1) => String.fromCharCode('0x' + p1)
|
2022-02-24 19:43:44 +08:00
|
|
|
)),
|
2021-12-07 19:40:55 +08:00
|
|
|
*/
|
2023-02-16 00:29:47 +08:00
|
|
|
|
|
|
|
b64EncodeJSON = data => b64Encode(JSON.stringify(data)),
|
|
|
|
|
2021-12-07 19:40:55 +08:00
|
|
|
b64EncodeJSONSafe = data => b64EncodeJSON(data).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''),
|
|
|
|
|
2021-10-21 23:15:00 +08:00
|
|
|
getKeyByValue = (o, v) => Object.keys(o).find(key => o[key] === v);
|