UNPKG

tedb

Version:

TypeScript Embedded Database

35 lines (34 loc) 1.3 kB
/** * Get the type of element that will be sorted as `[object ${TYPE}]` * * Examples: * ~~~ * getSortType([{a: 1}], "a"); // [object Number] * getSortType([{a: "b"}], "a"); // [object String] * getSortType([{a: new Date()}], "a"); // [object Date] * getSortType([{a: []}], "a"); // [object Array] * getSortType([{a: {}}], "a"); // [object Object] * ~~~ * @param arr - Array to check for type, will not send back a type if null or undefined * @param field - field name to check against * @returns {string} */ export declare const getSortType: (arr: any[], field: string) => string; /** * Sort array of documents using MergeSort * * Examples: * ~~~ * let docs = [{n: 1}, {n: 6}, {n: 5}]; * let sort = {n: -1}; * let key = Object.keys(sort)[0]; // "n" * let val = sort[key]; // -1 * let type = getSortType(docs, key); // "[object Number]" * mergeSort(docs, key, val, type); // [{n: 6}, {n: 5}, {n: 1}] * ~~~ * @param toSort - array of documents to sort * @param sortField - field name as string from documents * @param sortParam - numeric -1 for descending and 1 for ascending sort order * @param type - one of the results of Object.prototype.toString.call(obj[field]) */ export declare const mergeSort: (toSort: any[], sortField: string, sortParam: number, type: any) => any;