I applied [this answer](https://stackoverflow.com/a/5499821/492258) in project, I need to escape both at client and server:

```js
function replaceTag(tag) {
        var tagsToReplace = {
            "&": "&amp;",
            "<": "&lt;",
            ">": "&gt;"
        };
        return tagsToReplace[tag] || tag;
    }

    function safe_tags_replace(str) {
        var self = this;
        return str.replace(/[&<>]/g, self.replaceTag);
    }

    var result = safe_tags_replace(">");
    result = safe_tags_replace(result);
    console.log(result);
```

How can I make special character `>` is "escaped" to `&gt;` instead of `&amp;gt;`