How to convert an entire string to UT8 escape sequences (like encodeURI() but for an entire string)?

The builtin function encodeURI() and encodeURIComponent() will convert a string to it’s equivalent UTF-8 escape sequences – but it will skip certain characters.

How do you encode all characters using their escape sequences?

for instance:

decodeURI('%6D%65%64%69%61') // 'media'

How would one encode a string?