1- import type { Cell , Column , Data } from "./types"
1+ import type { Cell , Column , CompareFn , Data } from "./types"
22
33export function toTitleCase ( str : string ) : string {
44 // convert snake case to title case
@@ -41,15 +41,15 @@ export function isNullable(variable: any): boolean {
4141 return variable === null || variable === "" || variable === undefined
4242}
4343
44- export function stableSort < T > ( arr : T [ ] , compare : Function ) : T [ ] {
44+ export function stableSort < T > ( arr : T [ ] , compare : CompareFn ) : T [ ] {
4545 return arr
4646 . map ( ( item , index ) => ( { item, index } ) )
4747 . sort ( ( a , b ) => compare ( a . item , b . item ) || a . index - b . index )
4848 . map ( ( { item } ) => item )
4949}
5050
5151// Safely compare two items, which may be nullable
52- export function safeCompare ( compareFunction : Function ) : Function {
52+ export function safeCompare ( compareFunction : CompareFn ) : CompareFn {
5353 return function ( a : any , b : any ) {
5454 if ( isNullable ( a ) ) return 1
5555 if ( isNullable ( b ) ) return - 1
@@ -58,7 +58,7 @@ export function safeCompare(compareFunction: Function): Function {
5858}
5959
6060// Safely compare two items by key, which may be nullable
61- export function safeKeyCompare ( compareFunction : Function , key : string ) {
61+ export function safeKeyCompare ( compareFunction : CompareFn , key : string ) {
6262 return function ( a : any , b : any ) {
6363 if ( isNullable ( a [ key ] ) ) return 1
6464 if ( isNullable ( b [ key ] ) ) return - 1
@@ -67,7 +67,7 @@ export function safeKeyCompare(compareFunction: Function, key: string) {
6767}
6868
6969// Reverse a comparison function
70- export function reverseCompare ( compareFunction : Function ) : Function {
70+ export function reverseCompare ( compareFunction : CompareFn ) : CompareFn {
7171 return ( a : any , b : any ) => compareFunction ( b , a )
7272}
7373
@@ -82,7 +82,7 @@ export function compareNumbers(a: string | number, b: string | number): number {
8282}
8383
8484// Safely stable sort an array that may have null elements
85- export function arraySafeSort < T > ( array : T [ ] , compareFunction : Function ) : T [ ] {
85+ export function arraySafeSort < T > ( array : T [ ] , compareFunction : CompareFn ) : T [ ] {
8686 return stableSort ( array , safeCompare ( compareFunction ) )
8787}
8888
@@ -94,7 +94,8 @@ export function sortDataByColumns(data: Data, columns: Column[]): Data {
9494 let i = 0
9595 while ( i < l ) {
9696 const c = columns [ i ]
97- let { sortingMode, compareFunction : f } = c
97+ const { sortingMode, compareFunction } = c
98+ let f = compareFunction
9899
99100 // reverse comparison
100101 const reverseSearch = sortingMode === "desc"
@@ -141,7 +142,11 @@ export function getEventTargetValue(event: any = null) {
141142}
142143
143144// Performs search on strings
144- export function searchStringColumn ( data : Cell , search : string , key : string ) {
145+ export function searchStringColumn (
146+ data : Cell ,
147+ search : string ,
148+ key : string
149+ ) : boolean {
145150 return ( data [ key ] || "" ) . toLowerCase ( ) . includes ( search . toLowerCase ( ) )
146151}
147152
0 commit comments