'Cheerio: Add Link To Text

Using Cheerio, I'm trying to search an HTML for certain text and add a link to it only if it is not linked already. For example:

<div>
<p> this is an example link </p>
</div>

I want to transform to:

<div>
<p> this is an <a href="https://www.example.com"> example link </a></p>
</div>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source