Move sort functions for freedata.js for use elsewhere, add a sort desc function as well.

This commit is contained in:
Mashintime 2023-11-03 21:50:28 -04:00
parent 39b28884bf
commit 7eb65dd91e
2 changed files with 20 additions and 11 deletions

View file

@ -20,7 +20,7 @@ import { sendMessage, sendBroadcastChannel } from "./sock.js";
import { displayToast } from "./popupHandler.js"; import { displayToast } from "./popupHandler.js";
//const FD = require("./src/js/freedata.js"); //const FD = require("./src/js/freedata.js");
import { btoa_FD } from "./freedata.js"; import { btoa_FD,sortByProperty } from "./freedata.js";
// define default message object // define default message object
interface Attachment { interface Attachment {
@ -279,16 +279,6 @@ function sortChatList() {
return reorderedData; return reorderedData;
} }
//https://medium.com/@asadise/sorting-a-json-array-according-one-property-in-javascript-18b1d22cd9e9
function sortByProperty(property) {
return function (a, b) {
if (a[property] > b[property]) return 1;
else if (a[property] < b[property]) return -1;
return 0;
};
}
export function getMessageAttachment(id) { export function getMessageAttachment(id) {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
try { try {

View file

@ -25,3 +25,22 @@ export function atob(data) {
//exports.atob = function (data) { //exports.atob = function (data) {
return window.btoa(Buffer.from(data, "base64").toString("utf8")); return window.btoa(Buffer.from(data, "base64").toString("utf8"));
} }
//https://medium.com/@asadise/sorting-a-json-array-according-one-property-in-javascript-18b1d22cd9e9
export function sortByProperty(property) {
return function (a, b) {
if (a[property] > b[property]) return 1;
else if (a[property] < b[property]) return -1;
return 0;
};
}
//https://medium.com/@asadise/sorting-a-json-array-according-one-property-in-javascript-18b1d22cd9e9
export function sortByPropertyDesc(property) {
return function (a, b) {
if (a[property] < b[property]) return 1;
else if (a[property] > b[property]) return -1;
return 0;
};
}