-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathparameterize.ts
28 lines (26 loc) · 1.35 KB
/
parameterize.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import type { ParameterizedString } from '../types-hoist';
/**
* 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.
*/
export function parameterize(strings: TemplateStringsArray, ...values: unknown[]): ParameterizedString {
const formatted = new String(String.raw(strings, ...values)) as ParameterizedString;
formatted.__sentry_template_string__ = strings.join('\x00').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.
*/
export const fmt = parameterize;