[Use as-is] Anyone with improvements for my `escapeString` function that converts unprintable characters to HEX escapes?

The below gist has a escapeString function function that is a start of
Anyone having a stringify function to circumvent :put not displaying un-printable characters as HEX escapes?

https://gist.github.com/jpluimers/f667af4696d2a6411be44df1eeda2c2f

Anyone having improvements for it? (I for one would like a loop based filling of the associative array as requested in How to convert a HEX value to a char?)

Output example:

:put [$escapeString value=("f o\00\01\7E\7F\80\81\FE\FFo")] 
f o\00\01~\7F\80\81\FE\FFo

–jeroen