Extract format module

Extract formatting utils used by unhandled rejection reporting, and add some unit tests.

See also #412 
I'll take a crack at rewording it slightly.  I'm not too concerned since it's an internal-only API and a quick look at the code will make it obvious what's going on.