There should be utils to do this. @chrisndodge or @dmitchell should know.