For what it's worth, the linked code on github appears to be specific to node.js. Last I checked, there was no native function to convert strings to and from base64, only buffers.
If you're writing this for client side, it would indeed be preferable to use the native functions.