axiodb
Version:
A blazing-fast, lightweight, and scalable nodejs package based DBMS for modern application. Supports schemas, encryption, and advanced query capabilities.
57 lines • 2.42 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable @typescript-eslint/no-explicit-any */
/**
* Class representing a sorting utility.
*/
class Sorting {
/**
* Create a Sorting instance.
* @param arr - The array to be sorted.
* @param query - The query object containing the sorting key and order.
*/
constructor(arr, query) {
this.arr = arr;
this.query = query;
}
/**
* Sort the array based on the query.
* @param arr - The array to be sorted.
* @param query - The query object containing the sorting key and order.
* @returns A promise that resolves to the sorted array.
*/
sort(aditionalField) {
return __awaiter(this, void 0, void 0, function* () {
const [key, order] = Object.entries(this.query)[0]; // Extract the field and order (1 for ascending, -1 for descending)
if (aditionalField) {
return [...this.arr].sort((a, b) => {
if (a[aditionalField][key] < b[aditionalField][key])
return -order; // Swap order
if (a[aditionalField][key] > b[aditionalField][key])
return order; // Swap order
return 0;
});
}
else {
return [...this.arr].sort((a, b) => {
if (a[key] < b[key])
return -order; // Swap order
if (a[key] > b[key])
return order; // Swap order
return 0;
});
}
});
}
}
exports.default = Sorting;
//# sourceMappingURL=SortData.utils.js.map