File tree Expand file tree Collapse file tree 2 files changed +15
-15
lines changed
src/advanced-filtering/src Expand file tree Collapse file tree 2 files changed +15
-15
lines changed Original file line number Diff line number Diff line change 1
- import { LogEntry , SimpleLogFilterCriteria , SortCriteria } from " ../types" ;
1
+ import { LogEntry , SimpleLogFilterCriteria , SortCriteria } from ' ../types' ;
2
2
3
- export function advancedSort < ItemType > (
3
+ export function advancedSort < ItemType extends object > (
4
4
arr : ItemType [ ] ,
5
5
criteria : SortCriteria < ItemType >
6
6
) : ItemType [ ] {
7
7
return [ ...arr ] . sort ( ( a , b ) => {
8
8
for ( const key in criteria ) {
9
- const { direction, customCompare} = criteria [ key ] || { } ;
9
+ const { direction, customCompare } = criteria [ key ] || { } ;
10
10
if ( a [ key ] !== b [ key ] ) {
11
11
let comparison : number ;
12
12
if ( customCompare ) {
13
13
comparison = customCompare ( a [ key ] , b [ key ] ) ;
14
14
} else {
15
15
comparison = a [ key ] < b [ key ] ? - 1 : 1 ;
16
16
}
17
- return direction === " desc" ? - comparison : comparison ;
17
+ return direction === ' desc' ? - comparison : comparison ;
18
18
}
19
19
}
20
20
return 0 ;
@@ -35,7 +35,7 @@ export function simpleLogFilter(
35
35
return true ;
36
36
}
37
37
const value = log [ key ] ;
38
- if ( typeof condition === " function" ) {
38
+ if ( typeof condition === ' function' ) {
39
39
return ( condition as ( value : any ) => boolean ) ( value ) ;
40
40
}
41
41
return value === condition ;
Original file line number Diff line number Diff line change 1
- export type LogLevel = " INFO" | " WARNING" | " ERROR" ;
1
+ export type LogLevel = ' INFO' | ' WARNING' | ' ERROR' ;
2
2
export type LogSource =
3
- | " user-service"
4
- | " auth-service"
5
- | " payment-service"
6
- | " notification-service"
7
- | " api-gateway" ;
3
+ | ' user-service'
4
+ | ' auth-service'
5
+ | ' payment-service'
6
+ | ' notification-service'
7
+ | ' api-gateway' ;
8
8
9
9
export interface LogEntry {
10
10
timestamp : Date ;
@@ -19,9 +19,9 @@ export type CompareFunction<ItemTypeValue> = (
19
19
b : ItemTypeValue
20
20
) => number ;
21
21
22
- export type SortCriteria < ItemType > = {
22
+ export type SortCriteria < ItemType extends object > = {
23
23
[ Key in keyof ItemType ] ?: {
24
- direction : " asc" | " desc" ;
24
+ direction : ' asc' | ' desc' ;
25
25
customCompare ?: CompareFunction < ItemType [ Key ] > ;
26
26
} ;
27
27
} ;
@@ -31,11 +31,11 @@ export type SimpleLogFilterCriteria = {
31
31
source ?: LogSource | ( ( value : LogSource ) => boolean ) ;
32
32
} ;
33
33
34
- export type SimpleLogFilterKey = " level" | " source" ;
34
+ export type SimpleLogFilterKey = ' level' | ' source' ;
35
35
36
36
export type SimpleFilterableLogValue = LogLevel | LogSource ;
37
37
38
38
export type UpdateLogFilterFunction = (
39
39
key : SimpleLogFilterKey ,
40
- value : SimpleFilterableLogValue | ""
40
+ value : SimpleFilterableLogValue | ''
41
41
) => void ;
You can’t perform that action at this time.
0 commit comments