communication-react-19
Version:
React library for building modern communication user experiences utilizing Azure Communication Services (React 19 compatible fork)
31 lines • 898 B
JavaScript
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* @internal
*
* Replace the pattern "\{\}" in str with the values passed in as vars
*
* @example
* ```ts
* _formatString("hello {name}. '{name}' is a rare name.", {name: "Foo"});
* // returns "hello Foo. 'Foo' is a rare name."
* ```
* @param str - The string to be formatted
* @param variables - Variables to use to format the string
* @returns a formatted string
*/
export const _formatString = (str, vars) => {
if (!str) {
return '';
}
if (!vars) {
return str;
}
// regex to search for the pattern "\{\}"
const placeholdersRegex = /{(\w+)}/g;
return str.replace(placeholdersRegex, (_, k) => {
const replaceValue = vars[k];
return replaceValue === undefined ? `{${k}}` : replaceValue;
});
};
//# sourceMappingURL=localizationUtils.js.map