UNPKG

2.32 kBTypeScriptView Raw
1// Type definitions for redux-logger 3.0
2// Project: https://github.com/theaqua/redux-logger
3// Definitions by: Alexander Rusakov <https://github.com/arusakov>
4// Kevin Groat <https://github.com/kgroat>
5// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
6
7export as namespace ReduxLogger;
8
9import * as Redux from 'redux';
10
11export const logger: Redux.Middleware;
12
13export type LoggerPredicate = (
14 getState: () => any,
15 action: any,
16 logEntry?: LogEntryObject
17) => boolean;
18
19export type StateToString = (state: any) => string;
20export type ActionToString = (action: any) => string;
21export type ErrorToString = (error: any, prevState: any) => string;
22
23export interface ColorsObject {
24 title?: boolean | ActionToString | undefined;
25 prevState?: boolean | StateToString | undefined;
26 action?: boolean | ActionToString | undefined;
27 nextState?: boolean | StateToString | undefined;
28 error?: boolean | ErrorToString | undefined;
29}
30
31export interface LevelObject {
32 prevState?: string | boolean | StateToString | undefined;
33 action?: string | boolean | ActionToString | undefined;
34 nextState?: string | boolean | StateToString | undefined;
35 error?: string | boolean | ErrorToString | undefined;
36}
37
38export interface LogEntryObject {
39 action?: string | boolean | ActionToString | undefined;
40 started?: number | undefined;
41 startedTime?: Date | undefined;
42 took?: number | undefined;
43 error?(error: any): any;
44 nextState?(state: any): any;
45 prevState?(state: any): any;
46}
47
48export interface ReduxLoggerOptions {
49 level?: string | ActionToString | LevelObject | undefined;
50 duration?: boolean | undefined;
51 timestamp?: boolean | undefined;
52 colors?: ColorsObject | false | undefined;
53 titleFormatter?(formattedAction: any, formattedTime: string, took: number): string;
54 logger?: any;
55 logErrors?: boolean | undefined;
56 collapsed?: boolean | LoggerPredicate | undefined;
57 predicate?: LoggerPredicate | undefined;
58 diff?: boolean | undefined;
59 diffPredicate?: LoggerPredicate | undefined;
60 stateTransformer?(state: any): any;
61 actionTransformer?(action: any): any;
62 errorTransformer?(error: any): any;
63}
64
65export function createLogger(options?: ReduxLoggerOptions): Redux.Middleware;
66
67export default logger;