Skip to content

Commit 83208f9

Browse files
committed
style: eslint fixes
1 parent ed14e52 commit 83208f9

File tree

8 files changed

+30
-24
lines changed

8 files changed

+30
-24
lines changed

src/components/DataTable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ export default defineComponent({
364364
lastPage,
365365
]
366366
}
367-
throw new Error('INVALID PAGE RANGE')
367+
throw new Error("INVALID PAGE RANGE")
368368
},
369369

370370
// ─────────────────────────────────────────────────────────────────────

src/demo/App.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export default {
132132

133133
methods: {
134134
updateUserField(user: User, field: UserField, value: any) {
135-
const ind = this.data.findIndex((u: any) => u.id === user.id)
135+
const ind = this.data.findIndex((u: User) => u.id === user.id)
136136
if (ind < 0) return
137137
const newUser = { ...this.data[ind] }
138138
newUser[field] = value
@@ -151,12 +151,12 @@ export default {
151151
this.showUser(user)
152152
break
153153
case "updateCell":
154-
const { key, value } = payload
155-
this.updateUserField(user, key, value)
154+
this.updateUserField(user, payload.key, payload.value)
156155
break
157156
case "select":
158-
const { selected } = payload
159-
this.updateSelection(user, selected)
157+
this.updateSelection(user, payload.selected)
158+
break
159+
default:
160160
}
161161
},
162162
addUser(user: User) {

src/demo/CellImage.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/>
77
</template>
88
<script>
9-
export default { name: "CellImage", props: ["data"] }
9+
export default { name: "CellImage", props: { data: Object } }
1010
</script>
1111
<style>
1212
.cell-img {

src/demo/CellList.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
</ul>
1010
</template>
1111
<script>
12-
export default { name: "CellList", props: ["data"] }
12+
export default { name: "CellList", props: { data: Object } }
1313
</script>

src/parser/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ export const globalDefaultColumn = {
1616
type: "string",
1717
} as Column
1818

19-
const type2searchFunction = {
20-
string: searchStringColumn as Function,
21-
numeric: searchNumericColumn as Function,
22-
} as Record<ColumnType, Function>
19+
const type2searchFunction: Partial<
20+
Record<ColumnType, Column["searchFunction"]>
21+
> = { string: searchStringColumn, numeric: searchNumericColumn }
2322

2423
export function parseColumnProps(props: any) {
2524
// extract the columns. If not set, columns are derived from columnKeys

src/types.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
export type VueComponent = string | any
55
export type VueComponentProps = { [key: string]: any }
66

7+
export type CompareFn = (a: any, b: any) => number
78
export type SortingMode = "asc" | "desc" | "none"
89
export type ColumnType = "numeric" | "string" | "array" | "other"
910
export type Column = {
10-
compareFunction: Function
11+
compareFunction: CompareFn
1112
component: VueComponent
1213
componentProps: VueComponentProps
1314
collapsed: boolean
@@ -17,7 +18,7 @@ export type Column = {
1718
key: string
1819
id: number
1920
searchable: boolean
20-
searchFunction: Function
21+
searchFunction: (data: Cell, search: string, key: string) => boolean
2122
sortable: boolean
2223
sortingIndex: number
2324
sortingMode: SortingMode

src/utils.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Cell, Column, Data } from "./types"
1+
import type { Cell, Column, CompareFn, Data } from "./types"
22

33
export 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

tests/utils.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
arraySafeSort,
55
safeCompare,
66
} from "../src/utils"
7+
import type { CompareFn } from "../src/types"
78

89
test("test string replacement", function () {
910
const str = "showing :first: to :last: entries of :total: rows"
@@ -16,8 +17,8 @@ test("test string replacement", function () {
1617
test("test safe sort", function () {
1718
let arr = [2, 45, null, 10, 20, null, 15]
1819
let res: (number | null)[]
19-
let f: Function = (a: any, b: any) => a - b
20-
let g: Function = (a: any, b: any) => b - a
20+
let f: CompareFn = (a: any, b: any) => a - b
21+
let g: CompareFn = (a: any, b: any) => b - a
2122
res = arraySafeSort(arr, f)
2223
expect(res).toEqual([2, 10, 15, 20, 45, null, null])
2324
res = arraySafeSort(arr, g)

0 commit comments

Comments
 (0)