Extract format module

Extract formatting utils used by unhandled rejection reporting, and add some unit tests.

See also #412 
I'd say `should be the contents of the stack property of an error`.