can somebody say how to replace it ?
function textFormat(value){
value = value.replace(/\*{2}(.*?)\*{2}/g, <strong>{'$1'}</strong>);
value = value.replace(/\*(.*?)\*/g, <i>{'$1'}</i>);
value = value.replace(/~{2}(.*?)~{2}/g, <s>{'$1'}</s>);
value = value.replace(/_{2}(.*?)_{2}/g, <u>{'$1'}</u>);
return value;
}
It might help if you can show how you're getting the initial value that's being passed to the textFormat() function.
But in general it looks like the function expects a text string, but the value being passed to the function is an object.
The best approach here would probably be to adjust the code outside of the function, so that when the textFormat() function is called, the value it's called with is a text string instead of an object.
Or, a more versatile solution would be to add an input handler at the top of textFormat() to handle different kinds of input differently:
function textFormat(inVal){
// check input type
let value;
if (typeof inVal === 'object') {
// input is an object, so we'll turn the
// object into a JSON string
value = JSON.stringify(inVal);
} else {
// input is not an object, so we'll assume
// it's a string
value = inVal;
}
value = value.replace(/\*{2}(.*?)\*{2}/g, <strong>{'$1'}</strong>);
value = value.replace(/\*(.*?)\*/g, <i>{'$1'}</i>);
value = value.replace(/~{2}(.*?)~{2}/g, <s>{'$1'}</s>);
value = value.replace(/_{2}(.*?)_{2}/g, <u>{'$1'}</u>);
return value;
}
Note, however, that with the latter solution if you input an object, the return value will be a JSON-ified string of that object (with the given string replacements performed). If you want to get back a modified object, then you'll have to turn the JSON string back into an object after the string.replace() lines.
You can do that with JSON.parse()