Files
klz-cables.com/.pnpm-store/v10/files/d4/3d82938caabca623885ef02b60bad2b3814937cca4cba0779945d79132621735f5d16179d5a1cce4d1cf0a20f596fe4472ca23d89d2ea7dd1751ae5284075f
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

64 lines
2.1 KiB
Plaintext

'use strict'
module.exports = prettifyMessage
const {
LEVELS
} = require('../constants')
const getPropertyValue = require('./get-property-value')
const interpretConditionals = require('./interpret-conditionals')
/**
* @typedef {object} PrettifyMessageParams
* @property {object} log The log object with the message to colorize.
* @property {PrettyContext} context The context object built from parsing
* the options.
*/
/**
* Prettifies a message string if the given `log` has a message property.
*
* @param {PrettifyMessageParams} input
*
* @returns {undefined|string} If the message key is not found, or the message
* key is not a string, then `undefined` will be returned. Otherwise, a string
* that is the prettified message.
*/
function prettifyMessage ({ log, context }) {
const {
colorizer,
customLevels,
levelKey,
levelLabel,
messageFormat,
messageKey,
useOnlyCustomProps
} = context
if (messageFormat && typeof messageFormat === 'string') {
const parsedMessageFormat = interpretConditionals(messageFormat, log)
const message = String(parsedMessageFormat).replace(
/{([^{}]+)}/g,
function (match, p1) {
// return log level as string instead of int
let level
if (p1 === levelLabel && (level = getPropertyValue(log, levelKey)) !== undefined) {
const condition = useOnlyCustomProps ? customLevels === undefined : customLevels[level] === undefined
return condition ? LEVELS[level] : customLevels[level]
}
// Parse nested key access, e.g. `{keyA.subKeyB}`.
return getPropertyValue(log, p1) || ''
})
return colorizer.message(message)
}
if (messageFormat && typeof messageFormat === 'function') {
const msg = messageFormat(log, messageKey, levelLabel, { colors: colorizer.colors })
return colorizer.message(msg)
}
if (messageKey in log === false) return undefined
if (typeof log[messageKey] !== 'string' && typeof log[messageKey] !== 'number' && typeof log[messageKey] !== 'boolean') return undefined
return colorizer.message(log[messageKey])
}