Extract format module

Extract formatting utils used by unhandled rejection reporting, and add some unit tests.

See also #412 
Thanks. I thought the API gets somewhat published as it moves into a separate module and gets documented (no word in the docs says it's for internal use only).