Skip to content

Commit

Permalink
Update code style in utils
Browse files Browse the repository at this point in the history
  • Loading branch information
dolfbarr committed Dec 1, 2022
1 parent 7bd3063 commit d9dab87
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { Printer, _PrintConfig, _PrintTypes, _SupportedConsole } from './types'

export function getCurrentDate(): string {
return new Date().toLocaleTimeString()
}

export function getGroupLabel(
type: _PrintTypes,
componentName?: string,
): string {
return `${String(type)} ${
componentName ? 'in %c<' + String(componentName) + ' /> ' : '%c'
}%c@ ${new Date().toLocaleTimeString()}`
const componentNameWrapper = componentName
? `in %c<${String(componentName)} /> `
: '%c'
const typeWrapper = `${String(type)} `
const dateWrapper = `%c@ ${getCurrentDate()}`

return `${typeWrapper}${componentNameWrapper}${dateWrapper}`
}

export function getComponentName(): string {
Expand Down Expand Up @@ -57,20 +65,21 @@ export function print<T>({
const getCurrentPrinter = (
method: keyof _SupportedConsole,
): _SupportedConsole[keyof _SupportedConsole] => getPrinter(printer, method)

const groupMethod = flags.isCollapsed ? 'groupCollapsed' : 'group'

if (flags.isGrouped) {
getCurrentPrinter(groupMethod)(group, componentCSS, subValueCSS)
}

if (!('prevValue' in arguments[0])) {
getCurrentPrinter('log')(`${label.padStart(14, ' ')}: ${String(value)}`)
} else {
if ('prevValue' in arguments[0]) {
getCurrentPrinter('log')(
`Previous value: %c${String(arguments[0].prevValue)}`,
subValueCSS,
)
getCurrentPrinter('log')(` Current value: %c${String(value)}`, changeCSS)
} else {
getCurrentPrinter('log')(`${label.padStart(14, ' ')}: ${String(value)}`)
}

if (flags.isGrouped) {
Expand Down

0 comments on commit d9dab87

Please sign in to comment.