@sentry/core
Version:
Base implementation for all Sentry JavaScript SDKs
30 lines (29 loc) • 1.38 kB
JavaScript
// src/utils/parameterize.ts
/**
* Tagged template function which returns parameterized representation of the message
* For example: parameterize`This is a log statement with ${x} and ${y} params`, would return:
* "__sentry_template_string__": 'This is a log statement with %s and %s params',
* "__sentry_template_values__": ['first', 'second']
*
* @param strings An array of string values splitted between expressions
* @param values Expressions extracted from template string
*
* @returns A `ParameterizedString` object that can be passed into `captureMessage` or Sentry.logger.X methods.
*/
function parameterize(strings, ...values) {
const cooked = strings.map((str, i) => str ?? strings.raw[i]);
const formatted = new String(String.raw({ raw: cooked }, ...values));
formatted.__sentry_template_string__ = cooked.join("\0").replace(/%/g, "%%").replace(/\0/g, "%s");
formatted.__sentry_template_values__ = values;
return formatted;
}
/**
* Tagged template function which returns parameterized representation of the message.
*
* @param strings An array of string values splitted between expressions
* @param values Expressions extracted from template string
* @returns A `ParameterizedString` object that can be passed into `captureMessage` or Sentry.logger.X methods.
*/
const fmt = parameterize;
export { fmt, parameterize };
//# sourceMappingURL=parameterize.js.map