2021-09-04 16:07:38 +02:00
|
|
|
export function sortByValue(object: any) {
|
2018-02-21 21:58:28 +02:00
|
|
|
const temp = [];
|
2020-03-14 01:46:14 +02:00
|
|
|
for (const k in object) {
|
2018-02-21 21:58:28 +02:00
|
|
|
if (!object.hasOwnProperty(k)) continue;
|
|
|
|
temp.push({
|
|
|
|
key: k,
|
|
|
|
value: object[k],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
temp.sort(function(a, b) {
|
|
|
|
let v1 = a.value;
|
|
|
|
let v2 = b.value;
|
2018-03-09 22:59:12 +02:00
|
|
|
if (typeof v1 === 'string') v1 = v1.toLowerCase();
|
|
|
|
if (typeof v2 === 'string') v2 = v2.toLowerCase();
|
2018-02-21 21:58:28 +02:00
|
|
|
if (v1 === v2) return 0;
|
|
|
|
return v1 < v2 ? -1 : +1;
|
|
|
|
});
|
|
|
|
|
2021-09-04 16:07:38 +02:00
|
|
|
const output: any = {};
|
2018-02-21 21:58:28 +02:00
|
|
|
for (let i = 0; i < temp.length; i++) {
|
|
|
|
const item = temp[i];
|
|
|
|
output[item.key] = item.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
2021-09-04 16:07:38 +02:00
|
|
|
}
|
2018-02-21 21:58:28 +02:00
|
|
|
|
2021-09-04 16:07:38 +02:00
|
|
|
export function fieldsEqual(o1: any, o2: any) {
|
2019-07-29 15:43:53 +02:00
|
|
|
if ((!o1 || !o2) && o1 !== o2) return false;
|
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
for (const k in o1) {
|
2018-02-25 19:01:16 +02:00
|
|
|
if (!o1.hasOwnProperty(k)) continue;
|
|
|
|
if (o1[k] !== o2[k]) return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const c1 = Object.getOwnPropertyNames(o1);
|
|
|
|
const c2 = Object.getOwnPropertyNames(o2);
|
|
|
|
|
|
|
|
if (c1.length !== c2.length) return false;
|
|
|
|
|
|
|
|
return true;
|
2021-09-04 16:07:38 +02:00
|
|
|
}
|
2018-02-25 19:01:16 +02:00
|
|
|
|
2021-09-04 16:07:38 +02:00
|
|
|
export function convertValuesToFunctions(o: any) {
|
|
|
|
const output: any = {};
|
2020-03-14 01:46:14 +02:00
|
|
|
for (const n in o) {
|
2018-03-15 19:57:11 +02:00
|
|
|
if (!o.hasOwnProperty(n)) continue;
|
2019-07-29 15:43:53 +02:00
|
|
|
output[n] = () => {
|
|
|
|
return typeof o[n] === 'function' ? o[n]() : o[n];
|
|
|
|
};
|
2018-03-15 19:57:11 +02:00
|
|
|
}
|
|
|
|
return output;
|
2021-09-04 16:07:38 +02:00
|
|
|
}
|
2018-03-15 19:57:11 +02:00
|
|
|
|
2021-09-04 16:07:38 +02:00
|
|
|
export function isEmpty(o: any) {
|
2018-03-20 01:04:48 +02:00
|
|
|
if (!o) return true;
|
|
|
|
return Object.keys(o).length === 0 && o.constructor === Object;
|
2021-09-04 16:07:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// export function isStringifiable(o:any):boolean {
|
|
|
|
// if (o === null || o === undefined) return true;
|
|
|
|
|
|
|
|
// if (Array.isArray(o)) {
|
|
|
|
// for (const e of o) {
|
|
|
|
// if (!isStringifiable(e)) return false;
|
|
|
|
// }
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (typeof o === 'object') {
|
|
|
|
|
|
|
|
// }
|
2018-03-20 01:04:48 +02:00
|
|
|
|
2021-09-04 16:07:38 +02:00
|
|
|
// return true;
|
|
|
|
// }
|