Skip to content

Commit a956bcb

Browse files
authored
perf(lib): replace redundant reduce call on array (#59)
1 parent dd7c51e commit a956bcb

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

benchmark/format-message.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
const benchmark = require('benchmark')
44
const messageFormatFactory = require('../lib/messageFormatFactory')
55

6-
const formatMessageColorized = messageFormatFactory(true)
6+
const colors = {
7+
60: 'red',
8+
50: 'red',
9+
40: 'yellow',
10+
30: 'green',
11+
20: 'blue',
12+
10: 'cyan'
13+
}
14+
const formatMessageColorized = messageFormatFactory(true, colors, true)
715
const log = {
816
time: Date.now(),
917
level: 30,

lib/messageFormatFactory.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ const formatDate = require('./formatDate')
33
const colorizerFactory = require('pino-pretty').colorizerFactory
44

55
const messageFormatFactory = (levels, colors, useColors) => {
6-
const customColors =
7-
colors != null
8-
? Object.entries(colors).reduce((colors, [level, color]) => {
9-
return [...colors, [level, color]]
10-
}, [])
11-
: undefined
6+
let customColors
7+
if (colors != null) {
8+
customColors = Object.entries(colors)
9+
}
1210
const colorizer = colorizerFactory(useColors, customColors)
1311

1412
const levelLookUp = {

0 commit comments

Comments
 (0)