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
69 lines
2.3 KiB
Plaintext
69 lines
2.3 KiB
Plaintext
import { isPrimitive } from '../utils/is.js';
|
|
import { normalize } from '../utils/normalize.js';
|
|
import { GLOBAL_OBJ } from '../utils/worldwide.js';
|
|
|
|
/**
|
|
* Formats the given values into a string.
|
|
*
|
|
* @param values - The values to format.
|
|
* @param normalizeDepth - The depth to normalize the values.
|
|
* @param normalizeMaxBreadth - The max breadth to normalize the values.
|
|
* @returns The formatted string.
|
|
*/
|
|
function formatConsoleArgs(values, normalizeDepth, normalizeMaxBreadth) {
|
|
return 'util' in GLOBAL_OBJ && typeof (GLOBAL_OBJ ).util.format === 'function'
|
|
? (GLOBAL_OBJ ).util.format(...values)
|
|
: safeJoinConsoleArgs(values, normalizeDepth, normalizeMaxBreadth);
|
|
}
|
|
|
|
/**
|
|
* Joins the given values into a string.
|
|
*
|
|
* @param values - The values to join.
|
|
* @param normalizeDepth - The depth to normalize the values.
|
|
* @param normalizeMaxBreadth - The max breadth to normalize the values.
|
|
* @returns The joined string.
|
|
*/
|
|
function safeJoinConsoleArgs(values, normalizeDepth, normalizeMaxBreadth) {
|
|
return values
|
|
.map(value =>
|
|
isPrimitive(value) ? String(value) : JSON.stringify(normalize(value, normalizeDepth, normalizeMaxBreadth)),
|
|
)
|
|
.join(' ');
|
|
}
|
|
|
|
/**
|
|
* Checks if a string contains console substitution patterns like %s, %d, %i, %f, %o, %O, %c.
|
|
*
|
|
* @param str - The string to check
|
|
* @returns true if the string contains console substitution patterns
|
|
*/
|
|
function hasConsoleSubstitutions(str) {
|
|
// Match console substitution patterns: %s, %d, %i, %f, %o, %O, %c
|
|
return /%[sdifocO]/.test(str);
|
|
}
|
|
|
|
/**
|
|
* Creates template attributes for multiple console arguments.
|
|
*
|
|
* @param args - The console arguments
|
|
* @returns An object with template and parameter attributes
|
|
*/
|
|
function createConsoleTemplateAttributes(firstArg, followingArgs) {
|
|
const attributes = {};
|
|
|
|
// Create template with placeholders for each argument
|
|
const template = new Array(followingArgs.length).fill('{}').join(' ');
|
|
attributes['sentry.message.template'] = `${firstArg} ${template}`;
|
|
|
|
// Add each argument as a parameter
|
|
followingArgs.forEach((arg, index) => {
|
|
attributes[`sentry.message.parameter.${index}`] = arg;
|
|
});
|
|
|
|
return attributes;
|
|
}
|
|
|
|
export { createConsoleTemplateAttributes, formatConsoleArgs, hasConsoleSubstitutions, safeJoinConsoleArgs };
|
|
//# sourceMappingURL=utils.js.map
|