Skip to content

Commit

Permalink
perf(lib): replace redundant reduce call on array (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs authored Jan 10, 2025
1 parent dd7c51e commit a956bcb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 9 additions & 1 deletion benchmark/format-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
const benchmark = require('benchmark')
const messageFormatFactory = require('../lib/messageFormatFactory')

const formatMessageColorized = messageFormatFactory(true)
const colors = {
60: 'red',
50: 'red',
40: 'yellow',
30: 'green',
20: 'blue',
10: 'cyan'
}
const formatMessageColorized = messageFormatFactory(true, colors, true)
const log = {
time: Date.now(),
level: 30,
Expand Down
10 changes: 4 additions & 6 deletions lib/messageFormatFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ const formatDate = require('./formatDate')
const colorizerFactory = require('pino-pretty').colorizerFactory

const messageFormatFactory = (levels, colors, useColors) => {
const customColors =
colors != null
? Object.entries(colors).reduce((colors, [level, color]) => {
return [...colors, [level, color]]
}, [])
: undefined
let customColors
if (colors != null) {
customColors = Object.entries(colors)
}
const colorizer = colorizerFactory(useColors, customColors)

const levelLookUp = {
Expand Down

0 comments on commit a956bcb

Please sign in to comment.