Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: consider replacing any usage of any with unknown #59
- Loading branch information
Showing
18 changed files
with
131 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,3 +71,4 @@ typings/ | |
# stryker temp files | ||
.stryker-tmp | ||
/reports | ||
!@types/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ConsolaLogObject, ConsolaReporter, ConsolaReporterArgs } from 'consola'; | ||
import { InspectOptions } from 'util'; | ||
import { ForegroundColor } from 'chalk'; | ||
|
||
declare module 'consola' { | ||
type Color = typeof ForegroundColor; | ||
|
||
export interface ReporterOptions { | ||
dateFormat?: string; | ||
formatOptions?: InspectOptions; | ||
secondaryColor?: Color; | ||
} | ||
|
||
export class FancyReporter implements ConsolaReporter { | ||
protected options: ReporterOptions; | ||
|
||
constructor(options?: ReporterOptions); | ||
|
||
public log(logObj: ConsolaLogObject, args: ConsolaReporterArgs): void; | ||
|
||
protected formatType(logObj: ConsolaLogObject): string; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,59 @@ | ||
// @ts-ignore | ||
import { ConsolaLogObject, ConsolaReporter, ConsolaReporterArgs, FancyReporter } from 'consola'; | ||
import { ConsolaLogObject, ConsolaReporter, FancyReporter, ReporterOptions } from 'consola'; | ||
import chalk = require('chalk'); | ||
import * as figures from 'figures'; | ||
import type { Chalk, BackgroundColor, ForegroundColor } from 'chalk'; | ||
import { Nullable } from 'Union/Nullable'; | ||
import { isNumber } from 'ts-type-guards'; | ||
|
||
const bgColorCache: any = {}; | ||
const bgColorCache: Record<string, Chalk> = {}; | ||
|
||
const chalkBgColor = (name: string): any => { | ||
let color = bgColorCache[name]; | ||
if (color) { | ||
return color; | ||
const chalkBgColor = (name: BGColor): Chalk => { | ||
if (!bgColorCache[name]) { | ||
bgColorCache[name] = chalk[name]; | ||
} | ||
// @ts-ignore | ||
color = chalk[`bg${name[0].toUpperCase()}${name.slice(1)}`]; | ||
bgColorCache[name] = color; | ||
return color; | ||
return bgColorCache[name]; | ||
}; | ||
|
||
const LEVEL_COLOR_MAP = { | ||
0: `red`, | ||
1: `yellow`, | ||
2: `white`, | ||
3: `green`, | ||
const LEVEL_COLOR_MAP: Record<number, Nullable<BGColor>> = { | ||
0: `bgRed`, | ||
1: `bgYellow`, | ||
2: `bgWhite`, | ||
3: `bgGreen`, | ||
}; | ||
|
||
const TYPE_COLOR_MAP = { | ||
info: `blue`, | ||
const TYPE_COLOR_MAP: Record<string, Nullable<BGColor>> = { | ||
info: `bgBlue`, | ||
}; | ||
|
||
const TYPE_ICONS = { | ||
const TYPE_ICONS: Record<string, Nullable<string>> = { | ||
info: figures(`ℹ`), | ||
success: figures(`✔`), | ||
error: figures(`✖`), | ||
warn: figures(`Ⓘ`), | ||
}; | ||
|
||
export type BGColor = typeof BackgroundColor; | ||
export type Color = typeof ForegroundColor; | ||
|
||
export interface LogReporterOptions extends ReporterOptions { | ||
secondaryColor: Color; | ||
bgColor: BGColor; | ||
} | ||
|
||
export class LogReporter extends FancyReporter implements ConsolaReporter { | ||
constructor(options?: any) { | ||
private bgColor: BGColor; | ||
constructor(options: LogReporterOptions) { | ||
super(options); | ||
this.bgColor = options.bgColor; | ||
} | ||
|
||
protected formatType(logObj: any): string { | ||
// @ts-ignore | ||
const typeColor = TYPE_COLOR_MAP[logObj.type] || LEVEL_COLOR_MAP[logObj.level] || this.options.secondaryColor; | ||
// @ts-ignore | ||
const typeIcon = TYPE_ICONS[logObj.type]; | ||
const text = ` ${typeIcon || logObj.type.toUpperCase()} `; | ||
protected formatType(logObj: ConsolaLogObject): string { | ||
const typeColor = | ||
(logObj.type && TYPE_COLOR_MAP[logObj.type]) || | ||
(isNumber(logObj.level) && LEVEL_COLOR_MAP[logObj.level]) || | ||
this.bgColor; | ||
const typeIcon = logObj.type && TYPE_ICONS[logObj.type]; | ||
const text = ` ${typeIcon || (logObj.type && logObj.type.toUpperCase())} `; | ||
return chalkBgColor(typeColor).black(text); | ||
} | ||
|
||
public log(logObj: ConsolaLogObject, args: ConsolaReporterArgs): void { | ||
super.log(logObj, args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { isNumber, isString } from 'ts-type-guards'; | ||
import { StringOrNumber } from './types'; | ||
|
||
export const isStringOrNumber = (x: any): x is StringOrNumber => { | ||
export const isStringOrNumber = (x: unknown): x is StringOrNumber => { | ||
return isString(x) || isNumber(x); | ||
}; |
Oops, something went wrong.